- unified treeRelation and relation
- deleted reltype attribute
- foundry/layer specified before edgeAnno
- edgeAnno: [dummyword="key"]
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
index ed58e7d..1b2ff74 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
@@ -151,6 +151,7 @@
return group;
}
+ @Deprecated
protected LinkedHashMap<String, Object> makeTreeRelation(String reltype) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "korap:treeRelation");
@@ -158,10 +159,9 @@
return group;
}
- protected LinkedHashMap<String, Object> makeRelation(String reltype) {
+ protected LinkedHashMap<String, Object> makeRelation() {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "korap:relation");
- if (reltype != null) group.put("reltype", reltype);
return group;
}
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 61c0f23..68b5822 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
@@ -1,7 +1,5 @@
package de.ids_mannheim.korap.query.serialize;
-import static org.junit.Assert.assertEquals;
-
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
@@ -327,11 +325,14 @@
// make an (outer) group and an inner group containing the dummy node or previous relations
group = makeGroup("relation");
LinkedHashMap<String,Object> innerGroup = makeGroup("relation");
- LinkedHashMap<String,Object> treeRelation = makeTreeRelation("dominance");
+ LinkedHashMap<String,Object> relation = makeRelation();
+ LinkedHashMap<String,Object> term = makeTerm();
+ term.put("layer", "c");
+ relation.put("wrap", term);
// commonancestor is an indirect commonparent relation
- if (reltype.equals("commonancestor")) treeRelation.put("boundary", makeBoundary(1, MAXIMUM_DISTANCE));
- group.put("relation", treeRelation);
- innerGroup.put("relation", treeRelation);
+ if (reltype.equals("commonancestor")) relation.put("boundary", makeBoundary(1, MAXIMUM_DISTANCE));
+ group.put("relation", relation);
+ innerGroup.put("relation", relation);
// Get operands list before possible re-assignment of 'group' (see following 'if')
ArrayList<Object> outerOperands = (ArrayList<Object>) group.get("operands");
ArrayList<Object> innerOperands = (ArrayList<Object>) innerGroup.get("operands");
@@ -355,8 +356,8 @@
if (i < node.getChildCount()-2) {
group = wrapInReference(group, classCounter);
}
- // All other n-ary linguistic relations have special 'relation' attributes defined in CQLF and can be
- // handled more easily...
+ // All other n-ary linguistic relations have special 'relation' attributes defined in CQLF and can be
+ // handled more easily...
} else {
LinkedHashMap<String, Object> operatorGroup = parseOperatorNode(node.getChild(i).getChild(0));
String groupType;
@@ -367,9 +368,10 @@
}
group = makeGroup(groupType);
if (groupType.equals("relation") || groupType.equals("treeRelation")) {
- LinkedHashMap<String, Object> relationGroup = new LinkedHashMap<String, Object>();
- putAllButGroupType(relationGroup, operatorGroup);
- group.put("relation", relationGroup);
+ LinkedHashMap<String, Object> relation = new LinkedHashMap<String, Object>();
+ putAllButGroupType(relation, operatorGroup);
+ System.err.println(relation);
+ group.put("relation", relation);
} else if (groupType.equals("sequence") || groupType.equals("position")) {
putAllButGroupType(group, operatorGroup);
}
@@ -450,7 +452,7 @@
String operator = getNodeCat(operatorNode);
// DOMINANCE
if (operator.equals("dominance")) {
- relation = makeTreeRelation("dominance");
+ relation = makeRelation();
relation.put("groupType", "relation");
ParseTree leftChildSpec = getFirstChildWithCat(operatorNode, "@l");
ParseTree rightChildSpec = getFirstChildWithCat(operatorNode, "@r");
@@ -458,28 +460,31 @@
ParseTree edgeSpec = getFirstChildWithCat(operatorNode, "edgeSpec");
ParseTree star = getFirstChildWithCat(operatorNode, "*");
ParseTree rangeSpec = getFirstChildWithCat(operatorNode, "rangeSpec");
+ LinkedHashMap<String,Object> term = makeTerm();
+ term.put("layer", "c");
if (leftChildSpec != null) relation.put("index", 0);
if (rightChildSpec != null) relation.put("index", -1);
- if (qName != null) relation.putAll(parseQNameNode(qName));
- if (edgeSpec != null) relation.put("wrap", parseEdgeSpec(edgeSpec)) ;
- if (star != null) relation.put("distance", makeBoundary(0, 100));
+ if (qName != null) term = parseQNameNode(qName);
+ if (edgeSpec != null) term.putAll(parseEdgeSpec(edgeSpec));
+ if (star != null) relation.put("boundary", makeBoundary(0, null));
if (rangeSpec != null) relation.put("boundary", boundaryFromRangeSpec(rangeSpec));
-
+ relation.put("wrap", term);
}
else if (operator.equals("pointing")) {
// String reltype = operatorNode.getChild(1).toStringTree(parser);
- relation = makeRelation(null);
+ relation = makeRelation();
relation.put("groupType", "relation");
ParseTree qName = getFirstChildWithCat(operatorNode, "qName");
ParseTree edgeSpec = getFirstChildWithCat(operatorNode, "edgeSpec");
ParseTree star = getFirstChildWithCat(operatorNode, "*");
ParseTree rangeSpec = getFirstChildWithCat(operatorNode, "rangeSpec");
// if (qName != null) relation.putAll(parseQNameNode(qName));
- if (qName != null) relation.put("reltype", qName.getText());
- if (edgeSpec != null) relation.put("wrap", parseEdgeSpec(edgeSpec)) ;
- if (star != null) relation.put("distance", makeBoundary(0, 100));
+ LinkedHashMap<String,Object> term = makeTerm();
+ if (qName != null) term.putAll(parseQNameNode(qName));
+ if (edgeSpec != null) term.putAll(parseEdgeSpec(edgeSpec));
+ if (star != null) relation.put("boundary", makeBoundary(0, 100));
if (rangeSpec != null) relation.put("boundary", boundaryFromRangeSpec(rangeSpec));
-
+ relation.put("wrap", term);
}
else if (operator.equals("precedence")) {
relation = new LinkedHashMap<String, Object>();
@@ -544,12 +549,17 @@
return relation;
}
- private Object parseEdgeSpec(ParseTree edgeSpec) {
- ArrayList<Object> edgeAnnos = new ArrayList<Object>();
- for (ParseTree edgeAnno : getChildrenWithCat(edgeSpec, "edgeAnno")) {
- edgeAnnos.add(parseEdgeAnno(edgeAnno));
+ private LinkedHashMap<String,Object> parseEdgeSpec(ParseTree edgeSpec) {
+ List<ParseTree> annos = getChildrenWithCat(edgeSpec, "edgeAnno");
+ if (annos.size() == 1) return parseEdgeAnno(annos.get(0));
+ else {
+ LinkedHashMap<String,Object> termGroup = makeTermGroup("and");
+ ArrayList<Object> operands = (ArrayList<Object>) termGroup.get("operands");
+ for (ParseTree anno : annos) {
+ operands.add(parseEdgeAnno(anno));
+ }
+ return termGroup;
}
- return edgeAnnos;
}
private LinkedHashMap<String, Object> parseEdgeAnno(
@@ -692,7 +702,11 @@
"Katze=\"Hund\"",
"cnx/c=\"NP\"",
"cat=\"NP\"",
- "node & node & #1 .+ #2"
+ "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"
};
// AqlTree.verbose=true;
for (String q : queries) {
diff --git a/src/test/java/AqlTreeTest.java b/src/test/java/AqlTreeTest.java
index 44a8a5c..d22257d 100644
--- a/src/test/java/AqlTreeTest.java
+++ b/src/test/java/AqlTreeTest.java
@@ -90,7 +90,7 @@
"{@type=korap:group, operation=operation:relation, operands=[" +
"{@type=korap:span}," +
"{@type=korap:span}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -101,7 +101,7 @@
"{@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:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -116,7 +116,7 @@
"{@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:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -130,7 +130,7 @@
"{@type=korap:group, operation=operation:relation, operands=[" +
"{@type=korap:span}," +
"{@type=korap:span}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -141,7 +141,7 @@
"{@type=korap:group, operation=operation:relation, operands=[" +
"{@type=korap:span}," +
"{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -152,7 +152,7 @@
"{@type=korap:group, operation=operation:relation, operands=[" +
"{@type=korap:span}," +
"{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
- "], relation={@type=korap:treeRelation, reltype=dominance, wrap=[{@type=korap:term, layer=cat, key=NP, 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();
@@ -163,7 +163,7 @@
"{@type=korap:group, operation=operation:relation, operands=[" +
"{@type=korap:span}," +
"{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
- "], relation={@type=korap:treeRelation, reltype=dominance, index=0, wrap=[{@type=korap:term, layer=cat, key=NP, 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();
@@ -174,8 +174,7 @@
"{@type=korap:group, operation=operation:relation, operands=[" +
"{@type=korap:span}," +
"{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
- "], relation={@type=korap:treeRelation, reltype=dominance, " +
- "boundary={@type=korap:boundary, min=2, max=4}}" +
+ "], 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();
@@ -193,10 +192,10 @@
"{@type=korap:group, operation=operation:class, class=0, operands=[" +
"{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
"]}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
"]}," +
"{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -213,15 +212,15 @@
"{@type=korap:group, operation=operation:class, class=0, operands=[" +
"{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
"]}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
"]}," +
"{@type=korap:group, operation=operation:class, class=1, operands=[" +
"{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
"]}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
"]}," +
"{@type=korap:span, layer=cat, key=DP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -230,23 +229,23 @@
@Test
public void testPointingRelations() throws QueryException {
- query = "node & node & #2 ->label[coref=\"true\"] #1";
+ 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, reltype=label, wrap=[{@type=korap:term, layer=coref, key=true, match=match:eq}]}" +
+ "], 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 ->label[mate/coref=\"true\"] #1";
+ 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, reltype=label, wrap=[{@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}]}" +
+ "], 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();
@@ -380,7 +379,7 @@
"{@type=korap:group, operation=operation:class, class=0, operands=[" +
"{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
"]}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], 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=[" +
@@ -400,7 +399,7 @@
"{@type=korap:group, operation=operation:class, class=0, operands=[" +
"{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
"]}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], 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=[" +
@@ -422,16 +421,16 @@
"{@type=korap:span}" +
"]}," +
"{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
"]}," +
"{@type=korap:group, operation=operation:class, class=1, operands=[" +
"{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
"]}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}" +
"]}," +
"{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -543,10 +542,10 @@
"{@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:treeRelation, reltype=dominance}}" +
+ "], 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:treeRelation, reltype=dominance}}";
+ "], 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(" ", ""));
@@ -566,13 +565,13 @@
"{@type=korap:group, operation=operation:class, class=1, operands=[" +
"{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
"]}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], 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=2, operands=[" +
"{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
"]}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], 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]}" +
@@ -610,7 +609,7 @@
"{@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:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -628,10 +627,10 @@
"{@type=korap:span}" +
"]}," +
"{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
"]}," +
"{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
"";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -648,14 +647,14 @@
"{@type=korap:span}" +
"]}," +
"{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
"]}," +
"{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}" +
"]}," +
"{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
@@ -674,16 +673,16 @@
"{@type=korap:span}" +
"]}," +
"{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
"]}," +
"{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
"]}," +
"{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
"]}," +
"{@type=korap:span, layer=cat, key=CP, match=match:eq}" +
- "], relation={@type=korap:treeRelation, reltype=dominance}" +
+ "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
"}" +
"";
aqlt = new AqlTree(query);