Altered dominance serialization & added tests.
Change-Id: I7b03f804d48230157fa0b6c296ba130b6eb0da41
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 675b627..5dd557f 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
@@ -1,14 +1,16 @@
package de.ids_mannheim.korap.query.object;
-/** Definition of possible operations within koral:group.
+/**
+ * Definition of possible operations within koral:group.
+ *
* @author margaretha
*
*/
public enum KoralOperation {
- SEQUENCE, POSITION, DISJUNCTION, REPETITION, CLASS, MERGE, RELATION, FOCUS, EXCLUSION;
+ SEQUENCE, POSITION, DISJUNCTION, REPETITION, CLASS, MERGE, RELATION, FOCUS, EXCLUSION, HIERARCHY;
@Override
- public String toString() {
+ public String toString () {
return "operation:" + super.toString().toLowerCase();
}
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 a5f269f..5757625 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
@@ -715,6 +715,10 @@
group = KoralObjectGenerator.makeGroup(KoralOperation.SEQUENCE);
putAllButGroupType(group, operatorGroup);
}
+ else if (groupType.equals("hierarchy")) {
+ group = KoralObjectGenerator.makeGroup(KoralOperation.HIERARCHY);
+ putAllButGroupType(group, operatorGroup);
+ }
else if (groupType.equals("position")) {
group = new HashMap<String, Object>();
putAllButGroupType(group, operatorGroup);
@@ -851,20 +855,22 @@
String operator = getNodeCat(operatorNode);
// DOMINANCE
if (operator.equals("dominance")) {
- relation = KoralObjectGenerator.makeRelation();
- relation.put("groupType", "relation");
- ParseTree qName = getFirstChildWithCat(operatorNode, "qName");
+// relation = KoralObjectGenerator.makeRelation();
+ relation = new HashMap<String, Object>();
+ relation.put("groupType", "hierarchy");
+// ParseTree qName = getFirstChildWithCat(operatorNode, "qName");
ParseTree edgeSpecNode = getFirstChildWithCat(operatorNode,
"edgeSpec");
ParseTree star = getFirstChildWithCat(operatorNode, "*");
ParseTree rangeSpec = getFirstChildWithCat(operatorNode,
"rangeSpec");
- Map<String, Object> term = KoralObjectGenerator
- .makeTerm();
- term.put("layer", "c");
- if (qName != null)
- term = parseQNameNode(qName);
+
+// term.put("layer", "c");
+// if (qName != null)
+// term = parseQNameNode(qName);
if (edgeSpecNode != null) {
+ Map<String, Object> term = KoralObjectGenerator
+ .makeTerm();
Map<String, Object> edgeSpec = parseEdgeSpec(edgeSpecNode);
String edgeSpecType = (String) edgeSpec.get("@type");
if (edgeSpecType.equals("koral:termGroup")) {
@@ -872,22 +878,23 @@
term = edgeSpec;
}
else {
- term = KoralObjectGenerator.makeTermGroup(KoralTermGroupRelation.AND);
- ArrayList<Object> termGroupOperands = (ArrayList<Object>) term
- .get("operands");
- termGroupOperands.add(edgeSpec);
- Map<String, Object> constTerm = KoralObjectGenerator
- .makeTerm();
- constTerm.put("layer", "c");
- termGroupOperands.add(constTerm);
+ term = edgeSpec;
+// term = KoralObjectGenerator.makeTermGroup(KoralTermGroupRelation.AND);
+// ArrayList<Object> termGroupOperands = (ArrayList<Object>) term
+// .get("operands");
+// termGroupOperands.add(edgeSpec);
+// Map<String, Object> constTerm = KoralObjectGenerator
+// .makeTerm();
+// constTerm.put("layer", "c");
+// termGroupOperands.add(constTerm);
}
+ relation.put("label", term);
}
if (star != null)
relation.put("boundary",
KoralObjectGenerator.makeBoundary(0, null));
if (rangeSpec != null)
relation.put("boundary", boundaryFromRangeSpec(rangeSpec));
- relation.put("wrap", term);
}
else if (operator.equals("pointing")) {
relation = KoralObjectGenerator.makeRelation();
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 6949812..0222864 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
@@ -182,8 +182,7 @@
group.put("@type", KoralType.RELATION.toString());
return group;
}
-
-
+
public static Map<String, Object> makeBoundary (Integer min,
Integer max) {
Map<String, Object> group = new HashMap<String, Object>();
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/annis/AnnisQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/test/annis/AnnisQueryProcessorTest.java
index 066e615..effe058 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/annis/AnnisQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/annis/AnnisQueryProcessorTest.java
@@ -149,7 +149,7 @@
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("operation:relation", res
+ assertEquals("operation:hierarchy", res
.at("/query/operands/0/operation").asText());
assertEquals("frames:startsWith", res.at("/query/frames/0").asText());
assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
@@ -180,7 +180,7 @@
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("operation:relation", res
+ assertEquals("operation:hierarchy", res
.at("/query/operands/0/operation").asText());
assertEquals("frames:endsWith", res.at("/query/frames/0").asText());
assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
@@ -392,7 +392,7 @@
.asText());
assertEquals("koral:group", res
.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation",
+ assertEquals("operation:hierarchy",
res.at("/query/operands/0/operands/0/operation").asText());
assertEquals("koral:reference",
res.at("/query/operands/0/operands/0/operands/0/@type")
@@ -438,7 +438,7 @@
.asText());
assertEquals("koral:group", res
.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation",
+ assertEquals("operation:hierarchy",
res.at("/query/operands/0/operands/0/operation").asText());
assertEquals("koral:reference",
res.at("/query/operands/0/operands/0/operands/0/@type")
@@ -504,7 +504,7 @@
assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
assertEquals("koral:group", res
.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation",
+ assertEquals("operation:hierarchy",
res.at("/query/operands/0/operands/0/operation").asText());
assertEquals("koral:token",
res.at("/query/operands/0/operands/0/operands/0/@type")
@@ -542,7 +542,7 @@
assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
assertEquals("koral:group", res
.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation",
+ assertEquals("operation:hierarchy",
res.at("/query/operands/0/operands/0/operation").asText());
assertEquals("koral:token",
res.at("/query/operands/0/operands/0/operands/0/@type")
@@ -572,7 +572,7 @@
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("operation:hierarchy", res.at("/query/operation").asText());
assertEquals("koral:reference", res.at("/query/operands/0/@type")
.asText());
assertEquals("operation:focus", res.at("/query/operands/0/operation")
@@ -648,7 +648,7 @@
assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
assertEquals("koral:group", res
.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation",
+ assertEquals("operation:hierarchy",
res.at("/query/operands/0/operands/0/operation").asText());
assertEquals("operation:class",
res.at("/query/operands/0/operands/0/operands/0/operation")
@@ -859,11 +859,11 @@
query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("operation:hierarchy", res.at("/query/operation").asText());
assertEquals("operation:focus", res.at("/query/operands/0/operation")
.asText());
assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("operation:relation",
+ assertEquals("operation:hierarchy",
res.at("/query/operands/0/operands/0/operation").asText());
assertEquals("operation:class",
res.at("/query/operands/0/operands/0/operands/0/operation")
@@ -887,7 +887,7 @@
assertEquals("operation:focus", res.at("/query/operands/0/operation")
.asText());
assertEquals(130, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("operation:relation",
+ assertEquals("operation:hierarchy",
res.at("/query/operands/0/operands/0/operation").asText());
assertEquals("operation:focus",
res.at("/query/operands/0/operands/0/operands/0/operation")
@@ -896,7 +896,7 @@
res.at("/query/operands/0/operands/0/operands/0/classRef/0")
.asInt());
assertEquals(
- "operation:relation",
+ "operation:hierarchy",
res.at("/query/operands/0/operands/0/operands/0/operands/0/operation")
.asText());
assertEquals(
@@ -998,7 +998,7 @@
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("operation:hierarchy", res.at("/query/operation").asText());
assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
assertEquals("cnx", res.at("/query/operands/0/foundry").asText());
assertEquals("c", res.at("/query/operands/0/layer").asText());
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/annis/DominanceTests.java b/src/test/java/de/ids_mannheim/korap/query/test/annis/DominanceTests.java
index b36f6e4..ca8bce1 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/annis/DominanceTests.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/annis/DominanceTests.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.query.test.annis;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
@@ -12,261 +13,360 @@
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
+/**
+ * @author bingl, margaretha
+ *
+ */
public class DominanceTests {
private String query;
private QuerySerializer qs = new QuerySerializer();
private ObjectMapper mapper = new ObjectMapper();
private JsonNode res;
+
@Test
public void testDominanceWithArbitrarySpans ()
throws JsonProcessingException, IOException {
query = "node > node";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- // assertEquals("koral:group", res.at("/query/@type").asText());
- // assertEquals("operation:relation", res.at("/query/operation").asText());
- // assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- // assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- // assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- // assertEquals("koral:term", res.at("/query/relation/wrap/@type")
- // .asText());
- // assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
}
@Test
- public void testDominanceWithAnnotation1 ()
- throws JsonProcessingException, IOException {
- query = "node > cnx/c=\"np\"";
- qs.setQuery(query, "annis");
- res = mapper.readTree(qs.toJSON());
- // assertEquals("koral:group", res.at("/query/@type").asText());
- // assertEquals("operation:relation", res.at("/query/operation").asText());
- // assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- // assertEquals("koral: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("koral:relation", res.at("/query/relation/@type").asText());
- // assertEquals("koral:term", res.at("/query/relation/wrap/@type")
- // .asText());
- // assertEquals("c", res.at("/query/relation/wrap/layer").asText());
- }
-
-
- @Test
- public void testDominanceWithAnnotation2 ()
+ public void testDominanceWithAnnotationOnFirstOperand ()
throws JsonProcessingException, IOException {
query = "cnx/c=\"np\" > node";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- }
-
- @Test
- public void testDominanceWithReference ()
- throws JsonProcessingException, IOException {
- query = "cat=/NP/ & cat=/PP/ > #1";
- qs.setQuery(query, "annis");
- res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("np", 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("koral:span", res.at("/query/operands/1/@type").asText());
}
+
@Test
- public void testDominanceWithReference2 () throws JsonProcessingException,
- IOException {
+ public void testDominanceWithAnnotationOnSecondOperand ()
+ throws JsonProcessingException, IOException {
+ query = "node > cnx/c=\"np\"";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral: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());
+ }
+
+
+ @Test
+ public void testDominanceWithAnnotatedReferences ()
+ throws JsonProcessingException, IOException {
+ // cat=PP is a shorcut for const:cat="PP"
+ query = "cat=\"NP\" & cat=\"PP\" > #1";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("PP", res.at("/query/operands/0/key").asText());
+ assertEquals("c", res.at("/query/operands/0/layer").asText());
+ assertEquals("koral: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());
+ }
+
+
+ @Test
+ public void testDominanceWithAbritraryReferences ()
+ throws JsonProcessingException, IOException {
query = "node & node & #2 > #1";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
-// assertEquals("koral:group", res.at("/query/@type").asText());
-// assertEquals("operation:relation", res.at("/query/operation").asText());
-// assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
-// assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
-// assertEquals("koral:relation", res.at("/query/relation/@type").asText());
-// assertEquals("koral:term", res.at("/query/relation/wrap/@type")
-// .asText());
-// assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
}
-
+
+
@Test
public void testDominanceWithToken ()
throws JsonProcessingException, IOException {
query = "\"Mann\" & node & #2 > #1";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
-// assertEquals("koral:group", res.at("/query/@type").asText());
-// assertEquals("operation:relation", res.at("/query/operation").asText());
-// assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
-// assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
-// assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
-// assertEquals("koral:relation", res.at("/query/relation/@type").asText());
-// assertEquals("koral:term", res.at("/query/relation/wrap/@type")
-// .asText());
-// assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
}
-
-
+
+
@Test
- public void testDominanceFollowedByAnnotations () throws JsonProcessingException,
- IOException {
+ public void testDominanceFollowedByAnnotations ()
+ throws JsonProcessingException, IOException {
query = "#1 > #2 & cnx/cat=\"vp\" & cnx/cat=\"np\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
-// assertEquals("koral:group", res.at("/query/@type").asText());
-// assertEquals("operation:relation", res.at("/query/operation").asText());
-// assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
-// assertEquals("koral: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("koral: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("koral:relation", res.at("/query/relation/@type").asText());
-// assertEquals("koral:term", res.at("/query/relation/wrap/@type")
-// .asText());
-// assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral: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("koral: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());
}
-
+
+
@Test
- public void testIndirectDominance () throws JsonProcessingException,
- IOException {
+ public void testIndirectDominance ()
+ throws JsonProcessingException, IOException {
query = "node & node & #1 >2,4 #2";
qs.setQuery(query, "annis");
-// res = mapper.readTree(qs.toJSON());
-// assertEquals("koral:group", res.at("/query/@type").asText());
-// assertEquals("operation:relation", res.at("/query/operation").asText());
-// assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
-// assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
-// assertEquals("koral: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("koral:term", res.at("/query/relation/wrap/@type")
-// .asText());
-// assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ res = mapper.readTree(qs.toJSON());
+ System.out.println(res.asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals(2, res.at("/query/boundary/min").asInt());
+ assertEquals(4, res.at("/query/boundary/max").asInt());
+ assertTrue(res.at("/query/label").isMissingNode());
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());
+ assertEquals(0, res.at("/query/boundary/min").asInt());
+ assertTrue(res.at("/query/boundary/max").isMissingNode());
}
-
+
@Test
public void testDominanceWithType ()
throws JsonProcessingException, IOException {
- query = "\"Mann\" & node & #2 >[func=\"SB\"] #1"; //coordinates the func=SB term and requires a "c"-layer term (consituency relation/dominance)
+ query = "\"Mann\" & node & #2 >[func=\"SBJ\"] #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("koral:relation", res.at("/query/relation/@type").asText());
-// assertEquals("koral: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());
+ // System.out.println(res.asText());
+ // assertEquals("koral:relation",
+ // res.at("/query/relation/@type").asText());
+ // assertEquals("koral: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());
+
+ // {
+ // "@context": "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld",
+ // "query": {
+ // "operation": "operation:hierarchy",
+ // "operands": [
+ // {"@type": "koral:span"},
+ // {
+ // "wrap": {
+ // "@type": "koral:term",
+ // "layer": "orth",
+ // "match": "match:eq",
+ // "key": "Mann"
+ // },
+ // "@type": "koral:token"
+ // }
+ // ],
+ // "@type": "koral:group",
+ // "label": {
+ // "@type": "koral:term",
+ // "layer": "c",
+ // "match": "match:eq",
+ // "key": "SBJ"
+ // }
+ // }
+ // }
}
-
+
+
@Test
public void testDominanceWithMultipleTypes ()
throws JsonProcessingException, IOException {
query = "corenlp/c=\"VP\" & corenlp/c=\"NP\" & #1 >[malt/d=\"PP\" malt/d=\"PN\"] #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
+ System.out.println(res.asText());
+
+ // {
+ // "@context": "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld",
+ // "query": {
+ // "operation": "operation:hierarchy",
+ // "operands": [
+ // {
+ // "@type": "koral:span",
+ // "layer": "c",
+ // "foundry": "corenlp",
+ // "match": "match:eq",
+ // "key": "VP"
+ // },
+ // {
+ // "@type": "koral:span",
+ // "layer": "c",
+ // "foundry": "corenlp",
+ // "match": "match:eq",
+ // "key": "NP"
+ // }
+ // ],
+ // "@type": "koral:group",
+ // "label": {
+ // "operands": [
+ // {
+ // "@type": "koral:term",
+ // "layer": "d",
+ // "foundry": "malt",
+ // "match": "match:eq",
+ // "key": "PP"
+ // },
+ // {
+ // "@type": "koral:term",
+ // "layer": "d",
+ // "foundry": "malt",
+ // "match": "match:eq",
+ // "key": "PN"
+ // },
+ // {"@type": "koral:term"}
+ // ],
+ // "@type": "koral:termGroup",
+ // "relation": "relation:and"
+ // }
+ // }
+ // }
}
-
+
+
@Test
- public void testMultipleDominance () throws JsonProcessingException,
- IOException {
+ public void testMultipleDominance ()
+ throws JsonProcessingException, IOException {
query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
+ // System.out.println(res.asText());
assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type")
- .asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation")
- .asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operation").asText());
+ assertEquals("koral:reference",
+ res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/0/operation").asText());
assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("koral:group", res
- .at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation",
- res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:relation",
- res.at("/query/operands/0/operands/0/relation/@type").asText());
- assertEquals("c",
- res.at("/query/operands/0/operands/0/relation/wrap/layer")
- .asText());
- assertEquals("koral:span",
- res.at("/query/operands/0/operands/0/operands/0/@type")
- .asText());
- assertEquals("c",
- res.at("/query/operands/0/operands/0/operands/0/layer")
- .asText());
- assertEquals("CP", res
- .at("/query/operands/0/operands/0/operands/0/key").asText());
+
assertEquals("koral:group",
- res.at("/query/operands/0/operands/0/operands/1/@type")
- .asText());
+ res.at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:span", res
+ .at("/query/operands/0/operands/0/operands/0/@type").asText());
+ assertEquals("c", res
+ .at("/query/operands/0/operands/0/operands/0/layer").asText());
+ assertEquals("CP",
+ res.at("/query/operands/0/operands/0/operands/0/key").asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/operands/1/@type").asText());
assertEquals("operation:class",
res.at("/query/operands/0/operands/0/operands/1/operation")
.asText());
assertEquals(129,
res.at("/query/operands/0/operands/0/operands/1/classOut")
.asInt());
- assertEquals(
- "VP",
+ assertEquals("VP",
res.at("/query/operands/0/operands/0/operands/1/operands/0/key")
.asText());
}
- // query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
- // String dom1 =
- // "{@type=koral:group, operation=operation:relation, operands=[" +
- // "{@type=koral:reference, operation=operation:focus, classRef=[0], operands=[" +
- // "{@type=koral:group, operation=operation:relation, operands=[" +
- // "{@type=koral:span, layer=cat, key=CP, match=match:eq}," +
- // "{@type=koral:group, operation=operation:class, class=1, classOut=1, operands=[" +
- // "{@type=koral:span, layer=cat, key=VP, match=match:eq}" +
- // "]}" +
- // "], relation={@type=koral:relation, wrap={@type=koral:term, layer=c}}}" +
- // "]}," +
- // "{@type=koral:span, layer=cat, key=NP, match=match:eq}" +
- // "], relation={@type=koral:relation, wrap={@type=koral: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=koral:group, operation=operation:relation, operands=[" +
- // "{@type=koral:reference, operation=operation:focus, classRef=[1], operands=[" +
- // "{@type=koral:group, operation=operation:relation, operands=[" +
- // "{@type=koral:reference, operation=operation:focus, classRef=[0], operands=[" +
- // "{@type=koral:group, operation=operation:relation, operands=[" +
- // "{@type=koral:span, layer=cat, key=CP, match=match:eq}," +
- // "{@type=koral:group, operation=operation:class, class=1, classOut=1, operands=[" +
- // "{@type=koral:span, layer=cat, key=VP, match=match:eq}" +
- // "]}" +
- // "], relation={@type=koral:relation, wrap={@type=koral:term, layer=c}}}" +
- // "]}," +
- // "{@type=koral:group, operation=operation:class, class=2, classOut=2, operands=[" +
- // "{@type=koral:span, layer=cat, key=NP, match=match:eq}" +
- // "]}" +
- // "], relation={@type=koral:relation, wrap={@type=koral:term, layer=c}}}" +
- // "]}," +
- // "{@type=koral:span, layer=cat, key=DP, match=match:eq}" +
- // "], relation={@type=koral:relation, wrap={@type=koral:term, layer=c}}" +
- // "}";
- // aqlt = new AqlTree(query);
- // map = aqlt.getRequestMap().get("query").toString();
- // assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
- // }
+
+ @Test
+ public void testMultipleDominance2 ()
+ throws JsonProcessingException, IOException {
+ query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ System.out.println(res.asText());
+
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operation").asText());
+ assertEquals("koral:reference",
+ res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/0/operation").asText());
+ assertEquals(130, res.at("/query/operands/0/classRef/0").asInt());
+
+ assertEquals("c", res.at("/query/operands/1/layer").asText());
+ assertEquals("DP", res.at("/query/operands/1/key").asText());
+
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:hierarchy",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:reference", res
+ .at("/query/operands/0/operands/0/operands/0/@type").asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/0/classRef/0")
+ .asInt());
+
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals("NP",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/key")
+ .asText());
+
+ assertEquals("c",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/layer")
+ .asText());
+ assertEquals("CP",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals("VP",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/operands/0/key")
+ .asText());
+
+ }
}
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/annis/RelationTests.java b/src/test/java/de/ids_mannheim/korap/query/test/annis/RelationTests.java
index 053edc2..33658d7 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/annis/RelationTests.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/annis/RelationTests.java
@@ -2,7 +2,6 @@
import java.io.IOException;
-import org.junit.BeforeClass;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonProcessingException;