1 // $Id: CQLProxNode.java,v 1.13 2007-06-29 12:26:44 mike Exp $
3 package org.z3950.zing.cql;
7 * Represents a proximity node in a CQL parse-tree.
8 * The left- and right-hand-sides must be satisfied by parts of the
9 * candidate records which are sufficiently close to each other, as
10 * specified by a set of proximity parameters.
12 * @version $Id: CQLProxNode.java,v 1.13 2007-06-29 12:26:44 mike Exp $
14 public class CQLProxNode extends CQLBooleanNode {
16 * Creates a new PROX node with the specified left- and right-hand
17 * sides and modifiers.
19 public CQLProxNode(CQLNode left, CQLNode right, ModifierSet ms) {
20 super(left, right, ms);
28 * proximity ::= exclusion distance ordered relation which-code unit-code.
29 * exclusion ::= '1' | '0' | 'void'.
30 * distance ::= integer.
31 * ordered ::= '1' | '0'.
32 * relation ::= integer.
33 * which-code ::= 'known' | 'private' | integer.
34 * unit-code ::= integer.
37 int relCode = getRelCode();
38 int unitCode = getProxUnitCode();
40 String res = "prox " +
42 ms.modifier("distance") + " " +
43 (ms.modifier("ordering").equals("ordered") ? 1 : 0) + " " +
51 private int getRelCode() {
52 String rel = ms.modifier("relation");
53 if (rel.equals("<")) {
55 } else if (rel.equals("<=")) {
57 } else if (rel.equals("=")) {
59 } else if (rel.equals(">=")) {
61 } else if (rel.equals(">")) {
63 } else if (rel.equals("<>")) {
69 private int getProxUnitCode() {
70 String unit = ms.modifier("unit");
71 if (unit.equals("word")) {
73 } else if (unit.equals("sentence")) {
75 } else if (unit.equals("paragraph")) {
77 } else if (unit.equals("element")) {
85 byte[] op = new byte[100];
87 offset = putTag(CONTEXT, 46, CONSTRUCTED, op, 0); // Operator
88 op[offset++] = (byte)(0x80&0xff); // indefinite length
90 offset = putTag(CONTEXT, 3, CONSTRUCTED, op, offset); // prox
91 op[offset++] = (byte)(0x80&0xff); // indefinite length
93 offset = putTag(CONTEXT, 1, PRIMITIVE, op, offset); // exclusion
95 offset = putLen(numLen(value), op, offset);
96 offset = putNum(value, op, offset);
98 offset = putTag(CONTEXT, 2, PRIMITIVE, op, offset); // distance
99 value = Integer.parseInt(ms.modifier("distance"));
100 offset = putLen(numLen(value), op, offset);
101 offset = putNum(value, op, offset);
103 offset = putTag(CONTEXT, 3, PRIMITIVE, op, offset); // ordered
104 value = ms.modifier("ordering").equals("ordered") ? 1 : 0;
105 offset = putLen(numLen(value), op, offset);
106 offset = putNum(value, op, offset);
108 offset = putTag(CONTEXT, 4, PRIMITIVE, op, offset); // relationType
109 value = getRelCode();
110 offset = putLen(numLen(value), op, offset);
111 offset = putNum(value, op, offset);
113 offset = putTag(CONTEXT, 5, CONSTRUCTED, op, offset); // proximityUnitCode
114 op[offset++] = (byte)(0x80&0xff); // indefinite length
115 offset = putTag(CONTEXT, 1, PRIMITIVE, op, offset); // known
116 value = getProxUnitCode();
117 offset = putLen(numLen(value), op, offset);
118 offset = putNum(value, op, offset);
119 op[offset++] = 0x00; // end of proximityUnitCode
122 op[offset++] = 0x00; // end of prox
124 op[offset++] = 0x00; // end of Operator
127 byte[] o = new byte[offset];
128 System.arraycopy(op, 0, o, 0, offset);