X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Forg%2Fz3950%2Fzing%2Fcql%2FCQLProxNode.java;h=244cf9c9c01d71925c4aafa136b13302bca8d3da;hb=af923f9b50aecdbf896af612e733817f96c4388a;hp=b3a8dca4d38bd532f62a87ee075a0bf56b35911c;hpb=fc82b225d39cc66cb85c2557db0c0d4a4c5a6e27;p=cql-java-moved-to-github.git
diff --git a/src/org/z3950/zing/cql/CQLProxNode.java b/src/org/z3950/zing/cql/CQLProxNode.java
index b3a8dca..244cf9c 100644
--- a/src/org/z3950/zing/cql/CQLProxNode.java
+++ b/src/org/z3950/zing/cql/CQLProxNode.java
@@ -1,4 +1,4 @@
-// $Id: CQLProxNode.java,v 1.3 2002-11-06 20:13:45 mike Exp $
+// $Id: CQLProxNode.java,v 1.9 2007-06-27 22:15:04 mike Exp $
package org.z3950.zing.cql;
import java.util.Vector;
@@ -10,7 +10,7 @@ import java.util.Vector;
* candidate records which are sufficiently close to each other, as
* specified by a set of proximity parameters.
*
- * @version $Id: CQLProxNode.java,v 1.3 2002-11-06 20:13:45 mike Exp $
+ * @version $Id: CQLProxNode.java,v 1.9 2007-06-27 22:15:04 mike Exp $
*/
public class CQLProxNode extends CQLBooleanNode {
ModifierSet ms;
@@ -40,30 +40,20 @@ public class CQLProxNode extends CQLBooleanNode {
}
/**
- * Adds a modifier of the specified type and
- * value to a proximity node. Valid types are
- * relation, distance, unit and
- * ordering.
- *
- * For information on the semantics of these paramaters, see
- * section 3.1 (Proximity) of
- * A Gentle Introduction to CQL.
+ * Adds a modifier of the specified type,
+ * comparison and value to a proximity node.
*/
- public void addModifier(String type, String value) {
- ms.addModifier(type, value);
+ public void addModifier(String type, String comparison, String value) {
+ ms.addModifier(type, comparison, value);
}
/**
* Returns an array of the modifiers associated with a proximity
* node.
* @return
- * An array of modifiers, each represented by a two-element
- * Vector, in which element 0 is the modifier type
- * (e.g. distance or ordering) and element 1 is
- * the associated value (e.g. 3 or unordered).
+ * An array of Modifier objects.
*/
- public Vector[] getModifiers() {
+ public Vector getModifiers() {
return ms.getModifiers();
}
@@ -71,7 +61,7 @@ public class CQLProxNode extends CQLBooleanNode {
return ms.toCQL();
}
- String opXQL(int level) {
+ String opXCQL(int level) {
return ms.toXCQL(level, "boolean");
}
@@ -85,42 +75,98 @@ public class CQLProxNode extends CQLBooleanNode {
* unit-code ::= integer.
*/
String opPQF() {
+ int relCode = getRelCode();
+ int unitCode = getProxUnitCode();
+
+ String res = "prox " +
+ "0 " +
+ ms.modifier("distance") + " " +
+ (ms.modifier("ordering").equals("ordered") ? 1 : 0) + " " +
+ relCode + " " +
+ "1 " +
+ unitCode;
+
+ return res;
+ }
+
+ private int getRelCode() {
String rel = ms.modifier("relation");
- int relCode = 0;
if (rel.equals("<")) {
- relCode = 1;
+ return 1;
} else if (rel.equals("<=")) {
- relCode = 2;
+ return 2;
} else if (rel.equals("=")) {
- relCode = 3;
+ return 3;
} else if (rel.equals(">=")) {
- relCode = 4;
+ return 4;
} else if (rel.equals(">")) {
- relCode = 5;
+ return 5;
} else if (rel.equals("<>")) {
- relCode = 6;
+ return 6;
}
+ return 0;
+ }
+ private int getProxUnitCode() {
String unit = ms.modifier("unit");
- int unitCode = 0;
if (unit.equals("word")) {
- unitCode = 2;
+ return 2;
} else if (unit.equals("sentence")) {
- unitCode = 3;
+ return 3;
} else if (unit.equals("paragraph")) {
- unitCode = 4;
+ return 4;
} else if (unit.equals("element")) {
- unitCode = 8;
+ return 8;
}
+ return 0;
+ }
- String res = "prox " +
- "0 " +
- ms.modifier("distance") + " " +
- (ms.modifier("ordering").equals("ordered") ? 1 : 0) + " " +
- relCode + " " +
- "1 " +
- unitCode;
-
- return res;
+
+ byte[] opType1() {
+ byte[] op = new byte[100];
+ int offset, value;
+ offset = putTag(CONTEXT, 46, CONSTRUCTED, op, 0); // Operator
+ op[offset++] = (byte)(0x80&0xff); // indefinite length
+
+ offset = putTag(CONTEXT, 3, CONSTRUCTED, op, offset); // prox
+ op[offset++] = (byte)(0x80&0xff); // indefinite length
+
+ offset = putTag(CONTEXT, 1, PRIMITIVE, op, offset); // exclusion
+ value = 0; // false
+ offset = putLen(numLen(value), op, offset);
+ offset = putNum(value, op, offset);
+
+ offset = putTag(CONTEXT, 2, PRIMITIVE, op, offset); // distance
+ value = Integer.parseInt(ms.modifier("distance"));
+ offset = putLen(numLen(value), op, offset);
+ offset = putNum(value, op, offset);
+
+ offset = putTag(CONTEXT, 3, PRIMITIVE, op, offset); // ordered
+ value = ms.modifier("ordering").equals("ordered") ? 1 : 0;
+ offset = putLen(numLen(value), op, offset);
+ offset = putNum(value, op, offset);
+
+ offset = putTag(CONTEXT, 4, PRIMITIVE, op, offset); // relationType
+ value = getRelCode();
+ offset = putLen(numLen(value), op, offset);
+ offset = putNum(value, op, offset);
+
+ offset = putTag(CONTEXT, 5, CONSTRUCTED, op, offset); // proximityUnitCode
+ op[offset++] = (byte)(0x80&0xff); // indefinite length
+ offset = putTag(CONTEXT, 1, PRIMITIVE, op, offset); // known
+ value = getProxUnitCode();
+ offset = putLen(numLen(value), op, offset);
+ offset = putNum(value, op, offset);
+ op[offset++] = 0x00; // end of proximityUnitCode
+ op[offset++] = 0x00;
+
+ op[offset++] = 0x00; // end of prox
+ op[offset++] = 0x00;
+ op[offset++] = 0x00; // end of Operator
+ op[offset++] = 0x00;
+
+ byte[] o = new byte[offset];
+ System.arraycopy(op, 0, o, 0, offset);
+ return o;
}
}