2 package org.z3950.zing.cql;
6 * Represents a proximity node in a CQL parse-tree.
7 * The left- and right-hand-sides must be satisfied by parts of the
8 * candidate records which are sufficiently close to each other, as
9 * specified by a set of proximity parameters.
12 public class CQLProxNode extends CQLBooleanNode {
14 * Creates a new PROX node with the specified left- and right-hand
15 * sides and modifiers.
17 public CQLProxNode(CQLNode left, CQLNode right, ModifierSet ms) {
18 super(left, right, ms);
22 public void traverse(CQLNodeVisitor visitor) {
23 visitor.onProxNode(this);
27 * proximity ::= exclusion distance ordered relation which-code unit-code.
28 * exclusion ::= '1' | '0' | 'void'.
29 * distance ::= integer.
30 * ordered ::= '1' | '0'.
31 * relation ::= integer.
32 * which-code ::= 'known' | 'private' | integer.
33 * 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")) {
86 byte[] op = new byte[100];
88 offset = putTag(CONTEXT, 46, CONSTRUCTED, op, 0); // Operator
89 op[offset++] = (byte)(0x80&0xff); // indefinite length
91 offset = putTag(CONTEXT, 3, CONSTRUCTED, op, offset); // prox
92 op[offset++] = (byte)(0x80&0xff); // indefinite length
94 offset = putTag(CONTEXT, 1, PRIMITIVE, op, offset); // exclusion
96 offset = putLen(numLen(value), op, offset);
97 offset = putNum(value, op, offset);
99 offset = putTag(CONTEXT, 2, PRIMITIVE, op, offset); // distance
100 value = Integer.parseInt(ms.modifier("distance"));
101 offset = putLen(numLen(value), op, offset);
102 offset = putNum(value, op, offset);
104 offset = putTag(CONTEXT, 3, PRIMITIVE, op, offset); // ordered
105 value = ms.modifier("ordering").equals("ordered") ? 1 : 0;
106 offset = putLen(numLen(value), op, offset);
107 offset = putNum(value, op, offset);
109 offset = putTag(CONTEXT, 4, PRIMITIVE, op, offset); // relationType
110 value = getRelCode();
111 offset = putLen(numLen(value), op, offset);
112 offset = putNum(value, op, offset);
114 offset = putTag(CONTEXT, 5, CONSTRUCTED, op, offset); // proximityUnitCode
115 op[offset++] = (byte)(0x80&0xff); // indefinite length
116 offset = putTag(CONTEXT, 1, PRIMITIVE, op, offset); // known
117 value = getProxUnitCode();
118 offset = putLen(numLen(value), op, offset);
119 offset = putNum(value, op, offset);
120 op[offset++] = 0x00; // end of proximityUnitCode
123 op[offset++] = 0x00; // end of prox
125 op[offset++] = 0x00; // end of Operator
128 byte[] o = new byte[offset];
129 System.arraycopy(op, 0, o, 0, offset);