opnot and opprox
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 58a5611..89de56f 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
@@ -257,16 +257,36 @@
}
}
- // negate every token that's under OPNOT > ARG2
- if (nodeCat.equals("ARG2") && openNodeCats.get(1).equals("OPNOT")) {
- negate = true;
+// // negate every token that's under OPNOT > ARG2
+// if (nodeCat.equals("ARG2") && openNodeCats.get(1).equals("OPNOT")) {
+// negate = true;
+// }
+
+ if (nodeCat.equals("ARG1") || nodeCat.equals("ARG2")) {
+ if (node.getChildCount()>1) {
+ // Step I: create sequence
+ LinkedHashMap<String, Object> sequence = new LinkedHashMap<String, Object>();
+ sequence.put("@type", "korap:sequence");
+ sequence.put("operands", new ArrayList<Object>());
+ objectStack.push(sequence);
+ stackedObjects++;
+ // Step II: decide where to put sequence
+ if (objectStack.size()>1) {
+ ArrayList<Object> topObjectOperands = (ArrayList<Object>) objectStack.get(1).get("operands");
+ topObjectOperands.add(sequence);
+ } else {
+ requestMap.put("query", sequence);
+ }
+ }
}
- if (nodeCat.equals("OPOR") || nodeCat.equals("OPAND")) {
+ if (nodeCat.equals("OPOR") || nodeCat.equals("OPAND") || nodeCat.equals("OPNOT")) {
// Step I: create group
LinkedHashMap<String, Object> disjunction = new LinkedHashMap<String, Object>();
disjunction.put("@type", "korap:group");
- String relation = nodeCat.equals("OPOR") ? "or" : "and";
+ String relation = "or";
+ if (nodeCat.equals("OPAND")) relation = "and";
+ if (nodeCat.equals("OPNOT")) relation = "not";
disjunction.put("relation", relation);
disjunction.put("operands", new ArrayList<Object>());
objectStack.push(disjunction);
@@ -428,7 +448,8 @@
"Sonne nicht (Mond Stern)",
"Sonne /+w1:4 Mond",
// "wegen #IN(L) <s>"
- "#BEG(<s>) /5w,s0 #END(<s>)"
+ "#BEG(<s>) /5w,s0 #END(<s>)",
+
};
CosmasTree.debug=true;
for (String q : queries) {
diff --git a/src/test/java/CosmasTreeTest.java b/src/test/java/CosmasTreeTest.java
index e4d8c5a..9af11af 100644
--- a/src/test/java/CosmasTreeTest.java
+++ b/src/test/java/CosmasTreeTest.java
@@ -101,19 +101,35 @@
@Test
public void testOPIN() {
query="wegen #IN(L) <s>";
- String disj1 =
+ String opin1 =
"{@type=korap:group, relation=in, position=L, operands=[" +
"{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}," +
"{@type=korap:element, @value=s}" +
"]}";
ppt = new CosmasTree(query);
map = ppt.getRequestMap().get("query").toString();
- assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
}
@Test
public void testOPNOT() {
-
+ query="Sonne nicht Mond";
+ String opnot1 =
+ "{@type=korap:group, relation=not, operands=[" +
+ "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
+ "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
+ "]}";
+ ppt = new CosmasTree(query);
+ map = ppt.getRequestMap().get("query").toString();
+ assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ }
+
+ @Test
+ public void testBEG_END() {
+ // BEG and END operators
+ // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
+ // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
+ // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
}
}