- edgeAnnos comprise layer c for dominance relations
- towards jsonification of tests
- test: >@l to wrap operands in startswith (still need to implement)
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 ad2d5b7..79d5fcb 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
@@ -204,9 +204,10 @@
object.put("wrap", term);
}
} else if (firstChildNodeCat.equals("qName")) { // only (foundry/)?layer specified
- // may be token or span, depending on indicated layer! (e.g. cnx/cat=NP or mate/pos=NN)
+ // may be token or span, depending on indicated layer! (e.g. cnx/cat=NP vs mate/pos=NN)
+ // TODO generalize the list below -> look up layers associated with tokens rather than spans somewhere
HashMap<String, Object> qNameParse = parseQNameNode(node.getChild(0));
- if (Arrays.asList(new String[]{"pos", "lemma", "morph", "tok"}).contains(qNameParse.get("layer"))) {
+ if (Arrays.asList(new String[]{"p", "lemma", "m", "orth"}).contains(qNameParse.get("layer"))) {
object = makeToken();
LinkedHashMap<String, Object> term = makeTerm();
object.put("wrap", term);
@@ -227,10 +228,10 @@
if (object.get("@type").equals("korap:token")) {
HashMap<String, Object> term = (HashMap<String, Object>) object.get("wrap");
term.putAll(parseTextSpec(node.getChild(2)));
- term.put("match", parseMatchOperator(node.getChild(1)));
+ term.put("match", parseMatchOperator(getFirstChildWithCat(node, "eqOperator")));
} else {
object.putAll(parseTextSpec(node.getChild(2)));
- object.put("match", parseMatchOperator(node.getChild(1)));
+ object.put("match", parseMatchOperator(getFirstChildWithCat(node, "eqOperator")));
}
}
@@ -378,7 +379,6 @@
group = makeGroup(groupType);
LinkedHashMap<String, Object> relation = new LinkedHashMap<String, Object>();
putAllButGroupType(relation, operatorGroup);
- System.err.println(relation);
group.put("relation", relation);
} else if (groupType.equals("sequence")) {
group = makeGroup(groupType);
@@ -402,7 +402,7 @@
if (operand1 != null) operands.add(operand1);
if (operand2 != null) operands.add(operand2);
} else {
- // ... but things get a little more complicated here. The AST is of this form: (operand1 operator 1 operand2 operator2 operand3 operator3 ...)
+ // ... but things get a little more complicated here. The AST is of this form: (operand1 operator1 operand2 operator2 operand3 operator3 ...)
// but we'll have to serialize it in a nested, binary way: (((operand1 operator1 operand2) operator2 operand3) operator3 ...)
// the following code will do just that:
if (i == 1) {
@@ -460,6 +460,7 @@
return attr;
}
+ @SuppressWarnings("unchecked")
private LinkedHashMap<String, Object> parseOperatorNode(ParseTree operatorNode) {
LinkedHashMap<String, Object> relation = null;
String operator = getNodeCat(operatorNode);
@@ -470,7 +471,7 @@
ParseTree leftChildSpec = getFirstChildWithCat(operatorNode, "@l");
ParseTree rightChildSpec = getFirstChildWithCat(operatorNode, "@r");
ParseTree qName = getFirstChildWithCat(operatorNode, "qName");
- ParseTree edgeSpec = getFirstChildWithCat(operatorNode, "edgeSpec");
+ ParseTree edgeSpecNode = getFirstChildWithCat(operatorNode, "edgeSpec");
ParseTree star = getFirstChildWithCat(operatorNode, "*");
ParseTree rangeSpec = getFirstChildWithCat(operatorNode, "rangeSpec");
LinkedHashMap<String,Object> term = makeTerm();
@@ -478,7 +479,21 @@
if (leftChildSpec != null) relation.put("index", 0);
if (rightChildSpec != null) relation.put("index", -1);
if (qName != null) term = parseQNameNode(qName);
- if (edgeSpec != null) term.putAll(parseEdgeSpec(edgeSpec));
+ if (edgeSpecNode != null) {
+ LinkedHashMap<String,Object> edgeSpec = parseEdgeSpec(edgeSpecNode);
+ String edgeSpecType = (String) edgeSpec.get("@type");
+ if (edgeSpecType.equals("korap:termGroup")) {
+ ((ArrayList<Object>) edgeSpec.get("operands")).add(term);
+ term = edgeSpec;
+ } else {
+ term = makeTermGroup("and");
+ ArrayList<Object> termGroupOperands = (ArrayList<Object>) term.get("operands");
+ termGroupOperands.add(edgeSpec);
+ LinkedHashMap<String,Object> constTerm = makeTerm();
+ constTerm.put("layer", "c");
+ termGroupOperands.add(constTerm);
+ }
+ }
if (star != null) relation.put("boundary", makeBoundary(0, null));
if (rangeSpec != null) relation.put("boundary", boundaryFromRangeSpec(rangeSpec));
relation.put("wrap", term);
@@ -548,13 +563,13 @@
relation.put("groupType", "position");
}
else if (operator.equals("identity")) {
- //TODO
+ //TODO since ANNIS v. 3.1.6
}
else if (operator.equals("equalvalue")) {
- //TODO
+ //TODO since ANNIS v. 3.1.6
}
else if (operator.equals("notequalvalue")) {
- //TODO
+ //TODO since ANNIS v. 3.1.6
}
return relation;
}
@@ -573,15 +588,13 @@
}
}
- private LinkedHashMap<String, Object> parseEdgeAnno(
- ParseTree edgeAnnoSpec) {
+ private LinkedHashMap<String, Object> parseEdgeAnno(ParseTree edgeAnnoSpec) {
LinkedHashMap<String, Object> edgeAnno = new LinkedHashMap<String, Object>();
edgeAnno.put("@type", "korap:term");
- ParseTree qNameNode = edgeAnnoSpec.getChild(0);
- ParseTree matchOperatorNode = edgeAnnoSpec.getChild(1);
- ParseTree textSpecNode = edgeAnnoSpec.getChild(2);
- ParseTree layerNode = getFirstChildWithCat(qNameNode, "layer");
- ParseTree foundryNode = getFirstChildWithCat(qNameNode, "foundry");
+ ParseTree textSpecNode = getFirstChildWithCat(edgeAnnoSpec, "textSpec");
+ ParseTree layerNode = getFirstChildWithCat(edgeAnnoSpec, "layer");
+ ParseTree foundryNode = getFirstChildWithCat(edgeAnnoSpec, "foundry");
+ ParseTree matchOperatorNode = getFirstChildWithCat(edgeAnnoSpec, "eqOperator");
if (foundryNode!=null) edgeAnno.put("foundry", foundryNode.getChild(0).toStringTree(parser));
if (layerNode!=null) edgeAnno.put("layer", layerNode.getChild(0).toStringTree(parser));
edgeAnno.putAll(parseTextSpec(textSpecNode));
@@ -628,7 +641,10 @@
* @return
*/
private String parseMatchOperator(ParseTree node) {
- return node.toStringTree(parser).equals("=") ? "match:eq" : "match:ne";
+ if (node.getChildCount()>0) {
+ return node.getChild(0).toStringTree(parser).equals("=") ? "match:eq" : "match:ne";
+ }
+ return null;
}
private LinkedHashMap<String, Object> parseQNameNode(ParseTree node) {
@@ -636,7 +652,10 @@
ParseTree layerNode = getFirstChildWithCat(node, "layer");
ParseTree foundryNode = getFirstChildWithCat(node, "foundry");
if (foundryNode != null) fields.put("foundry", foundryNode.getChild(0).toStringTree(parser));
- fields.put("layer", layerNode.getChild(0).toStringTree(parser));
+ String layer = layerNode.getChild(0).toStringTree(parser);
+ if (layer.equals("pos")) layer = "p";
+ if (layer.equals("cat")) layer = "c";
+ fields.put("layer", layer);
return fields;
}
@@ -707,26 +726,7 @@
* For testing
*/
String[] queries = new String[] {
-// "cat=\"NP\" & cat=\"VP\" & #1 $ #2 ",
-// "Haus",
-// "lemma=\"Haus\"",
-// "Katze=\"Hund\"",
-// "cnx/c=\"NP\"",
-// "cat=\"NP\"",
-// "node & node & #1 .+ #2",
-// " #1 > #2 & cnx/cat=\"VP\" & cnx/cat=\"NP\"",
-// "\"Mann\" & node & #2 >[cat=\"NP\"] #1",
-// "node & node & #2 ->coref[val=\"true\"] #1",
-// "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3",
-// "tok=\"Mann\" & tok=\"geht\" & #1 .* #2",
-// "\"Sonne\"",
-// "\"so\" & ( \"nicht\" | \"doch\" ) & #1 .1,6 #2",
-//
-// "NP#cat=\"NP\" & PP1#cat=\"PP\" . PP2#cat=\"PP\" & #NP > #PP1 & #NP > #PP2 ",
-// "cat=\"NP\" > cat=\"VP\" & #1 _l_ #2",
-// "cat=\"NP\" > cat=\"VP\" & #1 . tok=\"foo\"",
- "cat=\"NP\" & cat=\"VP\" & #1 > #2 & #1 _l_ #2",
- "tok"
+ "cat=\"S\" & node & #1 >@l[func=\"SB\"] #2"
};
// AqlTree.verbose=true;
for (String q : queries) {
@@ -742,4 +742,4 @@
}
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/AqlTreeTest.java b/src/test/java/AqlTreeTest.java
index 9e0aa59..61dbbc1 100644
--- a/src/test/java/AqlTreeTest.java
+++ b/src/test/java/AqlTreeTest.java
@@ -1,739 +1,831 @@
import static org.junit.Assert.*;
+import java.io.IOException;
+import java.util.ArrayList;
+
import org.junit.Test;
-import de.ids_mannheim.korap.query.serialize.AqlTree;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import de.ids_mannheim.korap.query.serialize.QuerySerializer;
import de.ids_mannheim.korap.util.QueryException;
+/**
+ * Tests for JSON-LD serialization of ANNIS QL queries.
+ * @author Joachim Bingel (bingel@ids-mannheim.de)
+ * @version 1.0
+ */
public class AqlTreeTest {
- AqlTree aqlt;
- String map;
- private String query;
+ String query;
+ ArrayList<JsonNode> operands;
- private boolean equalsQueryContent(String res, String query) throws QueryException {
- res = res.replaceAll(" ", "");
- aqlt = new AqlTree(query);
- String queryMap = aqlt.getRequestMap().get("query").toString().replaceAll(" ", "");
- return res.equals(queryMap);
+ QuerySerializer qs = new QuerySerializer();
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res;
+
+ @Test
+ public void testContext() throws QueryException, JsonProcessingException, IOException {
+ String contextUrl = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld";
+ query = "foo";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals(contextUrl, res.get("@context").asText());
}
@Test
- public void testContext() throws QueryException {
- String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld";
- aqlt = new AqlTree("Test");
- assertEquals(contextString.replaceAll(" ", ""), aqlt.getRequestMap().get("@context").toString().replaceAll(" ", ""));
- }
-
- @Test
- public void testSingleTokens() throws QueryException {
- // "Mann"
+ public void testSingleTokens() throws QueryException, JsonProcessingException, IOException {
query = "\"Mann\"";
- String token1 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}";
- assertTrue(equalsQueryContent(token1, query));
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:token", res.at("/query/@type").asText());
+ assertEquals("korap:term", res.at("/query/wrap/@type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("Mann", res.at("/query/wrap/key").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
- // [orth!=Frau]
query = "tok!=\"Frau\"";
- String token2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:ne}}";
- assertTrue(equalsQueryContent(token2, query));
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:token", res.at("/query/@type").asText());
+ assertEquals("korap:term", res.at("/query/wrap/@type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("Frau", res.at("/query/wrap/key").asText());
+ assertEquals("match:ne", res.at("/query/wrap/match").asText());
- // Mann
- query = "Mann";
- String token4 = "{@type=korap:span, layer=Mann}";
- assertTrue(equalsQueryContent(token4, query));
+ query = "tok"; // special keyword for token
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:token", res.at("/query/@type").asText());
- // tok
- query = "tok";
- String token5 = "{@type=korap:token}";
- assertTrue(equalsQueryContent(token5, query));
+ query = "Mann"; // no special keyword -> defaults to layer name
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:span", res.at("/query/@type").asText());
+ assertEquals("Mann", res.at("/query/layer").asText());
}
@Test
- public void testSpans() throws QueryException {
- query = "node";
- String span1 =
- "{@type=korap:span}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(span1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ public void testSpans() throws QueryException, JsonProcessingException, IOException {
+ query = "node"; // special keyword for general span
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:span", res.at("/query/@type").asText());
+
+ query = "cat=\"np\""; // cat is special keyword for spans
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:span", res.at("/query/@type").asText());
+ assertEquals("np", res.at("/query/key").asText());
+ assertEquals("c", res.at("/query/layer").asText());
+
+ query = "cat=\"NP\"";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:span", res.at("/query/@type").asText());
+ assertEquals("NP", res.at("/query/key").asText());
+ assertEquals("c", res.at("/query/layer").asText());
}
@Test
- public void testRegex() throws QueryException {
- query = "/Mann/";
- String regex1 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=Mann, match=match:eq}}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(regex1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ public void testRegex() throws QueryException, JsonProcessingException, IOException {
+ query = "/Mann/";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:token", res.at("/query/@type").asText());
+ assertEquals("korap:term", res.at("/query/wrap/@type").asText());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("Mann", res.at("/query/wrap/key").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
- query = "/.*?Mann.*?/";
- String regex2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=.*?Mann.*?, match=match:eq}}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(regex2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ query = "/.*?Mann.*?/";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText());
}
-
- @Test
- public void testLayers() throws QueryException {
- query = "cnx/cat=\"NP\"";
- String layers1 = "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(layers1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "treetagger/pos=\"NN\"";
- String layers2 = "{@type=korap:token, wrap={@type=korap:term, foundry=treetagger, layer=pos, key=NN, match=match:eq}}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(layers2.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
-
- @Test
- public void testDirectDeclarationRelations() throws QueryException {
- query = "node > node";
- String ddr1 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(ddr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "node > cnx/cat=\"NP\"";
- String ddr2 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(ddr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- }
-
- @Test
- public void testDefPredicationInversion() throws QueryException {
- query = " #1 > #2 & cnx/cat=\"VP\" & cnx/cat=\"NP\"";
- String dom1 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span, foundry=cnx, layer=cat, key=VP, match=match:eq}," +
- "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
-
- @Test
- public void testSimpleDominance() throws QueryException {
- query = "node & node & #2 > #1";
- String dom1 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "\"Mann\" & node & #2 > #1";
- String dom2 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "\"Mann\" & node & #2 >[cat=\"NP\"] #1";
- String dom3 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c, key=NP, match=match:eq}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(dom3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "\"Mann\" & node & #2 >@l[cat=\"NP\"] #1";
- String dom4 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
- "], relation={@type=korap:relation, index=0, wrap={@type=korap:term, layer=c, key=NP, match=match:eq}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(dom4.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "\"Mann\" & node & #2 >2,4 #1";
- String dom5 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
- "], relation={@type=korap:relation, boundary={@type=korap:boundary, min=2, max=4}, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(dom5.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
-
- @Test
- public void testMultipleDominance() throws QueryException {
- query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
- String dom1 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "]}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4";
- String dom2 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "]}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
- "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "]}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=DP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
-
- @Test
- public void testPointingRelations() throws QueryException {
- query = "node & node & #2 ->coref[val=\"true\"] #1";
- String dom1 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=coref, key=true, match=match:eq}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "node & node & #2 ->mate/coref[val=\"true\"] #1";
- String dom2 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
-
- @Test
- public void testSequence() throws QueryException {
- query = "node & node & #1 . #2";
- String seq1 =
- "{@type=korap:group, operation=operation:sequence, " +
- "operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span}" +
- "], inOrder=true" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "node & node & #1 .* #2";
- String seq2 =
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span}" +
- "], distances=[" +
- "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0}, min=0}" +
- "], inOrder=true" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "node & node & #1 .2,3 #2";
- String seq3 =
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span}" +
- "], distances=[" +
- "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" +
- "], inOrder=true" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- }
-
- @Test
- public void testMultipleSequence() throws QueryException {
- query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 .0,2 #2 .0,4 #3";
- String seq4 =
- "{@type=korap:group, operation=operation:sequence," +
- "operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
- "]}" +
- "], distances=[" +
- "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
- "], inOrder=true}" +
- "]}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
- "],distances=[" +
- "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
- "], inOrder=true" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "node & node & node & #1 . #2 .1,3 #3";
- String seq5 =
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:span}" +
- "]} "+
- "], inOrder=true}" +
- "]}," +
- "{@type=korap:span}" +
- "], distances=[" +
- "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3}" +
- "], inOrder=true" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & tok=\"Himmel\" & #1 .0,2 #2 .0,4 #3 . #4";
- String seq6 =
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
- "]}" +
- "], distances=[" +
- "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
- "], inOrder=true}" +
- "]}," +
- "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
- "]}" +
- "],distances=[" +
- "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
- "], inOrder=true}" +
- "]}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Himmel, match=match:eq}}" +
- "], inOrder=true}" ;
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(seq6.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
-
- @Test
- public void testMultipleMixedOperators() throws QueryException {
- query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .0,4 #3";
- String seq4 =
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
- "]}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
- "], distances=[" +
- "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
- "], inOrder=true" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\"";
- String seq5 =
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
- "]}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
- "], distances=[" +
- "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
- "], inOrder=true" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3";
- String cp2 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:span}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
- "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "]}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
- /*
- @Test
- public void testMultipleOperatorsWithSameOperands() throws QueryException {
-
- query = "cat=\"NP\" > cat=\"VP\" & #1 _l_ #2";
- String eq2 =
- "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:group, operation=operation:class, class=, classOut=129, operands=[" +
- "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "]}," +
- "{@type=korap:group, operation=operation:class, class=, classOut=129, operands=[" +
- "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "]}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}," +
- "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
- "]" +
- "}"; // ???
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(eq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
- */
- @Test
- public void testPositions() throws QueryException {
- query = "node & node & #2 _=_ #1";
- String pos1 =
- "{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span}" +
- "], frame=frame:matches}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "node & node & #2 _i_ #1";
- String pos2 =
- "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span}" +
- "], frame=frame:contains" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(pos2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "node & node & #2 _l_ #1";
- String pos3 =
- "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:span}" +
- "], frame=frame:startswith" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "node & \"Mann\" & #1 _r_ #2";
- String pos4 =
- "{@type=korap:group, operation=operation:position, frames=[frames:endswith], operands=[" +
- "{@type=korap:span}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
- "], frame=frame:endswith" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "node & \"Mann\" & #2 _r_ #1";
- String pos5 =
- "{@type=korap:group, operation=operation:position, frames=[frames:endswith], operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
- "{@type=korap:span}" +
- "], frame=frame:endswith" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
-
- @Test
- public void testMultiplePredications() throws QueryException {
- // a noun before a verb before a preposition
- query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3";
- String mult1 =
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
- "]}" +
- "], inOrder=true}" +
- "]}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
- "], inOrder=true}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(mult1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- // a noun before a verb before a preposition
- query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\"";
- String mult2 =
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
- "]}" +
- "], inOrder=true}" +
- "]}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
- "], inOrder=true}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(mult2.replaceAll(" ", ""), map.replaceAll(" ", ""));
- query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3";
- String mult3 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
- "]}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(mult3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3";
- String mult4 =
- "{@type=korap:group, operation=operation:sequence, operands=[" +
- // reduce dominance relations "#1 > #2 & #1 > #3" to operand #2 in order to make it accessible for #2 . #3 (the last/outermost relation)
- "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- // dominance relation #1 > #2 is reduced to #1, for expressing #1 > #3
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "]}," +
- "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
- "]}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- // establish class 2 around P for later reference
- "{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
- "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
- "]}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- // refer back to class 2 as second operand
- "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
- "], inOrder=true}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(mult4.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
-
@Test
- public void testUnaryRelations() throws QueryException {
- query = "node & #1:tokenarity=2";
- String unary1 =
- "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ public void testFoundriesLayers() throws QueryException, JsonProcessingException, IOException {
+ query = "c=\"np\"";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:span", res.at("/query/@type").asText());
+ assertEquals("np", res.at("/query/key").asText());
+ assertEquals("c", res.at("/query/layer").asText());
- query = "cnx/cat=\"NP\" & #1:tokenarity=2";
- String unary2 =
- "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ query = "cnx/c=\"np\"";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:span", res.at("/query/@type").asText());
+ assertEquals("np", res.at("/query/key").asText());
+ assertEquals("c", res.at("/query/layer").asText());
+ assertEquals("cnx", res.at("/query/foundry").asText());
- query = "cnx/cat=\"NP\" & #1:root";
- String unary3 =
- "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2";
- String unary4 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," +
- "{@type=korap:span}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
-
- @Test
- public void testCommonParent() throws QueryException {
- query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2";
- String cp1 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:span}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(cp1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3";
- String cp2 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:span}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & cat=\"CP\" & #1 $ #2 $ #3 $ #4";
- String cp3 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:span}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=CP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
- "}" +
- "";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "cat=\"NP\" & cat=\"VP\" & #1 $* #2";
- String cp4 =
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
- "{@type=korap:group, operation=operation:relation, operands=[" +
- "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
- "{@type=korap:span}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
- "]}," +
- "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
- "";
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(cp4.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ query = "tt/pos=\"np\"";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:token", res.at("/query/@type").asText());
+ assertEquals("korap:term", res.at("/query/wrap/@type").asText());
+ assertEquals("np", res.at("/query/wrap/key").asText());
+ assertEquals("p", res.at("/query/wrap/layer").asText());
+ assertEquals("tt", res.at("/query/wrap/foundry").asText());
}
+ @Test
+ public void testDirectDeclarationRelations() throws QueryException, JsonProcessingException, IOException {
+ query = "node > node";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("korap:relation", res.at("/query/relation/@type").asText());
+ assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+
+ query = "node > cnx/c=\"np\"";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("np", res.at("/query/operands/1/key").asText());
+ assertEquals("c", res.at("/query/operands/1/layer").asText());
+ assertEquals("cnx", res.at("/query/operands/1/foundry").asText());
+ assertEquals("korap:relation", res.at("/query/relation/@type").asText());
+ assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+
+ query = "cnx/c=\"np\" > node";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals(true, res.at("/query/operands/1/key").isMissingNode());
+ assertEquals("np", res.at("/query/operands/0/key").asText());
+ }
+
+ @Test
+ public void testDefPredicationInversion() throws QueryException, JsonProcessingException, IOException {
+ query = "#1 > #2 & cnx/cat=\"vp\" & cnx/cat=\"np\"";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("vp", res.at("/query/operands/0/key").asText());
+ assertEquals("c", res.at("/query/operands/0/layer").asText());
+ assertEquals("cnx", res.at("/query/operands/0/foundry").asText());
+ assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("np", res.at("/query/operands/1/key").asText());
+ assertEquals("c", res.at("/query/operands/1/layer").asText());
+ assertEquals("cnx", res.at("/query/operands/1/foundry").asText());
+ assertEquals("korap:relation", res.at("/query/relation/@type").asText());
+ assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ }
+
+ @Test
+ public void testSimpleDominance() throws QueryException, JsonProcessingException, IOException {
+ query = "node & node & #2 > #1";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("korap:relation", res.at("/query/relation/@type").asText());
+ assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+
+ query = "\"Mann\" & node & #2 > #1";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("korap:relation", res.at("/query/relation/@type").asText());
+ assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+
+ query = "\"Mann\" & node & #2 >[func=\"SB\"] #1"; //coordinates the func=SB term and requires a "c"-layer term (consituency relation/dominance)
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:relation", res.at("/query/relation/@type").asText());
+ assertEquals("korap:termGroup", res.at("/query/relation/wrap/@type").asText());
+ assertEquals("relation:and", res.at("/query/relation/wrap/relation").asText());
+ assertEquals("c", res.at("/query/relation/wrap/operands/1/layer").asText());
+ assertEquals("func", res.at("/query/relation/wrap/operands/0/layer").asText());
+ assertEquals("SB", res.at("/query/relation/wrap/operands/0/key").asText());
+
+ query = "cat=\"S\" & node & #1 >[func=\"SB\" func=\"MO\"] #2"; // quite meaningless (function is subject and modifier), but this is allowed by Annis, however its backend only regards the 1st option
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:relation", res.at("/query/relation/@type").asText());
+ assertEquals("korap:termGroup", res.at("/query/relation/wrap/@type").asText());
+ assertEquals("relation:and", res.at("/query/relation/wrap/relation").asText());
+ assertEquals("func", res.at("/query/relation/wrap/operands/0/layer").asText());
+ assertEquals("SB", res.at("/query/relation/wrap/operands/0/key").asText());
+ assertEquals("func", res.at("/query/relation/wrap/operands/1/layer").asText());
+ 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
+ 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("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("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());
+ }
+
+ @Test
+ public void testIndirectDominance() throws QueryException, JsonProcessingException, IOException {
+ query = "node & node & #1 >2,4 #2";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("korap:relation", res.at("/query/relation/@type").asText());
+ assertEquals(2, res.at("/query/relation/boundary/min").asInt());
+ assertEquals(4, res.at("/query/relation/boundary/max").asInt());
+ assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+
+ query = "node & node & #1 >* #2";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals(0, res.at("/query/relation/boundary/min").asInt());
+ assertEquals(true, res.at("/query/relation/boundary/max").isMissingNode());
+ }
+
+ //
+// @Test
+// public void testMultipleDominance() throws QueryException {
+// query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
+// String dom1 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
+// "]}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4";
+// String dom2 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
+// "]}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
+// "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+// "]}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=DP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+// }
+//
+// @Test
+// public void testPointingRelations() throws QueryException {
+// query = "node & node & #2 ->coref[val=\"true\"] #1";
+// String dom1 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:span}," +
+// "{@type=korap:span}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=coref, key=true, match=match:eq}}" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "node & node & #2 ->mate/coref[val=\"true\"] #1";
+// String dom2 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:span}," +
+// "{@type=korap:span}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}}" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+// }
+//
+// @Test
+// public void testSequence() throws QueryException {
+// query = "node & node & #1 . #2";
+// String seq1 =
+// "{@type=korap:group, operation=operation:sequence, " +
+// "operands=[" +
+// "{@type=korap:span}," +
+// "{@type=korap:span}" +
+// "], inOrder=true" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "node & node & #1 .* #2";
+// String seq2 =
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:span}," +
+// "{@type=korap:span}" +
+// "], distances=[" +
+// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0}, min=0}" +
+// "], inOrder=true" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "node & node & #1 .2,3 #2";
+// String seq3 =
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:span}," +
+// "{@type=korap:span}" +
+// "], distances=[" +
+// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" +
+// "], inOrder=true" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// }
+//
+// @Test
+// public void testMultipleSequence() throws QueryException {
+// query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 .0,2 #2 .0,4 #3";
+// String seq4 =
+// "{@type=korap:group, operation=operation:sequence," +
+// "operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
+// "]}" +
+// "], distances=[" +
+// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
+// "], inOrder=true}" +
+// "]}," +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
+// "],distances=[" +
+// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
+// "], inOrder=true" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "node & node & node & #1 . #2 .1,3 #3";
+// String seq5 =
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:span}," +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:span}" +
+// "]} "+
+// "], inOrder=true}" +
+// "]}," +
+// "{@type=korap:span}" +
+// "], distances=[" +
+// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3}" +
+// "], inOrder=true" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & tok=\"Himmel\" & #1 .0,2 #2 .0,4 #3 . #4";
+// String seq6 =
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
+// "]}" +
+// "], distances=[" +
+// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
+// "], inOrder=true}" +
+// "]}," +
+// "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
+// "]}" +
+// "],distances=[" +
+// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
+// "], inOrder=true}" +
+// "]}," +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Himmel, match=match:eq}}" +
+// "], inOrder=true}" ;
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(seq6.replaceAll(" ", ""), map.replaceAll(" ", ""));
+// }
+//
+// @Test
+// public void testMultipleMixedOperators() throws QueryException {
+// query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .0,4 #3";
+// String seq4 =
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
+// "]}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
+// "], distances=[" +
+// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
+// "], inOrder=true" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\"";
+// String seq5 =
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
+// "]}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
+// "], distances=[" +
+// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
+// "], inOrder=true" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3";
+// String cp2 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:span}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
+// "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
+// "]}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
+// "}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+// }
+// /*
+// @Test
+// public void testMultipleOperatorsWithSameOperands() throws QueryException {
+//
+// query = "cat=\"NP\" > cat=\"VP\" & #1 _l_ #2";
+// String eq2 =
+// "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:group, operation=operation:class, class=, classOut=129, operands=[" +
+// "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+// "]}," +
+// "{@type=korap:group, operation=operation:class, class=, classOut=129, operands=[" +
+// "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
+// "]}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}," +
+// "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
+// "]" +
+// "}"; // ???
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(eq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+// }
+// */
+// @Test
+// public void testPositions() throws QueryException {
+// query = "node & node & #2 _=_ #1";
+// String pos1 =
+// "{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
+// "{@type=korap:span}," +
+// "{@type=korap:span}" +
+// "], frame=frame:matches}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "node & node & #2 _i_ #1";
+// String pos2 =
+// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
+// "{@type=korap:span}," +
+// "{@type=korap:span}" +
+// "], frame=frame:contains" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(pos2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "node & node & #2 _l_ #1";
+// String pos3 =
+// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
+// "{@type=korap:span}," +
+// "{@type=korap:span}" +
+// "], frame=frame:startswith" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "node & \"Mann\" & #1 _r_ #2";
+// String pos4 =
+// "{@type=korap:group, operation=operation:position, frames=[frames:endswith], operands=[" +
+// "{@type=korap:span}," +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
+// "], frame=frame:endswith" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "node & \"Mann\" & #2 _r_ #1";
+// String pos5 =
+// "{@type=korap:group, operation=operation:position, frames=[frames:endswith], operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
+// "{@type=korap:span}" +
+// "], frame=frame:endswith" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
+// }
+//
+// @Test
+// public void testMultiplePredications() throws QueryException {
+// // a noun before a verb before a preposition
+// query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3";
+// String mult1 =
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
+// "]}" +
+// "], inOrder=true}" +
+// "]}," +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
+// "], inOrder=true}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(mult1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// // a noun before a verb before a preposition
+// query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\"";
+// String mult2 =
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
+// "]}" +
+// "], inOrder=true}" +
+// "]}," +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
+// "], inOrder=true}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(mult2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3";
+// String mult3 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
+// "]}," +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(mult3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3";
+// String mult4 =
+// "{@type=korap:group, operation=operation:sequence, operands=[" +
+// // reduce dominance relations "#1 > #2 & #1 > #3" to operand #2 in order to make it accessible for #2 . #3 (the last/outermost relation)
+// "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// // dominance relation #1 > #2 is reduced to #1, for expressing #1 > #3
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+// "]}," +
+// "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
+// "]}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// // establish class 2 around P for later reference
+// "{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
+// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
+// "]}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// // refer back to class 2 as second operand
+// "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
+// "], inOrder=true}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(mult4.replaceAll(" ", ""), map.replaceAll(" ", ""));
+// }
+//
+// @Test
+// public void testUnaryRelations() throws QueryException {
+// query = "node & #1:tokenarity=2";
+// String unary1 =
+// "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "cnx/cat=\"NP\" & #1:tokenarity=2";
+// String unary2 =
+// "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "cnx/cat=\"NP\" & #1:root";
+// String unary3 =
+// "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2";
+// String unary4 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," +
+// "{@type=korap:span}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", ""));
+// }
+//
+// @Test
+// public void testCommonParent() throws QueryException {
+// query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2";
+// String cp1 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:span}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(cp1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3";
+// String cp2 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:span}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
+// "}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
+// "}";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & cat=\"CP\" & #1 $ #2 $ #3 $ #4";
+// String cp3 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:span}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=CP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
+// "}" +
+// "";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+// query = "cat=\"NP\" & cat=\"VP\" & #1 $* #2";
+// String cp4 =
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+// "{@type=korap:group, operation=operation:relation, operands=[" +
+// "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
+// "{@type=korap:span}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
+// "]}," +
+// "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
+// "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
+// "";
+// aqlt = new AqlTree(query);
+// map = aqlt.getRequestMap().get("query").toString();
+// assertEquals(cp4.replaceAll(" ", ""), map.replaceAll(" ", ""));
+// }
+
/*
@Test
public void testEqualNotequalValue() throws QueryException {
@@ -746,4 +838,4 @@
}
*/
-}
\ No newline at end of file
+}