AQL >@l/@r (leftmost/rightmost child) now wraps relation in position (startswith/endswith)
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
index 81efa6e..7b9a7e4 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
@@ -179,7 +179,7 @@
group.put("frames", Arrays.asList(allowedFrames));
group.put("operands", new ArrayList<Object>());
// DEPRECATED 'frame'
- if (classRefCheck.length==0) classRefCheck = new String[]{"classRefCheck:includes"};
+ if (classRefCheck == null || classRefCheck.length==0) classRefCheck = new String[]{"classRefCheck:includes"};
String frame = "";
if (allowedFrames.length==0 && classRefCheck[0]=="classRefCheck:includes") {
@@ -320,18 +320,24 @@
return makeReference(classRefs, "focus");
}
- protected LinkedHashMap<String, Object> makeReference(int classRef, String operation) {
+ protected LinkedHashMap<String, Object> makeReference(int classRef, String operation, boolean setBySystem) {
ArrayList<Integer> classRefs = new ArrayList<Integer>();
+ if (setBySystem) classRef = classRef+128;
classRefs.add(classRef);
return makeReference(classRefs, operation);
}
- protected LinkedHashMap<String, Object> makeReference(int classRef) {
+ protected LinkedHashMap<String, Object> makeReference(int classRef, boolean setBySystem) {
ArrayList<Integer> classRefs = new ArrayList<Integer>();
+ if (setBySystem) classRef = classRef+128;
classRefs.add(classRef);
return makeReference(classRefs, "focus");
}
+ protected LinkedHashMap<String, Object> makeReference(int classRef) {
+ return makeReference(classRef, false);
+ }
+
protected LinkedHashMap<String, Object> makeResetReference() {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "korap:reference");
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
index 79d5fcb..64141aa 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
@@ -390,6 +390,18 @@
// Get operands list before possible re-assignment of 'group' (see following 'if')
operands = (ArrayList<Object>) group.get("operands");
+
+ ParseTree leftChildSpec = getFirstChildWithCat(node.getChild(i).getChild(0), "@l");
+ ParseTree rightChildSpec = getFirstChildWithCat(node.getChild(i).getChild(0), "@r");
+ if (leftChildSpec != null || rightChildSpec != null) { //XXX
+ String frame = (leftChildSpec!=null) ? "frames:startswith" : "frames:endswith";
+ LinkedHashMap<String,Object> positionGroup = makePosition(new String[]{frame}, null);
+ operand2 = wrapInClass(operand2, ++classCounter);
+ ((ArrayList<Object>) positionGroup.get("operands")).add(group);
+ ((ArrayList<Object>) positionGroup.get("operands")).add(makeReference(classCounter,true));
+ group = positionGroup;
+ }
+
// Wrap in reference object in case other relations are following
if (i < node.getChildCount()-2) {
group = wrapInReference(group, classCounter);
@@ -476,8 +488,6 @@
ParseTree rangeSpec = getFirstChildWithCat(operatorNode, "rangeSpec");
LinkedHashMap<String,Object> term = makeTerm();
term.put("layer", "c");
- if (leftChildSpec != null) relation.put("index", 0);
- if (rightChildSpec != null) relation.put("index", -1);
if (qName != null) term = parseQNameNode(qName);
if (edgeSpecNode != null) {
LinkedHashMap<String,Object> edgeSpec = parseEdgeSpec(edgeSpecNode);
@@ -726,7 +736,7 @@
* For testing
*/
String[] queries = new String[] {
- "cat=\"S\" & node & #1 >@l[func=\"SB\"] #2"
+ "cat=\"S\" & node & #1 >@l #2"
};
// AqlTree.verbose=true;
for (String q : queries) {
diff --git a/src/test/java/AqlTreeTest.java b/src/test/java/AqlTreeTest.java
index 61dbbc1..a2412bb 100644
--- a/src/test/java/AqlTreeTest.java
+++ b/src/test/java/AqlTreeTest.java
@@ -237,22 +237,39 @@
assertEquals("MO" , res.at("/query/relation/wrap/operands/1/key").asText());
assertEquals("c", res.at("/query/relation/wrap/operands/2/layer").asText());
- query = "cat=\"S\" & cat=\"NP\" & #1 >@l #2"; // all sentences starting with subject -> wrap operands in startswith and retrieve 2nd operand with focus
+ query = "cat=\"S\" & cat=\"NP\" & #1 >@l #2"; // all sentences starting with NP -> wrap relation in startswith and retrieve 2nd operand with focus
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:startswith", res.at("/query/operands/0/frames/0").asText());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("operation:relation", res.at("/query/operands/0/operation").asText());
+ assertEquals("frames:startswith", res.at("/query/frames/0").asText());
assertEquals("korap:span", res.at("/query/operands/0/operands/0/@type").asText());
assertEquals("S", res.at("/query/operands/0/operands/0/key").asText());
assertEquals("korap:group", res.at("/query/operands/0/operands/1/@type").asText());
assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(128, res.at("/query/operands/0/operands/1/classOut").asInt());
+ assertEquals(129, res.at("/query/operands/0/operands/1/classOut").asInt());
assertEquals("korap:span", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
assertEquals("NP", res.at("/query/operands/0/operands/1/operands/0/key").asText());
assertEquals("korap:reference", res.at("/query/operands/1/@type").asText());
assertEquals("operation:focus", res.at("/query/operands/1/operation").asText());
- assertEquals(128, res.at("/query/operands/1/classRef/0").asInt());
+ assertEquals(129, res.at("/query/operands/1/classRef/0").asInt());
+
+ query = "cat=\"S\" & cat=\"NP\" & #1 >@r #2";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("operation:relation", res.at("/query/operands/0/operation").asText());
+ assertEquals("frames:endswith", res.at("/query/frames/0").asText());
+ assertEquals("korap:span", res.at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("S", res.at("/query/operands/0/operands/0/key").asText());
+ assertEquals("korap:group", res.at("/query/operands/0/operands/1/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(129, res.at("/query/operands/0/operands/1/classOut").asInt());
+ assertEquals("korap:span", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
+ assertEquals("NP", res.at("/query/operands/0/operands/1/operands/0/key").asText());
+ assertEquals("korap:reference", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operands/1/operation").asText());
+ assertEquals(129, res.at("/query/operands/1/classRef/0").asInt());
}
@Test