1 // $Id: CQLProxNode.java,v 1.14 2007-06-29 12:53:03 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.14 2007-06-29 12:53:03 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);
24 * proximity ::= exclusion distance ordered relation which-code unit-code.
25 * exclusion ::= '1' | '0' | 'void'.
26 * distance ::= integer.
27 * ordered ::= '1' | '0'.
28 * relation ::= integer.
29 * which-code ::= 'known' | 'private' | integer.
30 * unit-code ::= integer.
34 int relCode = getRelCode();
35 int unitCode = getProxUnitCode();
37 String res = "prox " +
39 ms.modifier("distance") + " " +
40 (ms.modifier("ordering").equals("ordered") ? 1 : 0) + " " +
48 private int getRelCode() {
49 String rel = ms.modifier("relation");
50 if (rel.equals("<")) {
52 } else if (rel.equals("<=")) {
54 } else if (rel.equals("=")) {
56 } else if (rel.equals(">=")) {
58 } else if (rel.equals(">")) {
60 } else if (rel.equals("<>")) {
66 private int getProxUnitCode() {
67 String unit = ms.modifier("unit");
68 if (unit.equals("word")) {
70 } else if (unit.equals("sentence")) {
72 } else if (unit.equals("paragraph")) {
74 } else if (unit.equals("element")) {
83 byte[] op = new byte[100];
85 offset = putTag(CONTEXT, 46, CONSTRUCTED, op, 0); // Operator
86 op[offset++] = (byte)(0x80&0xff); // indefinite length
88 offset = putTag(CONTEXT, 3, CONSTRUCTED, op, offset); // prox
89 op[offset++] = (byte)(0x80&0xff); // indefinite length
91 offset = putTag(CONTEXT, 1, PRIMITIVE, op, offset); // exclusion
93 offset = putLen(numLen(value), op, offset);
94 offset = putNum(value, op, offset);
96 offset = putTag(CONTEXT, 2, PRIMITIVE, op, offset); // distance
97 value = Integer.parseInt(ms.modifier("distance"));
98 offset = putLen(numLen(value), op, offset);
99 offset = putNum(value, op, offset);
101 offset = putTag(CONTEXT, 3, PRIMITIVE, op, offset); // ordered
102 value = ms.modifier("ordering").equals("ordered") ? 1 : 0;
103 offset = putLen(numLen(value), op, offset);
104 offset = putNum(value, op, offset);
106 offset = putTag(CONTEXT, 4, PRIMITIVE, op, offset); // relationType
107 value = getRelCode();
108 offset = putLen(numLen(value), op, offset);
109 offset = putNum(value, op, offset);
111 offset = putTag(CONTEXT, 5, CONSTRUCTED, op, offset); // proximityUnitCode
112 op[offset++] = (byte)(0x80&0xff); // indefinite length
113 offset = putTag(CONTEXT, 1, PRIMITIVE, op, offset); // known
114 value = getProxUnitCode();
115 offset = putLen(numLen(value), op, offset);
116 offset = putNum(value, op, offset);
117 op[offset++] = 0x00; // end of proximityUnitCode
120 op[offset++] = 0x00; // end of prox
122 op[offset++] = 0x00; // end of Operator
125 byte[] o = new byte[offset];
126 System.arraycopy(op, 0, o, 0, offset);