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.
33 int relCode = getRelCode();
34 int unitCode = getProxUnitCode();
36 String res = "prox " +
38 ms.modifier("distance") + " " +
39 (ms.modifier("ordering").equals("ordered") ? 1 : 0) + " " +
47 private int getRelCode() {
48 String rel = ms.modifier("relation");
49 if (rel.equals("<")) {
51 } else if (rel.equals("<=")) {
53 } else if (rel.equals("=")) {
55 } else if (rel.equals(">=")) {
57 } else if (rel.equals(">")) {
59 } else if (rel.equals("<>")) {
65 private int getProxUnitCode() {
66 String unit = ms.modifier("unit");
67 if (unit.equals("word")) {
69 } else if (unit.equals("sentence")) {
71 } else if (unit.equals("paragraph")) {
73 } 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);