cosmas element attributes
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
index a5c6969..7ec22f7 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
@@ -316,6 +316,15 @@
elname = 1;
}
if (node.getChildCount() > elname) {
+ /*
+ * Attributes can carry several values, like #ELEM(W ANA != 'N V'),
+ * denoting a word whose POS is neither N nor V.
+ * When seeing this, create a sub-termGroup and put it into the top-level
+ * term group, but only if there are other attributes in that group. If
+ * not, put the several values as distinct attr-val-pairs into the
+ * top-level group (in order to avoid a top-level group that only
+ * contains a sub-group).
+ */
LinkedHashMap<String, Object> termGroup = makeTermGroup("and");
ArrayList<Object> termGroupOperands = (ArrayList<Object>) termGroup.get("operands");
for (int i=elname; i<node.getChildCount(); i++) {
@@ -326,21 +335,34 @@
String layer = attrNode.getChild(0).toStringTree();
term.put("layer", translateMorph(layer));
term.put("key", attrNode.getChild(1).toStringTree());
- term.put("match", "match:eq");
+ String match = getNodeCat(attrNode).equals("EQ") ? "eq" : "ne";
+ term.put("match", "match:"+match);
} else {
- for (int j=1; j<attrNode.getChildCount(); j++) {
+ LinkedHashMap<String, Object> subTermGroup = makeTermGroup("and");
+ ArrayList<Object> subTermGroupOperands = (ArrayList<Object>) subTermGroup.get("operands");
+ int j;
+ for (j=1; j<attrNode.getChildCount(); j++) {
LinkedHashMap<String, Object> term = makeTerm();
- termGroupOperands.add(term);
String layer = attrNode.getChild(0).toStringTree();
term.put("layer", translateMorph(layer));
term.put("key", attrNode.getChild(j).toStringTree());
- term.put("match", "match:eq");
+ String match = getNodeCat(attrNode).equals("EQ") ? "eq" : "ne";
+ term.put("match", "match:"+match);
+ if (node.getChildCount()==elname+1) {
+ termGroupOperands.add(term);
+ System.err.println("taga");
+ } else {
+ subTermGroupOperands.add(term);
+ System.err.println(layer);
+ }
+ }
+ if (node.getChildCount()>elname+1) {
+ System.err.println(termGroupOperands);
+ termGroupOperands.add(subTermGroup);
+ System.err.println(termGroupOperands);
}
}
-
-
if (getNodeCat(attrNode).equals("NOTEQ")) negate=true;
-
}
elem.put("attr", termGroup);
}
@@ -892,7 +914,8 @@
"sagt der:sa Bundeskanzler",
// "Der:sa,-pe,+te ",
"#ELEM(W POS!='N V' title=tada)",
- "#ELEM(W ANA != 'N V')"
+ "#ELEM(W ANA != 'N V')",
+ "#ELEM(W ANA != 'N V' Genre = Sport)"
// "(&Baum #IN #ELEM(NP)) #IN(L) #ELEM(S)"
};
// CosmasTree.debug=true;
diff --git a/src/test/java/CosmasTreeTest.java b/src/test/java/CosmasTreeTest.java
index 777b75a..e8d8d3b 100644
--- a/src/test/java/CosmasTreeTest.java
+++ b/src/test/java/CosmasTreeTest.java
@@ -480,28 +480,47 @@
String elem3 =
"{@type=korap:span, key=w, attr=" +
"{@type=korap:termGroup, relation=relation:and, operands=[" +
- "{@type=korap:term, layer=pos, key=N, match=match:eq}," +
- "{@type=korap:term, layer=pos, key=V, match=match:eq}" +
+ "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
+ "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
"]}" +
"}";
ct = new CosmasTree(query);
map = ct.getRequestMap().get("query").toString();
assertEquals(elem3.replaceAll(" ", ""), map.replaceAll(" ", ""));
- query="#ELEM(W ANA != 'N V' Genre = Sport)";
+ query="#ELEM(W ANA != 'N A V' Genre = Sport)";
String elem4 =
"{@type=korap:span, key=w, attr=" +
"{@type=korap:termGroup, relation=relation:and, operands=[" +
"{@type=korap:termGroup, relation=relation:and, operands=[" +
- "{@type=korap:term, layer=pos, key=N, match=match:eq}," +
- "{@type=korap:term, layer=pos, key=V, match=match:eq}" +
- "]}" +
+ "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
+ "{@type=korap:term, layer=pos, key=A, match=match:ne}," +
+ "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
+ "]}," +
"{@type=korap:term, layer=Genre, key=Sport, match=match:eq}" +
"]}" +
"}";
ct = new CosmasTree(query);
map = ct.getRequestMap().get("query").toString();
assertEquals(elem4.replaceAll(" ", ""), map.replaceAll(" ", ""));
+
+ query="#ELEM(W ANA != 'N V' Genre != 'Sport Politik')";
+ String elem5 =
+ "{@type=korap:span, key=w, attr=" +
+ "{@type=korap:termGroup, relation=relation:and, operands=[" +
+ "{@type=korap:termGroup, relation=relation:and, operands=[" +
+ "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
+ "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
+ "]}," +
+ "{@type=korap:termGroup, relation=relation:and, operands=[" +
+ "{@type=korap:term, layer=Genre, key=Sport, match=match:ne}," +
+ "{@type=korap:term, layer=Genre, key=Politik, match=match:ne}" +
+ "]}" +
+ "]}" +
+ "}";
+ ct = new CosmasTree(query);
+ map = ct.getRequestMap().get("query").toString();
+ assertEquals(elem5.replaceAll(" ", ""), map.replaceAll(" ", ""));
}
@Test