Added and altered string types to enums.
Change-Id: I143ce5e270ea8868d3c62f62ebd13c66c74ac886
diff --git a/pom.xml b/pom.xml
index d86dfaa..d238e66 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,8 +53,6 @@
</repository>
</repositories>
<dependencies>
- <!-- <dependency> <groupId>org.antlr</groupId> <artifactId>antlr4-runtime</artifactId>
- <version>4.2</version> </dependency> -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/ClassRefCheck.java b/src/main/java/de/ids_mannheim/korap/query/object/ClassRefCheck.java
new file mode 100644
index 0000000..e19b0d4
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/query/object/ClassRefCheck.java
@@ -0,0 +1,11 @@
+package de.ids_mannheim.korap.query.object;
+
+public enum ClassRefCheck {
+
+ INTERSECTS, EQUALS, UNEQUALS, INCLUDES, DISJOINT;
+
+ @Override
+ public String toString() {
+ return "classRefCheck:"+name().toLowerCase();
+ }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/ClassRefOp.java b/src/main/java/de/ids_mannheim/korap/query/object/ClassRefOp.java
new file mode 100644
index 0000000..0c8b934
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/query/object/ClassRefOp.java
@@ -0,0 +1,11 @@
+package de.ids_mannheim.korap.query.object;
+
+public enum ClassRefOp {
+
+ INVERSION, INTERSECTION, UNION, DELETE;
+
+ @Override
+ public String toString () {
+ return "classRefOp:" + name().toLowerCase();
+ }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralFrame.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralFrame.java
new file mode 100644
index 0000000..5ac6e8c
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralFrame.java
@@ -0,0 +1,19 @@
+package de.ids_mannheim.korap.query.object;
+
+public enum KoralFrame {
+
+ SUCCEDS("succeeds"), SUCCEDS_DIRECTLY("succeedsDirectly"), OVERLAPS_RIGHT("overlapsRight"),
+ ALIGNS_RIGHT("alignsRight"), IS_WITHIN("isWithin"), STARTS_WITH("startsWith"),
+ MATCHES("matches"), ALIGNS_LEFT("alignsLeft"), IS_AROUND("isAround"), ENDS_WITH("endsWith"),
+ OVERLAPS_LEFT("overlapsLeft"), PRECEEDS_DIRECTLY("precedesDirectly"), PRECEDES("precedes");
+
+ private String value;
+ KoralFrame(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return "frames:"+value;
+ }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java
index 87d98e8..2e1b779 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java
@@ -23,7 +23,7 @@
private boolean inOrder = false;
private List<KoralObject> operands;
private List<KoralDistance> distances;
- private List<Frame> frames;
+ private List<KoralFrame> frames;
private KoralBoundary boundary;
// private int[] classIn;
@@ -68,11 +68,11 @@
this.distances = distances;
}
- public List<Frame> getFrames() {
+ public List<KoralFrame> getFrames() {
return frames;
}
- public void setFrames(List<Frame> frames) {
+ public void setFrames(List<KoralFrame> frames) {
this.frames = frames;
}
@@ -111,20 +111,20 @@
return map;
}
- public enum Frame{
- SUCCEDS("succeeds"), SUCCEDS_DIRECTLY("succeedsDirectly"), OVERLAPS_RIGHT("overlapsRight"),
- ALIGNS_RIGHT("alignsRight"), IS_WITHIN("isWithin"), STARTS_WITH("startsWith"),
- MATCHES("matches"), ALIGNS_LEFT("alignsLeft"), IS_AROUND("isAround"), ENDS_WITH("endsWith"),
- OVERLAPS_LEFT("overlapsLeft"), PRECEEDS_DIRECTLY("precedesDirectly"), PRECEDES("precedes");
-
- private String value;
- Frame(String value) {
- this.value = value;
- }
-
- @Override
- public String toString() {
- return "frame:"+value;
- }
- }
+// public enum Frame{
+// SUCCEDS("succeeds"), SUCCEDS_DIRECTLY("succeedsDirectly"), OVERLAPS_RIGHT("overlapsRight"),
+// ALIGNS_RIGHT("alignsRight"), IS_WITHIN("isWithin"), STARTS_WITH("startsWith"),
+// MATCHES("matches"), ALIGNS_LEFT("alignsLeft"), IS_AROUND("isAround"), ENDS_WITH("endsWith"),
+// OVERLAPS_LEFT("overlapsLeft"), PRECEEDS_DIRECTLY("precedesDirectly"), PRECEDES("precedes");
+//
+// private String value;
+// Frame(String value) {
+// this.value = value;
+// }
+//
+// @Override
+// public String toString() {
+// return "frame:"+value;
+// }
+// }
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralOperation.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralOperation.java
index d81557f..98dae3e 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralOperation.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralOperation.java
@@ -5,7 +5,7 @@
*
*/
public enum KoralOperation {
- SEQUENCE, POSITION, DISJUNCTION, REPETITION, CLASS, MERGE, RELATION;
+ SEQUENCE, POSITION, DISJUNCTION, REPETITION, CLASS, MERGE, RELATION, FOCUS;
@Override
public String toString() {
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralType.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralType.java
index 4992f43..beb76ab 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralType.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralType.java
@@ -1,24 +1,28 @@
package de.ids_mannheim.korap.query.object;
-/** Definition of various types of KoralQuery building objects.
- *
+/**
+ * Definition of various types of KoralQuery building objects.
+ *
* @author margaretha
*
*/
public enum KoralType {
- TERMGROUP("koral:termGroup"), TERM("koral:term"), TOKEN("koral:token"), SPAN(
- "koral:span"), GROUP("koral:group"), BOUNDARY("koral:boundary"), RELATION(
- "koral:relation"), DISTANCE("koral:distance"), REFERENCE(
- "koral:reference");
+ TERMGROUP("koral:termGroup"), TERM("koral:term"), TOKEN("koral:token"),
+ SPAN("koral:span"), GROUP("koral:group"), BOUNDARY("koral:boundary"),
+ RELATION("koral:relation"), DISTANCE("koral:distance"), REFERENCE(
+ "koral:reference"), DOCUMENT("koral:doc"), DOCUMENTGROUP("koral:docGroup"),
+ COSMAS_DISTANCE("cosmas:distance");
String value;
+
KoralType (String value) {
this.value = value;
}
+
@Override
- public String toString() {
+ public String toString () {
return value;
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
index 98f6536..c4d0fa1 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
@@ -10,11 +10,11 @@
import de.ids_mannheim.korap.query.object.KoralBoundary;
import de.ids_mannheim.korap.query.object.KoralGroup;
import de.ids_mannheim.korap.query.object.KoralDistance;
+import de.ids_mannheim.korap.query.object.KoralFrame;
import de.ids_mannheim.korap.query.object.KoralObject;
import de.ids_mannheim.korap.query.object.KoralOperation;
import de.ids_mannheim.korap.query.object.KoralSpan;
import de.ids_mannheim.korap.query.object.KoralTerm;
-import de.ids_mannheim.korap.query.object.KoralGroup.Frame;
import eu.clarin.sru.server.fcs.parser.ExpressionWildcard;
import eu.clarin.sru.server.fcs.parser.QueryDisjunction;
import eu.clarin.sru.server.fcs.parser.QueryGroup;
@@ -125,7 +125,7 @@
private KoralGroup parseWithinQuery(QueryWithWithin queryNode)
throws KoralException {
KoralGroup koralGroup = new KoralGroup(KoralOperation.POSITION);
- koralGroup.setFrames(Arrays.asList(Frame.IS_AROUND));
+ koralGroup.setFrames(Arrays.asList(KoralFrame.IS_AROUND));
List<KoralObject> operands = new ArrayList<KoralObject>();
operands.add(parseQueryNode(queryNode.getWithin()));
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java
index 528d799..5a1c0b0 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java
@@ -17,9 +17,13 @@
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;
+import org.apache.commons.lang.math.Fraction;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
+import de.ids_mannheim.korap.query.object.KoralFrame;
+import de.ids_mannheim.korap.query.object.KoralOperation;
+import de.ids_mannheim.korap.query.object.KoralTermGroupRelation;
import de.ids_mannheim.korap.query.parse.annis.AqlLexer;
import de.ids_mannheim.korap.query.parse.annis.AqlParser;
import de.ids_mannheim.korap.query.serialize.util.Antlr4DescriptiveErrorListener;
@@ -38,6 +42,7 @@
* @see http://annis-tools.org/aql.html
*
* @author Joachim Bingel (bingel@ids-mannheim.de)
+ * @author Eliza Margaretha (margaretha@ids-mannheim.de)
* @version 0.3.0
* @since 0.1.0
*/
@@ -392,7 +397,7 @@
List<ParseTree> andTopExprs = getChildrenWithCat(node, "andTopExpr");
if (andTopExprs.size() > 1) {
LinkedHashMap<String, Object> topOr = KoralObjectGenerator
- .makeGroup("disjunction");
+ .makeGroup(KoralOperation.DISJUNCTION);
requestMap.put("query", topOr);
objectStack.push(topOr);
}
@@ -475,7 +480,7 @@
}
else {
LinkedHashMap<String, Object> termGroup = KoralObjectGenerator
- .makeTermGroup("and");
+ .makeTermGroup(KoralTermGroupRelation.AND);
ArrayList<Object> operands = (ArrayList<Object>) termGroup
.get("operands");
for (ParseTree unaryTerm : unaryTermsForRef) {
@@ -634,9 +639,9 @@
|| reltype.equals("commonancestor")) {
// make an (outer) group and an inner group containing the dummy
// node or previous relations
- group = KoralObjectGenerator.makeGroup("relation");
+ group = KoralObjectGenerator.makeGroup(KoralOperation.RELATION);
LinkedHashMap<String, Object> innerGroup = KoralObjectGenerator
- .makeGroup("relation");
+ .makeGroup(KoralOperation.RELATION);
LinkedHashMap<String, Object> relation = KoralObjectGenerator
.makeRelation();
LinkedHashMap<String, Object> term = KoralObjectGenerator
@@ -701,14 +706,15 @@
groupType = "relation";
}
if (groupType.equals("relation")
- || groupType.equals("treeRelation")) {
- group = KoralObjectGenerator.makeGroup(groupType);
+// || groupType.equals("treeRelation")
+ ) {
+ group = KoralObjectGenerator.makeGroup(KoralOperation.RELATION);
LinkedHashMap<String, Object> relation = new LinkedHashMap<String, Object>();
putAllButGroupType(relation, operatorGroup);
group.put("relation", relation);
}
else if (groupType.equals("sequence")) {
- group = KoralObjectGenerator.makeGroup(groupType);
+ group = KoralObjectGenerator.makeGroup(KoralOperation.SEQUENCE);
putAllButGroupType(group, operatorGroup);
}
else if (groupType.equals("position")) {
@@ -725,10 +731,12 @@
ParseTree rightChildSpec = getFirstChildWithCat(node
.getChild(i).getChild(0), "@r");
if (leftChildSpec != null || rightChildSpec != null) {
- String frame = (leftChildSpec != null) ? "frames:startsWith"
- : "frames:endsWith";
+ KoralFrame frame = (leftChildSpec != null) ? KoralFrame.STARTS_WITH
+ : KoralFrame.ENDS_WITH;
+ ArrayList<KoralFrame> frames = new ArrayList<KoralFrame>();
+ frames.add(frame);
LinkedHashMap<String, Object> positionGroup = KoralObjectGenerator
- .makePosition(new String[] { frame });
+ .makePosition(frames);
operand2 = KoralObjectGenerator.wrapInClass(operand2,
++classCounter + 128);
((ArrayList<Object>) positionGroup.get("operands"))
@@ -866,7 +874,7 @@
term = edgeSpec;
}
else {
- term = KoralObjectGenerator.makeTermGroup("and");
+ term = KoralObjectGenerator.makeTermGroup(KoralTermGroupRelation.AND);
ArrayList<Object> termGroupOperands = (ArrayList<Object>) term
.get("operands");
termGroupOperands.add(edgeSpec);
@@ -923,30 +931,31 @@
}
else if (operator.equals("spanrelation")) {
String reltype = operatorNode.getChild(0).toStringTree(parser);
- String[] frames = new String[] {};
+ ArrayList<KoralFrame> frames = new ArrayList<>();
switch (reltype) {
case "_=_":
- frames = new String[] { "frames:matches" };
+ frames.add(KoralFrame.MATCHES);
break;
case "_l_":
- frames = new String[] { "frames:startsWith",
- "frames:matches" };
+ frames.add(KoralFrame.STARTS_WITH);
+ frames.add(KoralFrame.MATCHES);
break;
case "_r_":
- frames = new String[] { "frames:endsWith", "frames:matches" };
+ frames.add(KoralFrame.ENDS_WITH);
+ frames.add(KoralFrame.MATCHES);
break;
case "_i_":
- frames = new String[] { "frames:isAround" };
+ frames.add(KoralFrame.IS_AROUND);
break;
case "_o_":
- frames = new String[] { "frames:overlapsLeft",
- "frames:overlapsRight" };
+ frames.add(KoralFrame.OVERLAPS_LEFT);
+ frames.add(KoralFrame.OVERLAPS_RIGHT);
break;
case "_ol_":
- frames = new String[] { "frames:overlapsLeft" };
+ frames.add(KoralFrame.OVERLAPS_LEFT);
break;
case "_or_":
- frames = new String[] { "frames:overlapsRight" };
+ frames.add(KoralFrame.OVERLAPS_RIGHT);
break;
}
relation = KoralObjectGenerator.makePosition(frames);
@@ -989,7 +998,7 @@
return parseEdgeAnno(annos.get(0));
else {
LinkedHashMap<String, Object> termGroup = KoralObjectGenerator
- .makeTermGroup("and");
+ .makeTermGroup(KoralTermGroupRelation.AND);
ArrayList<Object> operands = (ArrayList<Object>) termGroup
.get("operands");
for (ParseTree anno : annos) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
index ae544a1..4667430 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
@@ -1,5 +1,6 @@
package de.ids_mannheim.korap.query.serialize;
+import de.ids_mannheim.korap.query.object.KoralTermGroupRelation;
import de.ids_mannheim.korap.query.parse.collection.CollectionQueryLexer;
import de.ids_mannheim.korap.query.parse.collection.CollectionQueryParser;
import de.ids_mannheim.korap.query.serialize.util.Antlr4DescriptiveErrorListener;
@@ -519,8 +520,12 @@
rightOp = node.getChild(node.getChildCount() - 2);
// establish boolean relation
ParseTree boolOp = getFirstChildWithCat(node, "booleanOp");
- String operator = boolOp.getText().equals("&") ? "and" : "or";
- termGroup = KoralObjectGenerator.makeTermGroup(operator);
+ if (boolOp.getText().equals("&")){
+ termGroup = KoralObjectGenerator.makeTermGroup(KoralTermGroupRelation.AND);
+ }
+ else {
+ termGroup = KoralObjectGenerator.makeTermGroup(KoralTermGroupRelation.OR);
+ }
ArrayList<Object> operands = (ArrayList<Object>) termGroup
.get("operands");
// recursion with left/right operands
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
index 0d5980a..c3b31e2 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
@@ -1,8 +1,16 @@
package de.ids_mannheim.korap.query.serialize;
+import de.ids_mannheim.korap.query.object.ClassRefCheck;
+import de.ids_mannheim.korap.query.object.ClassRefOp;
+import de.ids_mannheim.korap.query.object.KoralFrame;
+import de.ids_mannheim.korap.query.object.KoralMatchOperator;
+import de.ids_mannheim.korap.query.object.KoralOperation;
+import de.ids_mannheim.korap.query.object.KoralTermGroupRelation;
+import de.ids_mannheim.korap.query.object.KoralType;
import de.ids_mannheim.korap.query.parse.cosmas.c2psLexer;
import de.ids_mannheim.korap.query.parse.cosmas.c2psParser;
import de.ids_mannheim.korap.query.serialize.util.Antlr3DescriptiveErrorListener;
+import de.ids_mannheim.korap.query.serialize.util.Converter;
import de.ids_mannheim.korap.query.serialize.util.KoralObjectGenerator;
import de.ids_mannheim.korap.query.serialize.util.ResourceMapper;
import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
@@ -26,6 +34,7 @@
*
* @author Joachim Bingel (bingel@ids-mannheim.de)
* @author Nils Diewald (diewald@ids-mannheim.de)
+ * @author Eliza Margaretha (margaretha@ids-mannheim.de)
* @version 0.3
*/
public class Cosmas2QueryProcessor extends Antlr3AbstractQueryProcessor {
@@ -87,8 +96,8 @@
* be in a sequence with any number of other nodes in this list)
*/
private final List<String> sequentiableNodeTypes = Arrays
- .asList(new String[] { "OPWF", "OPLEM", "OPMORPH", "OPBEG",
- "OPEND", "OPIN", "OPBED", "OPELEM", "OPOR", "OPAND" });
+ .asList(new String[] { "OPWF", "OPLEM", "OPMORPH", "OPBEG", "OPEND",
+ "OPIN", "OPBED", "OPELEM", "OPOR", "OPAND" });
/**
* Keeps track of sequenced nodes, i.e. nodes that implicitly
* govern a sequence, as in (C2PQ (OPWF der) (OPWF Mann)). This is
@@ -173,8 +182,8 @@
if (node == parent.getChild(0)) {
nodeHasSequentiableSiblings = false;
for (int i = 1; i < parent.getChildCount(); i++) {
- if (sequentiableNodeTypes.contains(getNodeCat(parent
- .getChild(i)))) {
+ if (sequentiableNodeTypes
+ .contains(getNodeCat(parent.getChild(i)))) {
nodeHasSequentiableSiblings = true;
continue;
}
@@ -182,7 +191,7 @@
if (nodeHasSequentiableSiblings) {
// Step I: create sequence
LinkedHashMap<String, Object> sequence = KoralObjectGenerator
- .makeGroup("sequence");
+ .makeGroup(KoralOperation.SEQUENCE);
// push sequence on object stack but don't
// increment stackedObjects counter since
// we've got to wait until the parent node is
@@ -387,8 +396,10 @@
submatchOperands.add(conditionGroup);
}
else if (conditionCount < conditionGroups.size()) {
+ ArrayList<KoralFrame> frames = new ArrayList<KoralFrame>();
+ frames.add(KoralFrame.MATCHES);
LinkedHashMap<String, Object> matchesGroup = KoralObjectGenerator
- .makePosition(new String[] { "frames:matches" });
+ .makePosition(frames);
@SuppressWarnings("unchecked")
ArrayList<Object> matchesOperands = (ArrayList<Object>) matchesGroup
.get("operands");
@@ -425,7 +436,7 @@
LinkedHashMap<String, Object> group = KoralObjectGenerator
.makeReference(classCounter + 128);
LinkedHashMap<String, Object> classRefCheck = KoralObjectGenerator
- .makeClassRefOp("classRefOp:inversion", classRef,
+ .makeClassRefOp(ClassRefOp.INVERSION, classRef,
classCounter + 128);
ArrayList<Object> operands = new ArrayList<Object>();
operands.add(classRefCheck);
@@ -467,7 +478,7 @@
// LinkedHashMap<String, Object> posgroup =
// makePosition(null);
LinkedHashMap<String, Object> posGroup = KoralObjectGenerator
- .makeGroup("position");
+ .makeGroup(KoralOperation.POSITION);
LinkedHashMap<String, Object> positionOptions;
// posgroup
if (nodeCat.equals("OPIN")) {
@@ -487,7 +498,7 @@
.push((ArrayList<Object>) posGroup.get("operands"));
stackedObjects++;
// Step II: wrap in classRefCheck and/or focus and decide where to put
- ArrayList<String> check = (ArrayList<String>) positionOptions
+ ArrayList<ClassRefCheck> check = (ArrayList<ClassRefCheck>) positionOptions
.get("classRefCheck");
Integer[] classIn = new Integer[] { classCounter + 128 - 2,
classCounter + 128 - 1 };
@@ -503,8 +514,7 @@
}
LinkedHashMap<String, Object> focusGroup = null;
if ((boolean) positionOptions.get("matchall") == true) {
- focusGroup = KoralObjectGenerator.makeClassRefOp(
- "classRefOp:delete",
+ focusGroup = KoralObjectGenerator.makeClassRefOp(ClassRefOp.DELETE,
new Integer[] { 128 + classCounter++ }, 128 + classCounter);
((ArrayList<Object>) focusGroup.get("operands")).add(topGroup);
}
@@ -517,7 +527,7 @@
if (positionOptions.containsKey("grouping")) {
if (positionOptions.get("grouping").equals(true)) {
LinkedHashMap<String, Object> mergeOperation = KoralObjectGenerator
- .makeGroup("merge");
+ .makeGroup(KoralOperation.MERGE);
ArrayList<Object> mergeOperands = (ArrayList<Object>) mergeOperation
.get("operands");
mergeOperands.add(focusGroup);
@@ -536,7 +546,7 @@
Tree dist_list = prox_opts.getChild(1);
// Step I: create group
LinkedHashMap<String, Object> group = KoralObjectGenerator
- .makeGroup("sequence");
+ .makeGroup(KoralOperation.SEQUENCE);
ArrayList<Object> constraints = new ArrayList<Object>();
boolean exclusion = typ.getChild(0).toStringTree().equals("EXCL");
@@ -584,7 +594,7 @@
.makeDistance(meas, min, max);
// override @type, min/max to be treated according to
// Cosmas particularities
- distance.put("@type", "cosmas:distance");
+ distance.put("@type", KoralType.COSMAS_DISTANCE.toString());
if (exclusion) {
distance.put("exclude", true);
}
@@ -608,8 +618,8 @@
LinkedHashMap<String, Object> embeddedSequence = group;
if (!(openNodeCats.get(1).equals("OPBEG")
- || openNodeCats.get(1).equals("OPEND") || inOPALL || openNodeCats
- .get(1).equals("OPNHIT"))) {
+ || openNodeCats.get(1).equals("OPEND") || inOPALL
+ || openNodeCats.get(1).equals("OPNHIT"))) {
wrapOperandInClass(node, 1, 128 + classCounter);
wrapOperandInClass(node, 2, 128 + classCounter);
// Deactivated, uncomment to wrap sequence in reference.
@@ -669,7 +679,7 @@
private void processOPOR (Tree node) {
// Step I: create group
LinkedHashMap<String, Object> disjunction = KoralObjectGenerator
- .makeGroup("disjunction");
+ .makeGroup(KoralOperation.DISJUNCTION);
disjunction.put("inOrder", false); // Order is not important
objectStack.push(disjunction);
stackedObjects++;
@@ -682,7 +692,7 @@
// Step I: create group
String nodeCat = getNodeCat(node);
LinkedHashMap<String, Object> distgroup = KoralObjectGenerator
- .makeGroup("sequence");
+ .makeGroup(KoralOperation.SEQUENCE);
distgroup.put("inOrder", false); // Order is not important
ArrayList<Object> distances = new ArrayList<Object>();
LinkedHashMap<String, Object> zerodistance = KoralObjectGenerator
@@ -709,46 +719,43 @@
}
- // TODO: The handling of attributes vs. element names is somehow disputable ...
+ // TODO: The handling of attributes vs. element names is somehow disputable ...
@SuppressWarnings("unchecked")
private void processOPELEM (Tree node) {
// Step I: create element
LinkedHashMap<String, Object> span = KoralObjectGenerator.makeSpan();
if (node.getChild(0).toStringTree().equals("EMPTY")) {
- addError(
- StatusCodes.MALFORMED_QUERY,
- "Empty #ELEM() operator."
- + " Please specify a valid element key (like 's' for sentence).");
+ addError(StatusCodes.MALFORMED_QUERY, "Empty #ELEM() operator."
+ + " Please specify a valid element key (like 's' for sentence).");
return;
}
else {
int elname = 0;
Tree elnameNode = getFirstChildWithCat(node, "ELNAME");
- /*
- // TODO: This is identical to processOPMORPH
- String wordOrRegex = "\\w+|\".+?\"";
- Pattern p = Pattern.compile("((\\w+)/)?((\\w*)(!?=))?(" + wordOrRegex
- + ")(:(" + wordOrRegex + "))?");
- */
+ /*
+ // TODO: This is identical to processOPMORPH
+ String wordOrRegex = "\\w+|\".+?\"";
+ Pattern p = Pattern.compile("((\\w+)/)?((\\w*)(!?=))?(" + wordOrRegex
+ + ")(:(" + wordOrRegex + "))?");
+ */
if (elnameNode != null) {
- /*
+ /*
span.put("key", elnameNode.getChild(0).toStringTree()
.toLowerCase());
- */
- LinkedHashMap<String, Object> fm =
- termToFieldMap(elnameNode.getChild(0).toStringTree());
+ */
+ LinkedHashMap<String, Object> fm = termToFieldMap(
+ elnameNode.getChild(0).toStringTree());
- if (fm == null)
- return;
+ if (fm == null)
+ return;
- // Workaround for things like #ELEM(S) to become #ELEM(s)
- if (fm.get("foundry") == null &&
- fm.get("layer") == null &&
- fm.get("key") != null) {
- fm.put("key", fm.get("key").toString().toLowerCase());
- };
- span.put("wrap", fm);
+ // Workaround for things like #ELEM(S) to become #ELEM(s)
+ if (fm.get("foundry") == null && fm.get("layer") == null
+ && fm.get("key") != null) {
+ fm.put("key", fm.get("key").toString().toLowerCase());
+ };
+ span.put("wrap", fm);
elname = 1;
}
@@ -766,7 +773,7 @@
* sub-group).
*/
LinkedHashMap<String, Object> termGroup = KoralObjectGenerator
- .makeTermGroup("and");
+ .makeTermGroup(KoralTermGroupRelation.AND);
ArrayList<Object> termGroupOperands = (ArrayList<Object>) termGroup
.get("operands");
for (int i = elname; i < node.getChildCount(); i++) {
@@ -783,13 +790,14 @@
}
term.put("layer", translateMorph(layer));
term.put("key", attrNode.getChild(1).toStringTree());
- String match = getNodeCat(attrNode).equals("EQ") ? "eq"
- : "ne";
- term.put("match", "match:" + match);
+ KoralMatchOperator match = getNodeCat(attrNode)
+ .equals("EQ") ? KoralMatchOperator.EQUALS
+ : KoralMatchOperator.NOT_EQUALS;
+ term.put("match", match.toString());
}
else {
LinkedHashMap<String, Object> subTermGroup = KoralObjectGenerator
- .makeTermGroup("and");
+ .makeTermGroup(KoralTermGroupRelation.AND);
ArrayList<Object> subTermGroupOperands = (ArrayList<Object>) subTermGroup
.get("operands");
int j;
@@ -803,10 +811,12 @@
layer = splitted[1];
}
term.put("layer", translateMorph(layer));
- term.put("key", attrNode.getChild(j).toStringTree());
- String match = getNodeCat(attrNode).equals("EQ") ? "eq"
- : "ne";
- term.put("match", "match:" + match);
+ term.put("key",
+ attrNode.getChild(j).toStringTree());
+ KoralMatchOperator match = getNodeCat(attrNode)
+ .equals("EQ") ? KoralMatchOperator.EQUALS
+ : KoralMatchOperator.NOT_EQUALS;
+ term.put("match", match.toString());
if (node.getChildCount() == elname + 1) {
termGroupOperands.add(term);
}
@@ -828,13 +838,13 @@
.get(0);
}
- // TODO: This should be improved ...
- if (elname == 0) {
- span.put("wrap", termGroup);
- }
- else {
- span.put("attr", termGroup);
- }
+ // TODO: This should be improved ...
+ if (elname == 0) {
+ span.put("wrap", termGroup);
+ }
+ else {
+ span.put("attr", termGroup);
+ }
}
}
// Step II: decide where to put
@@ -852,21 +862,21 @@
for (String morphterm : morphterms) {
- fieldMap = termToFieldMap(morphterm);
- if (fieldMap == null) {
- return;
- };
-
+ fieldMap = termToFieldMap(morphterm);
+ if (fieldMap == null) {
+ return;
+ };
+
terms.add(fieldMap);
}
-
+
if (morphterms.length == 1) {
token.put("wrap", fieldMap);
}
-
+
else {
LinkedHashMap<String, Object> termGroup = KoralObjectGenerator
- .makeTermGroup("and");
+ .makeTermGroup(KoralTermGroupRelation.AND);
termGroup.put("operands", terms);
token.put("wrap", termGroup);
}
@@ -912,10 +922,10 @@
// negate field (see above)
if (negate) {
- fieldMap.put("match", "match:ne");
+ fieldMap.put("match", KoralMatchOperator.NOT_EQUALS.toString());
}
else {
- fieldMap.put("match", "match:eq");
+ fieldMap.put("match", KoralMatchOperator.EQUALS.toString());
}
// Step II: decide where to put
if (!hasChild(node, "TPOS")) {
@@ -986,16 +996,26 @@
@SuppressWarnings("unchecked")
/**
- * Processes individual position conditions as provided in the OPTS node under the OPBEG node.
- * #BEG allows to specify position constrains that apply to the beginning or the end of the subquery X.
- * E.g., in #BEG(X, tpos/tpos), the 'tpos' constraints before the slash indicate conditions that apply
- * to the beginning of X, those after the slash are conditions that apply to the end of X.
- * See the official C-II documentation for more details. <br/><br/>
+ * Processes individual position conditions as provided in the
+ * OPTS node under the OPBEG node.
+ * #BEG allows to specify position constrains that apply to the
+ * beginning or the end of the subquery X.
+ * E.g., in #BEG(X, tpos/tpos), the 'tpos' constraints before the
+ * slash indicate conditions that apply
+ * to the beginning of X, those after the slash are conditions
+ * that apply to the end of X.
+ * See the official C-II documentation for more details.
+ * <br/><br/>
* What's important here is what follows: <br/>
- * Assume the query #BED(der Mann, sa/pa). This means that <b>the beginning<b/> of "der Mann" stands at
- * the beginning of a sentence and that <b>the end</b> (because this constraint comes after the slash) stands at the
- * beginning of a paragraph. The "end" means the last item, here "Mann", so this token comes at the beginning
- * of a paragraph. To capture this, we choose spanRefs: The last item of X matches the first item of the span (here: P).
+ * Assume the query #BED(der Mann, sa/pa). This means that <b>the
+ * beginning<b/> of "der Mann" stands at
+ * the beginning of a sentence and that <b>the end</b> (because
+ * this constraint comes after the slash) stands at the
+ * beginning of a paragraph. The "end" means the last item, here
+ * "Mann", so this token comes at the beginning
+ * of a paragraph. To capture this, we choose spanRefs: The last
+ * item of X matches the first item of the span (here: P).
+ *
* @param cond
* @param distributedOperands
* @param mode
@@ -1005,7 +1025,7 @@
ArrayList<Object> distributedOperands, String mode) {
boolean negated = false;
String elem; // the 'span' (s/p/t)
- String position = "frames:matches"; // default
+ KoralFrame position = KoralFrame.MATCHES; // default
// spanRef to be used for the element ('span')
Integer[] elemSpanRef = null;
// spanRef to be used for the subquery X
@@ -1026,7 +1046,7 @@
// we need to define spanRefs
if (mode.equals("beg")) {
if (nodeString.equals("a")) {
- position = "frames:startsWith";
+ position = KoralFrame.STARTS_WITH;
}
else if (nodeString.equals("e")) {
hitSpanRef = new Integer[] { 0, 1 };
@@ -1035,7 +1055,7 @@
}
else if (mode.equals("end")) {
if (nodeString.equals("e")) {
- position = "frames:endsWith";
+ position = KoralFrame.ENDS_WITH;
}
else if (nodeString.equals("a")) {
hitSpanRef = new Integer[] { 0, 1 };
@@ -1044,8 +1064,10 @@
}
// Create the position group and add the span and the subquery
// as operands, possibly wrapped in spanRefs
+ ArrayList<KoralFrame> frames = new ArrayList<KoralFrame>();
+ frames.add(position);
LinkedHashMap<String, Object> positionGroup = KoralObjectGenerator
- .makePosition(new String[] { position });
+ .makePosition(frames);
if (negated)
positionGroup.put("exclude", true);
ArrayList<Object> posOperands = new ArrayList<Object>();
@@ -1058,7 +1080,7 @@
objectStack.push(classGroup);
if (hitSpanRef != null) {
LinkedHashMap<String, Object> spanRefAroundHit = KoralObjectGenerator
- .makeSpanReference(hitSpanRef, "focus");
+ .makeSpanReference(hitSpanRef, KoralOperation.FOCUS);
((ArrayList<Object>) spanRefAroundHit.get("operands"))
.add(classGroup);
// re-assign after wrapping classGroup in spanRef
@@ -1066,7 +1088,7 @@
}
if (elemSpanRef != null) {
LinkedHashMap<String, Object> spanRefAroundSpan = KoralObjectGenerator
- .makeSpanReference(elemSpanRef, "focus");
+ .makeSpanReference(elemSpanRef, KoralOperation.FOCUS);
((ArrayList<Object>) spanRefAroundSpan.get("operands")).add(span);
// re-assign after wrapping span in spanRef
span = spanRefAroundSpan;
@@ -1084,46 +1106,46 @@
Tree groupnode = getFirstChildWithCat(node, "GROUP");
boolean negatePosition = false;
LinkedHashMap<String, Object> posOptions = new LinkedHashMap<String, Object>();
- ArrayList<String> positions = new ArrayList<String>();
- ArrayList<String> classRefCheck = new ArrayList<String>();
+ ArrayList<KoralFrame> positions = new ArrayList<KoralFrame>();
+ ArrayList<ClassRefCheck> classRefCheck = new ArrayList<ClassRefCheck>();
posOptions.put("matchall", false);
String posOption = null;
if (posnode != null) {
posOption = posnode.getChild(0).toStringTree();
switch (posOption) {
case "L":
- positions.add("frames:startsWith");
- positions.add("frames:matches");
+ positions.add(KoralFrame.STARTS_WITH);
+ positions.add(KoralFrame.MATCHES);
// classRefCheck.add("classRefCheck:includes");
break;
case "R":
- positions.add("frames:endsWith");
- positions.add("frames:matches");
+ positions.add(KoralFrame.ENDS_WITH);
+ positions.add(KoralFrame.MATCHES);
// classRefCheck.add("classRefCheck:includes");
break;
case "F":
- positions.add("frames:matches");
+ positions.add(KoralFrame.MATCHES);
// classRefCheck.add("classRefCheck:includes");
break;
case "FE":
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:equals");
+ positions.add(KoralFrame.MATCHES);
+ classRefCheck.add(ClassRefCheck.EQUALS);
break;
case "FI":
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:unequals");
+ positions.add(KoralFrame.MATCHES);
+ classRefCheck.add(ClassRefCheck.UNEQUALS);
// classRefCheck.add("classRefCheck:includes");
break;
case "N":
- positions.add("frames:contains");
+ positions.add(KoralFrame.IS_AROUND);
// classRefCheck.add("classRefCheck:includes");
break;
}
}
else {
- classRefCheck.add("classRefCheck:includes");
+ classRefCheck.add(ClassRefCheck.INCLUDES);
}
- posOptions.put("frames", positions);
+ posOptions.put("frames", Converter.enumListToStringList(positions));
posOptions.put("classRefCheck", classRefCheck);
if (exclnode != null) {
if (exclnode.getChild(0).toStringTree().equals("YES")) {
@@ -1164,48 +1186,48 @@
Tree exclnode = getFirstChildWithCat(node, "EXCL");
Tree groupnode = getFirstChildWithCat(node, "GROUP");
LinkedHashMap<String, Object> posOptions = new LinkedHashMap<String, Object>();
- ArrayList<String> positions = new ArrayList<String>();
- ArrayList<String> classRefCheck = new ArrayList<String>();
+ ArrayList<KoralFrame> positions = new ArrayList<KoralFrame>();
+ ArrayList<ClassRefCheck> classRefCheck = new ArrayList<ClassRefCheck>();
posOptions.put("matchall", false);
String posOption = null;
if (posnode != null) {
posOption = posnode.getChild(0).toStringTree();
switch (posOption) {
case "L":
- positions.add("frames:startsWith");
- positions.add("frames:overlapsLeft");
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:intersects");
+ positions.add(KoralFrame.STARTS_WITH);
+ positions.add(KoralFrame.OVERLAPS_LEFT);
+ positions.add(KoralFrame.MATCHES);
+ classRefCheck.add(ClassRefCheck.INTERSECTS);
break;
case "R":
- positions.add("frames:endsWith");
- positions.add("frames:overlapsRight");
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:intersects");
+ positions.add(KoralFrame.ENDS_WITH);
+ positions.add(KoralFrame.OVERLAPS_RIGHT);
+ positions.add(KoralFrame.MATCHES);
+ classRefCheck.add(ClassRefCheck.INTERSECTS);
break;
case "F":
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:intersects");
+ positions.add(KoralFrame.MATCHES);
+ classRefCheck.add(ClassRefCheck.INTERSECTS);
break;
case "FE":
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:equals");
+ positions.add(KoralFrame.MATCHES);
+ classRefCheck.add(ClassRefCheck.EQUALS);
break;
case "FI":
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:unequals");
+ positions.add(KoralFrame.MATCHES);
+ classRefCheck.add(ClassRefCheck.UNEQUALS);
break;
case "X":
- positions.add("frames:contains");
- classRefCheck.add("classRefCheck:intersects");
+ positions.add(KoralFrame.IS_AROUND);
+ classRefCheck.add(ClassRefCheck.INTERSECTS);
break;
}
}
else {
- classRefCheck.add("classRefCheck:intersects");
+ classRefCheck.add(ClassRefCheck.INTERSECTS);
}
- posOptions.put("frames", positions);
+ posOptions.put("frames", Converter.enumListToStringList(positions));
posOptions.put("classRefCheck", classRefCheck);
if (exclnode != null) {
if (exclnode.getChild(0).toStringTree().equals("YES")) {
@@ -1244,8 +1266,8 @@
LinkedHashMap<String, Object>[] wrapCascade) {
int i;
for (i = 0; i < wrapCascade.length - 1; i++) {
- ArrayList<Object> containerOperands = (ArrayList<Object>) wrapCascade[i + 1]
- .get("operands");
+ ArrayList<Object> containerOperands = (ArrayList<Object>) wrapCascade[i
+ + 1].get("operands");
containerOperands.add(0, wrapCascade[i]);
}
return wrapCascade[i];
@@ -1303,64 +1325,65 @@
return rewrittenQuery;
}
- private LinkedHashMap<String, Object> termToFieldMap (String term) {
+
+ private LinkedHashMap<String, Object> termToFieldMap (String term) {
// regex group #2 is foundry, #4 layer, #5 operator,
// #6 key, #8 value
String wordOrRegex = "\\w+|\".+?\"";
- // TODO: Should be initialized globally
+ // TODO: Should be initialized globally
Pattern p = Pattern.compile("((\\w+)/)?((\\w*)(!?=))?(" + wordOrRegex
+ ")(:(" + wordOrRegex + "))?");
Matcher m;
- m = p.matcher(term);
- if (!m.matches()) {
- addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
- "Something went wrong parsing the argument in MORPH() or #ELEM().");
- requestMap.put("query", new LinkedHashMap<String, Object>());
- return null;
- };
+ m = p.matcher(term);
+ if (!m.matches()) {
+ addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
+ "Something went wrong parsing the argument in MORPH() or #ELEM().");
+ requestMap.put("query", new LinkedHashMap<String, Object>());
+ return null;
+ };
LinkedHashMap<String, Object> fieldMap = null;
- fieldMap = KoralObjectGenerator.makeTerm();
+ fieldMap = KoralObjectGenerator.makeTerm();
- if (m.group(2) != null)
- fieldMap.put("foundry", m.group(2));
- if (m.group(4) != null)
- fieldMap.put("layer", m.group(4));
- if (m.group(5) != null) {
- if ("!=".equals(m.group(5)))
- negate = !negate;
- }
- if (m.group(6) != null) {
- String key = m.group(6);
- if (key.startsWith("\"") && key.endsWith("\"")) {
- key = key.substring(1, key.length() - 1);
- fieldMap.put("type", "type:regex");
- }
- fieldMap.put("key", key);
- }
+ if (m.group(2) != null)
+ fieldMap.put("foundry", m.group(2));
+ if (m.group(4) != null)
+ fieldMap.put("layer", m.group(4));
+ if (m.group(5) != null) {
+ if ("!=".equals(m.group(5)))
+ negate = !negate;
+ }
+ if (m.group(6) != null) {
+ String key = m.group(6);
+ if (key.startsWith("\"") && key.endsWith("\"")) {
+ key = key.substring(1, key.length() - 1);
+ fieldMap.put("type", "type:regex");
+ }
+ fieldMap.put("key", key);
+ }
- if (m.group(8) != null) {
- String value = m.group(8);
- if (value.startsWith("\"") && value.endsWith("\"")) {
- value = value.substring(1, value.length() - 1);
- fieldMap.put("type", "type:regex");
- }
- fieldMap.put("value", value);
- }
+ if (m.group(8) != null) {
+ String value = m.group(8);
+ if (value.startsWith("\"") && value.endsWith("\"")) {
+ value = value.substring(1, value.length() - 1);
+ fieldMap.put("type", "type:regex");
+ }
+ fieldMap.put("value", value);
+ }
- // negate field (see above)
- if (negate) {
- fieldMap.put("match", "match:ne");
- }
- else {
- fieldMap.put("match", "match:eq");
- };
- return fieldMap;
- };
+ // negate field (see above)
+ if (negate) {
+ fieldMap.put("match", KoralMatchOperator.NOT_EQUALS.toString());
+ }
+ else {
+ fieldMap.put("match", KoralMatchOperator.EQUALS.toString());
+ };
+ return fieldMap;
+ };
-
+
private Tree parseCosmasQuery (String query) {
query = rewritePositionQuery(query);
Tree tree = null;
@@ -1382,7 +1405,8 @@
}
catch (RecognitionException e) {
- log.error("Could not parse query. Please make sure it is well-formed.");
+ log.error(
+ "Could not parse query. Please make sure it is well-formed.");
addError(StatusCodes.MALFORMED_QUERY,
"Could not parse query. Please make sure it is well-formed.");
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
index b0e88ef..e8dc203 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
@@ -1,5 +1,10 @@
package de.ids_mannheim.korap.query.serialize;
+import de.ids_mannheim.korap.query.object.ClassRefOp;
+import de.ids_mannheim.korap.query.object.KoralFrame;
+import de.ids_mannheim.korap.query.object.KoralMatchOperator;
+import de.ids_mannheim.korap.query.object.KoralOperation;
+import de.ids_mannheim.korap.query.object.KoralTermGroupRelation;
import de.ids_mannheim.korap.query.parse.poliqarpplus.PoliqarpPlusLexer;
import de.ids_mannheim.korap.query.parse.poliqarpplus.PoliqarpPlusParser;
import de.ids_mannheim.korap.query.serialize.util.Antlr4DescriptiveErrorListener;
@@ -29,6 +34,7 @@
* v0.3.0.
*
* @author Joachim Bingel (bingel@ids-mannheim.de)
+ * @author Eliza Margaretha (margaretha@ids-mannheim.de)
* @version 0.3.0
* @since 0.1.0
*/
@@ -66,8 +72,8 @@
processNode(tree);
}
else {
- addError(StatusCodes.MALFORMED_QUERY, "Could not parse query >>> "
- + query + " <<<.");
+ addError(StatusCodes.MALFORMED_QUERY,
+ "Could not parse query >>> " + query + " <<<.");
}
}
@@ -216,7 +222,7 @@
ParseTree quantification = getFirstChildWithCat(node, "repetition");
if (quantification != null) {
LinkedHashMap<String, Object> quantGroup = KoralObjectGenerator
- .makeGroup("repetition");
+ .makeGroup(KoralOperation.REPETITION);
Integer[] minmax = parseRepetition(quantification);
quantGroup.put("boundary",
KoralObjectGenerator.makeBoundary(minmax[0], minmax[1]));
@@ -234,9 +240,8 @@
*/
private void processSequence (ParseTree node) {
// skip in case of emptyTokenSequence or emptyTokenSequenceClass
- if (node.getChildCount() == 1
- && getNodeCat(node.getChild(0))
- .startsWith("emptyTokenSequence")) {
+ if (node.getChildCount() == 1 && getNodeCat(node.getChild(0))
+ .startsWith("emptyTokenSequence")) {
return;
}
// skip in case this sequence is just a container for an alignment
@@ -250,8 +255,8 @@
}
}
LinkedHashMap<String, Object> sequence = KoralObjectGenerator
- .makeGroup("sequence");
-
+ .makeGroup(KoralOperation.SEQUENCE);
+
putIntoSuperObject(sequence);
objectStack.push(sequence);
stackedObjects++;
@@ -261,6 +266,7 @@
@SuppressWarnings("unchecked")
/**
* empty tokens at beginning/end of sequence
+ *
* @param node
*/
private void processEmptyTokenSequence (ParseTree node) {
@@ -286,8 +292,8 @@
private void processEmptyTokenSequenceClass (ParseTree node) {
int classId = 1;
if (hasChild(node, "spanclass_id")) {
- classId = Integer.parseInt(node.getChild(1).getChild(0)
- .toStringTree(parser));
+ classId = Integer.parseInt(
+ node.getChild(1).getChild(0).toStringTree(parser));
}
LinkedHashMap<String, Object> classGroup = KoralObjectGenerator
.makeSpanClass(classId);
@@ -328,8 +334,9 @@
}
term.put("layer", "orth");
term.put("key", key);
- String matches = negated ? "ne" : "eq";
- term.put("match", "match:" + matches);
+ KoralMatchOperator matches = negated ? KoralMatchOperator.NOT_EQUALS
+ : KoralMatchOperator.EQUALS;
+ term.put("match", matches.toString());
ParseTree flagNode = getFirstChildWithCat(node, "flag");
if (flagNode != null) {
ArrayList<String> flags = new ArrayList<String>();
@@ -379,7 +386,7 @@
int i = 1;
if (node.getChild(0).getText().equals("^")) {
i = 0; // if there is no first child (anchor is at extreme left or
- // right of segment), start counting at 0 in the loop
+ // right of segment), start counting at 0 in the loop
}
// for every alignment anchor, get its left and right child and register
// these to be wrapped in classes.
@@ -445,9 +452,9 @@
if (termOpNode != null) {
String termOp = termOpNode.getText();
if (termOp.equals("=="))
- wrappedTerm.put("match", "match:eq");
+ wrappedTerm.put("match", KoralMatchOperator.EQUALS.toString());
else if (termOp.equals("!="))
- wrappedTerm.put("match", "match:ne");
+ wrappedTerm.put("match", KoralMatchOperator.NOT_EQUALS.toString());
}
if (termNode != null) {
LinkedHashMap<String, Object> termOrTermGroup = parseTermOrTermGroup(
@@ -467,7 +474,7 @@
private void processDisjunction (ParseTree node) {
LinkedHashMap<String, Object> disjunction = KoralObjectGenerator
- .makeGroup("disjunction");
+ .makeGroup(KoralOperation.DISJUNCTION);
putIntoSuperObject(disjunction);
objectStack.push(disjunction);
stackedObjects++;
@@ -484,7 +491,7 @@
private void processRelation (ParseTree node) {
LinkedHashMap<String, Object> relationGroup = KoralObjectGenerator
- .makeGroup("relation");
+ .makeGroup(KoralOperation.RELATION);
LinkedHashMap<String, Object> relation = KoralObjectGenerator
.makeRelation();
LinkedHashMap<String, Object> term = KoralObjectGenerator.makeTerm();
@@ -549,13 +556,13 @@
private void processMatching (ParseTree node) {
// Step I: get info
ArrayList<Integer> classRefs = new ArrayList<Integer>();
- String classRefOp = null;
+ ClassRefOp classRefOp = null;
if (getNodeCat(node.getChild(2)).equals("spanclass_id")) {
ParseTree spanNode = node.getChild(2);
for (int i = 0; i < spanNode.getChildCount() - 1; i++) {
String ref = spanNode.getChild(i).getText();
if (ref.equals("|") || ref.equals("&")) {
- classRefOp = ref.equals("|") ? "intersection" : "union";
+ classRefOp = ref.equals("|") ? ClassRefOp.INTERSECTION : ClassRefOp.UNION;
}
else {
try {
@@ -581,7 +588,7 @@
if (type.equals("split"))
referenceGroup.put("operation", "operation:split");
if (classRefOp != null) {
- referenceGroup.put("classRefOp", "classRefOp:" + classRefOp);
+ referenceGroup.put("classRefOp", classRefOp.toString());
}
ArrayList<Object> referenceOperands = new ArrayList<Object>();
referenceGroup.put("operands", referenceOperands);
@@ -621,8 +628,8 @@
addWarning("You used the 'meta' keyword in a PoliqarpPlus query. This"
+ " feature is currently not supported. Please use virtual "
+ "collections to restrict documents by metadata.");
- CollectionQueryProcessor cq = new CollectionQueryProcessor(node
- .getChild(1).getText());
+ CollectionQueryProcessor cq = new CollectionQueryProcessor(
+ node.getChild(1).getText());
requestMap.put("collection", cq.getRequestMap().get("collection"));
for (ParseTree child : getChildren(node)) {
visited.add(child);
@@ -638,8 +645,10 @@
.makeSpan(domain);
LinkedHashMap<String, Object> queryObj = (LinkedHashMap<String, Object>) requestMap
.get("query");
+ ArrayList<KoralFrame> frames = new ArrayList<KoralFrame>();
+ frames.add(KoralFrame.IS_AROUND);
LinkedHashMap<String, Object> contains = KoralObjectGenerator
- .makePosition(new String[] { "frames:isAround" });
+ .makePosition(frames);
ArrayList<Object> operands = (ArrayList<Object>) contains
.get("operands");
operands.add(span);
@@ -712,23 +721,25 @@
private LinkedHashMap<String, Object> parseFrame (ParseTree node) {
String operator = node.toStringTree(parser).toLowerCase();
- String[] frames = new String[] { "" };
+ ArrayList<KoralFrame> frames = new ArrayList<KoralFrame>();
switch (operator) {
case "contains":
- frames = new String[] { "frames:isAround" };
+ frames.add(KoralFrame.IS_AROUND);
break;
case "matches":
- frames = new String[] { "frames:matches" };
+ frames.add(KoralFrame.MATCHES);
break;
case "startswith":
- frames = new String[] { "frames:startsWith", "frames:matches" };
+ frames.add(KoralFrame.STARTS_WITH);
+ frames.add(KoralFrame.MATCHES);
break;
case "endswith":
- frames = new String[] { "frames:endsWith", "frames:matches" };
+ frames.add(KoralFrame.ENDS_WITH);
+ frames.add(KoralFrame.MATCHES);
break;
case "overlaps":
- frames = new String[] { "frames:overlapsLeft",
- "frames:overlapsRight" };
+ frames.add(KoralFrame.OVERLAPS_LEFT);
+ frames.add(KoralFrame.OVERLAPS_RIGHT);
break;
}
return KoralObjectGenerator.makePosition(frames);
@@ -765,7 +776,8 @@
// Term is defined recursive with non-necessary brackets
if (getNodeCat(node.getChild(0)).equals("(")) {
- return parseTermOrTermGroup(node.getChild(1), negatedGlobal, mode);
+ return parseTermOrTermGroup(node.getChild(1), negatedGlobal,
+ mode);
};
String key = null;
@@ -856,7 +868,8 @@
// TermGroup is defined recursive with non-necessary brackets
if (getNodeCat(node.getChild(0)).equals("(")) {
- return parseTermOrTermGroup(node.getChild(1), negatedGlobal, mode);
+ return parseTermOrTermGroup(node.getChild(1), negatedGlobal,
+ mode);
};
// For termGroups, establish a boolean relation between
@@ -877,8 +890,14 @@
rightOp = node.getChild(node.getChildCount() - 2);
// establish boolean relation
ParseTree boolOp = getFirstChildWithCat(node, "boolOp");
- String operator = boolOp.getText().equals("&") ? "and" : "or";
- termGroup = KoralObjectGenerator.makeTermGroup(operator);
+ if (boolOp.getText().equals("&")) {
+ termGroup = KoralObjectGenerator
+ .makeTermGroup(KoralTermGroupRelation.AND);
+ }
+ else {
+ termGroup = KoralObjectGenerator
+ .makeTermGroup(KoralTermGroupRelation.OR);
+ }
ArrayList<Object> operands = (ArrayList<Object>) termGroup
.get("operands");
// recursion with left/right operands
@@ -947,8 +966,8 @@
private Integer[] parseDistance (ParseTree distanceNode) {
int emptyTokenSeqIndex = getNodeCat(distanceNode).equals("distance") ? 0
: 2;
- Integer[] minmax = parseEmptySegments(distanceNode
- .getChild(emptyTokenSeqIndex));
+ Integer[] minmax = parseEmptySegments(
+ distanceNode.getChild(emptyTokenSeqIndex));
Integer min = minmax[0];
Integer max = minmax[1];
// min++;
@@ -1011,8 +1030,8 @@
// Get starting rule from parser
Method startRule = PoliqarpPlusParser.class.getMethod("request");
- tree = (ParserRuleContext) startRule
- .invoke(parser, (Object[]) null);
+ tree = (ParserRuleContext) startRule.invoke(parser,
+ (Object[]) null);
}
// Some things went wrong ...
catch (Exception e) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/Converter.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/Converter.java
new file mode 100644
index 0000000..5691a70
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/Converter.java
@@ -0,0 +1,15 @@
+package de.ids_mannheim.korap.query.serialize.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Converter {
+
+ public static List<String> enumListToStringList(List<?> objects){
+ List<String> list = new ArrayList<String>();
+ for (Object o:objects){
+ list.add(o.toString());
+ }
+ return list;
+ }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
index fc6cc49..8f2b5c6 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
@@ -3,7 +3,14 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
+import java.util.List;
+import de.ids_mannheim.korap.query.object.ClassRefCheck;
+import de.ids_mannheim.korap.query.object.ClassRefOp;
+import de.ids_mannheim.korap.query.object.KoralFrame;
+import de.ids_mannheim.korap.query.object.KoralOperation;
+import de.ids_mannheim.korap.query.object.KoralTermGroupRelation;
+import de.ids_mannheim.korap.query.object.KoralType;
import de.ids_mannheim.korap.query.serialize.AbstractQueryProcessor;
public class KoralObjectGenerator {
@@ -19,14 +26,14 @@
public static LinkedHashMap<String, Object> makeSpan () {
LinkedHashMap<String, Object> span = new LinkedHashMap<String, Object>();
- span.put("@type", "koral:span");
+ span.put("@type", KoralType.SPAN.toString());
return span;
}
public static LinkedHashMap<String, Object> makeSpan (String key) {
LinkedHashMap<String, Object> span = new LinkedHashMap<String, Object>();
- span.put("@type", "koral:span");
+ span.put("@type", KoralType.SPAN.toString());
LinkedHashMap<String, Object> term = makeTerm();
term.put("key", key);
span.put("wrap", term);
@@ -36,15 +43,15 @@
public static LinkedHashMap<String, Object> makeTerm () {
LinkedHashMap<String, Object> term = new LinkedHashMap<String, Object>();
- term.put("@type", "koral:term");
+ term.put("@type", KoralType.TERM.toString());
return term;
}
- public static LinkedHashMap<String, Object> makeTermGroup (String relation) {
+ public static LinkedHashMap<String, Object> makeTermGroup (KoralTermGroupRelation relation) {
LinkedHashMap<String, Object> term = new LinkedHashMap<String, Object>();
- term.put("@type", "koral:termGroup");
- term.put("relation", "relation:" + relation);
+ term.put("@type", KoralType.TERMGROUP.toString());
+ term.put("relation", relation.toString());
term.put("operands", new ArrayList<Object>());
return term;
}
@@ -52,14 +59,14 @@
public static LinkedHashMap<String, Object> makeDoc () {
LinkedHashMap<String, Object> term = new LinkedHashMap<String, Object>();
- term.put("@type", "koral:doc");
+ term.put("@type", KoralType.DOCUMENT.toString());
return term;
}
public static LinkedHashMap<String, Object> makeDocGroup (String relation) {
LinkedHashMap<String, Object> term = new LinkedHashMap<String, Object>();
- term.put("@type", "koral:docGroup");
+ term.put("@type", KoralType.DOCUMENTGROUP.toString());
term.put("operation", "operation:" + relation);
term.put("operands", new ArrayList<Object>());
return term;
@@ -68,15 +75,15 @@
public static LinkedHashMap<String, Object> makeToken () {
LinkedHashMap<String, Object> token = new LinkedHashMap<String, Object>();
- token.put("@type", "koral:token");
+ token.put("@type", KoralType.TOKEN.toString());
return token;
}
- public static LinkedHashMap<String, Object> makeGroup (String operation) {
+ public static LinkedHashMap<String, Object> makeGroup (KoralOperation operation) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:group");
- group.put("operation", "operation:" + operation);
+ group.put("@type", KoralType.GROUP.toString());
+ group.put("operation", operation.toString());
group.put("operands", new ArrayList<Object>());
return group;
}
@@ -84,34 +91,33 @@
public static LinkedHashMap<String, Object> makeRepetition (Integer min,
Integer max) {
- LinkedHashMap<String, Object> group = makeGroup("repetition");
+ LinkedHashMap<String, Object> group = makeGroup(KoralOperation.REPETITION);
group.put("boundary", makeBoundary(min, max));
return group;
}
@Deprecated
- public static LinkedHashMap<String, Object> makePosition (String frame) {
+ public static LinkedHashMap<String, Object> makePosition (KoralFrame frame) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:group");
- group.put("operation", "operation:position");
- group.put("frame", "frame:" + frame);
+ group.put("@type", KoralType.GROUP.toString());
+ group.put("operation", KoralOperation.POSITION.toString());
+ group.put("frame", frame.toString());
group.put("operands", new ArrayList<Object>());
return group;
}
public static LinkedHashMap<String, Object> makePosition (
- String[] allowedFrames) {
+ List<KoralFrame> allowedFrames) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:group");
- group.put("operation", "operation:position");
- group.put("frames", Arrays.asList(allowedFrames));
+ group.put("@type", KoralType.GROUP.toString());
+ group.put("operation", KoralOperation.POSITION.toString());
+ group.put("frames", Converter.enumListToStringList(allowedFrames));
group.put("operands", new ArrayList<Object>());
return group;
}
-
public static LinkedHashMap<String, Object> makeSpanClass (int classId) {
return makeSpanClass(classId, false);
}
@@ -121,8 +127,8 @@
public static LinkedHashMap<String, Object> makeSpanClass (int classId,
boolean setBySystem) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:group");
- group.put("operation", "operation:class");
+ group.put("@type", KoralType.GROUP.toString());
+ group.put("operation", KoralOperation.CLASS.toString());
if (setBySystem) {
classId += 128;
qp.addMessage("A class has been introduced into the backend representation of "
@@ -136,11 +142,11 @@
public static LinkedHashMap<String, Object> makeClassRefCheck (
- ArrayList<String> check, Integer[] classIn, int classOut) {
+ ArrayList<ClassRefCheck> checks, Integer[] classIn, int classOut) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:group");
- group.put("operation", "operation:class");
- group.put("classRefCheck", check);
+ group.put("@type", KoralType.GROUP.toString());
+ group.put("operation", KoralOperation.CLASS.toString());
+ group.put("classRefCheck", Converter.enumListToStringList(checks));
group.put("classIn", Arrays.asList(classIn));
group.put("classOut", classOut);
group.put("operands", new ArrayList<Object>());
@@ -149,11 +155,11 @@
public static LinkedHashMap<String, Object> makeClassRefOp (
- String operation, Integer[] classIn, int classOut) {
+ ClassRefOp operation, Integer[] classIn, int classOut) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:group");
- group.put("operation", "operation:class");
- group.put("classRefOp", operation);
+ group.put("@type", KoralType.GROUP.toString());
+ group.put("operation", KoralOperation.CLASS.toString());
+ group.put("classRefOp", operation.toString());
group.put("classIn", Arrays.asList(classIn));
group.put("classOut", classOut);
group.put("operands", new ArrayList<Object>());
@@ -161,19 +167,19 @@
}
- @Deprecated
- public static LinkedHashMap<String, Object> makeTreeRelation (String reltype) {
- LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:treeRelation");
- if (reltype != null)
- group.put("reltype", reltype);
- return group;
- }
+// @Deprecated
+// public static LinkedHashMap<String, Object> makeTreeRelation (String reltype) {
+// LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
+// group.put("@type", "koral:treeRelation");
+// if (reltype != null)
+// group.put("reltype", reltype);
+// return group;
+// }
public static LinkedHashMap<String, Object> makeRelation () {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:relation");
+ group.put("@type", KoralType.RELATION.toString());
return group;
}
@@ -181,7 +187,7 @@
public static LinkedHashMap<String, Object> makeBoundary (Integer min,
Integer max) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:boundary");
+ group.put("@type", KoralType.BOUNDARY.toString());
group.put("min", min);
if (max != null) {
group.put("max", max);
@@ -194,10 +200,10 @@
Integer min, Integer max) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
if (key.equals("w")) {
- group.put("@type", "koral:distance");
+ group.put("@type", KoralType.DISTANCE.toString());
}
else {
- group.put("@type", "cosmas:distance");
+ group.put("@type", KoralType.COSMAS_DISTANCE.toString());
}
group.put("key", key);
group.put("boundary", makeBoundary(min, max));
@@ -213,10 +219,10 @@
public static LinkedHashMap<String, Object> makeReference (
- ArrayList<Integer> classRefs, String operation) {
+ ArrayList<Integer> classRefs, KoralOperation operation) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:reference");
- group.put("operation", "operation:" + operation);
+ group.put("@type", KoralType.REFERENCE.toString());
+ group.put("operation", operation.toString());
if (classRefs != null && !classRefs.isEmpty()) {
group.put("classRef", classRefs);
}
@@ -226,13 +232,13 @@
public static LinkedHashMap<String, Object> makeReference (
ArrayList<Integer> classRefs) {
- return makeReference(classRefs, "focus");
+ return makeReference(classRefs, KoralOperation.FOCUS);
}
@Deprecated
public static LinkedHashMap<String, Object> makeReference (int classRef,
- String operation, boolean setBySystem) {
+ KoralOperation operation, boolean setBySystem) {
ArrayList<Integer> classRefs = new ArrayList<Integer>();
if (setBySystem)
classRef = classRef + 128;
@@ -248,7 +254,7 @@
if (setBySystem)
classRef = classRef + 128;
classRefs.add(classRef);
- return makeReference(classRefs, "focus");
+ return makeReference(classRefs, KoralOperation.FOCUS);
}
@@ -260,8 +266,8 @@
@Deprecated
public static LinkedHashMap<String, Object> makeResetReference () {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:reference");
- group.put("operation", "operation:focus");
+ group.put("@type", KoralType.REFERENCE.toString());
+ group.put("operation", KoralOperation.FOCUS.toString());
group.put("reset", true);
group.put("operands", new ArrayList<Object>());
return group;
@@ -269,10 +275,10 @@
public static LinkedHashMap<String, Object> makeSpanReference (
- Integer[] spanRef, String operation) {
+ Integer[] spanRef, KoralOperation operation) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "koral:reference");
- group.put("operation", "operation:" + operation);
+ group.put("@type", KoralType.REFERENCE.toString());
+ group.put("operation", operation.toString());
group.put("spanRef", Arrays.asList(spanRef));
group.put("operands", new ArrayList<Object>());
return group;