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 * proximity ::= exclusion distance ordered relation which-code unit-code.
23 * exclusion ::= '1' | '0' | 'void'.
24 * distance ::= integer.
25 * ordered ::= '1' | '0'.
26 * relation ::= integer.
27 * which-code ::= 'known' | 'private' | integer.
28 * unit-code ::= integer.
32 int relCode = getRelCode();
33 int unitCode = getProxUnitCode();
35 String res = "prox " +
37 ms.modifier("distance") + " " +
38 (ms.modifier("ordering").equals("ordered") ? 1 : 0) + " " +
46 private int getRelCode() {
47 String rel = ms.modifier("relation");
48 if (rel.equals("<")) {
50 } else if (rel.equals("<=")) {
52 } else if (rel.equals("=")) {
54 } else if (rel.equals(">=")) {
56 } else if (rel.equals(">")) {
58 } else if (rel.equals("<>")) {
64 private int getProxUnitCode() {
65 String unit = ms.modifier("unit");
66 if (unit.equals("word")) {
68 } else if (unit.equals("sentence")) {
70 } else if (unit.equals("paragraph")) {
72 } else if (unit.equals("element")) {
81 byte[] op = new byte[100];
83 offset = putTag(CONTEXT, 46, CONSTRUCTED, op, 0); // Operator
84 op[offset++] = (byte)(0x80&0xff); // indefinite length
86 offset = putTag(CONTEXT, 3, CONSTRUCTED, op, offset); // prox
87 op[offset++] = (byte)(0x80&0xff); // indefinite length
89 offset = putTag(CONTEXT, 1, PRIMITIVE, op, offset); // exclusion
91 offset = putLen(numLen(value), op, offset);
92 offset = putNum(value, op, offset);
94 offset = putTag(CONTEXT, 2, PRIMITIVE, op, offset); // distance
95 value = Integer.parseInt(ms.modifier("distance"));
96 offset = putLen(numLen(value), op, offset);
97 offset = putNum(value, op, offset);
99 offset = putTag(CONTEXT, 3, PRIMITIVE, op, offset); // ordered
100 value = ms.modifier("ordering").equals("ordered") ? 1 : 0;
101 offset = putLen(numLen(value), op, offset);
102 offset = putNum(value, op, offset);
104 offset = putTag(CONTEXT, 4, PRIMITIVE, op, offset); // relationType
105 value = getRelCode();
106 offset = putLen(numLen(value), op, offset);
107 offset = putNum(value, op, offset);
109 offset = putTag(CONTEXT, 5, CONSTRUCTED, op, offset); // proximityUnitCode
110 op[offset++] = (byte)(0x80&0xff); // indefinite length
111 offset = putTag(CONTEXT, 1, PRIMITIVE, op, offset); // known
112 value = getProxUnitCode();
113 offset = putLen(numLen(value), op, offset);
114 offset = putNum(value, op, offset);
115 op[offset++] = 0x00; // end of proximityUnitCode
118 op[offset++] = 0x00; // end of prox
120 op[offset++] = 0x00; // end of Operator
123 byte[] o = new byte[offset];
124 System.arraycopy(op, 0, o, 0, offset);