"operation:or" -> "operation:disjunction"
negated tokens
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 880898a..6f95189 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
@@ -188,10 +188,10 @@
if (nodeCat.equals("n_ary_linguistic_term")) {
processN_ary_linguistic_term(node);
}
-
- if (nodeCat.equals("variableExpr")) {
- processVariableExpr(node);
- }
+//
+// if (nodeCat.equals("variableExpr")) {
+// processVariableExpr(node);
+// }
objectsToPop.push(stackedObjects);
@@ -299,7 +299,7 @@
private void processExprTop(ParseTree node) {
List<ParseTree> andTopExprs = getChildrenWithCat(node, "andTopExpr");
if (andTopExprs.size() > 1) {
- LinkedHashMap<String, Object> topOr = KoralObjectGenerator.makeGroup("or");
+ LinkedHashMap<String, Object> topOr = KoralObjectGenerator.makeGroup("disjunction");
requestMap.put("query", topOr);
objectStack.push(topOr);
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
index 5f4dfe8..c5ea126 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
@@ -656,10 +656,8 @@
private void processOPOR(Tree node) {
// Step I: create group
- LinkedHashMap<String, Object> disjunction = new LinkedHashMap<String, Object>();
- disjunction.put("@type", "korap:group");
- disjunction.put("operation", "operation:or");
- disjunction.put("operands", new ArrayList<Object>());
+ LinkedHashMap<String, Object> disjunction =
+ KoralObjectGenerator.makeGroup("disjunction");
objectStack.push(disjunction);
stackedObjects++;
// Step II: decide where to put
@@ -669,15 +667,10 @@
private void processOPAND_OPNOT(Tree node) {
// Step I: create group
String nodeCat = getNodeCat(node);
- LinkedHashMap<String, Object> distgroup = new LinkedHashMap<String, Object>();
- distgroup.put("@type", "korap:group");
- distgroup.put("operation", "operation:sequence");
+ LinkedHashMap<String, Object> distgroup = KoralObjectGenerator.makeGroup("sequence");
ArrayList<Object> distances = new ArrayList<Object>();
- LinkedHashMap<String, Object> zerodistance = new LinkedHashMap<String, Object>();
- zerodistance.put("@type", "cosmas:distance");
- zerodistance.put("key", "t");
- zerodistance.put("min", 0);
- zerodistance.put("max", 0);
+ LinkedHashMap<String, Object> zerodistance = KoralObjectGenerator.makeDistance("t", 0, 0);
+ zerodistance.put("@type", "cosmas:distance"); // overwrite @type: cosmas:distance!
if (nodeCat.equals("OPNOT"))
zerodistance.put("exclude", true);
distances.add(zerodistance);
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
index b07d0f9..5067a3c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
@@ -275,10 +275,15 @@
LinkedHashMap<String, Object> token = KoralObjectGenerator.makeToken();
// handle negation
List<ParseTree> negations = getChildrenWithCat(node, "!");
+ int termOrTermGroupChildId = 1;
boolean negated = false;
boolean isRegex = false;
- if (negations.size() % 2 == 1)
+ if (negations.size() % 2 == 1) {
negated = true;
+ termOrTermGroupChildId += negations.size();
+ }
+
+ System.err.println(negated);
if (getNodeCat(node.getChild(0)).equals("key")) {
// no 'term' child, but direct key specification: process here
LinkedHashMap<String, Object> term = KoralObjectGenerator.makeTerm();
@@ -314,12 +319,12 @@
else {
// child is 'term' or 'termGroup' -> process in extra method
LinkedHashMap<String, Object> termOrTermGroup =
- parseTermOrTermGroup(node.getChild(1), negated);
+ parseTermOrTermGroup(node.getChild(termOrTermGroupChildId),
+ negated);
token.put("wrap", termOrTermGroup);
}
putIntoSuperObject(token);
- visited.add(node.getChild(0));
- visited.add(node.getChild(2));
+ visited.addAll(getChildren(node));
}
@SuppressWarnings("unchecked")
@@ -393,7 +398,7 @@
private void processDisjunction(ParseTree node) {
LinkedHashMap<String, Object> disjunction =
- KoralObjectGenerator.makeGroup("or");
+ KoralObjectGenerator.makeGroup("disjunction");
putIntoSuperObject(disjunction);
objectStack.push(disjunction);
stackedObjects++;
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
index c6d1ebb..ea32134 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
@@ -13,7 +13,7 @@
import java.util.regex.Pattern;
/**
- * @author hanl
+ * @author Joachim Bingel (bingel@ids-mannheim.de), Michael Hanl (hanl@ids-mannheim.de)
* @date 10/12/2013
*/
public class QueryUtils {
@@ -255,11 +255,8 @@
.compile("\\.|\\^|\\$|\\||\\?|\\*|\\+|\\(|\\)|\\[|\\]|\\{|\\}");
Matcher m = p.matcher(key);
while (m.find()) {
- System.out.println(m.group(0));
String match = m.group();
- System.out.println(key);
key = m.replaceAll("\\\\" + match);
- System.out.println(" > " + key);
}
return key;
}
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessorTest.java
index 8a0ae98..d8b0196 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessorTest.java
@@ -956,6 +956,22 @@
assertEquals("korap:group", res.at("/query/operands/0/operands/0/@type").asText());
assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
}
+
+ @Test
+ public void testDisjunction() throws Exception {
+ query = "cat=\"NP\" | cat=\"VP\"";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:group", res.at("/query/@type").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation").asText());
+ assertEquals("korap: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("korap:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("VP", res.at("/query/operands/1/key").asText());
+ assertEquals("c", res.at("/query/operands/1/layer").asText());
+ }
+
//
// query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3";
// String cp2 =
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
index 82020db..faabc82 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
@@ -241,7 +241,7 @@
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
assertEquals("korap:group", res.at("/query/@type").asText());
- assertEquals("operation:or", res.at("/query/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation").asText());
assertEquals("Sonne", res.at("/query/operands/0/wrap/key").asText());
assertEquals("Mond", res.at("/query/operands/1/wrap/key").asText());
assertEquals(true, res.at("/query/operands/2").isMissingNode());
@@ -250,7 +250,7 @@
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
assertEquals("korap:group", res.at("/query/@type").asText());
- assertEquals("operation:or", res.at("/query/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation").asText());
assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
@@ -262,7 +262,7 @@
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
assertEquals("korap:group", res.at("/query/@type").asText());
- assertEquals("operation:or", res.at("/query/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation").asText());
assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
@@ -286,7 +286,7 @@
assertEquals(0, res.at("/query/distances/0/min").asInt());
assertEquals(0, res.at("/query/distances/0/max").asInt());
assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:or", res.at("/query/operands/0/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operands/0/operation").asText());
assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
assertEquals("Mond", res.at("/query/operands/0/operands/1/wrap/key").asText());
assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
@@ -304,7 +304,7 @@
assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
assertEquals("scheint", res.at("/query/operands/0/wrap/key").asText());
assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
assertEquals("Sonne", res.at("/query/operands/1/operands/0/wrap/key").asText());
assertEquals("Mond", res.at("/query/operands/1/operands/1/wrap/key").asText());
@@ -327,7 +327,7 @@
assertEquals(0, res.at("/query/operands/1/distances/0/max").asInt());
assertEquals("scheint", res.at("/query/operands/1/operands/0/wrap/key").asText());
assertEquals("korap:group", res.at("/query/operands/1/operands/1/@type").asText());
- assertEquals("operation:or", res.at("/query/operands/1/operands/1/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operands/1/operands/1/operation").asText());
assertEquals("Sonne", res.at("/query/operands/1/operands/1/operands/0/wrap/key").asText());
assertEquals("Mond", res.at("/query/operands/1/operands/1/operands/1/wrap/key").asText());
}
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
index f9cdf16..04bd48c 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
@@ -82,6 +82,17 @@
}
@Test
+ public void testNegatedTokens() throws JsonProcessingException, IOException {
+ query = "![p!=NN]";
+ qs.setQuery(query, "poliqarpplus");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("korap:token", res.at("/query/@type").asText());
+ assertEquals("NN", res.at("/query/wrap/key").asText());
+ assertEquals("p", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ }
+
+ @Test
public void testValue() throws JsonProcessingException, IOException {
query = "[mate/m=temp:pres]";
qs.setQuery(query, "poliqarpplus");
@@ -816,7 +827,7 @@
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
assertEquals("korap:group", res.at("/query/@type").asText());
- assertEquals("operation:or", res.at("/query/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation").asText());
assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
@@ -831,20 +842,20 @@
assertEquals("operation:sequence", res.at("/query/operation").asText());
assertEquals("Schild", res.at("/query/operands/1/wrap/key").asText());
assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:or", res.at("/query/operands/0/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operands/0/operation").asText());
query = "[base=Schild]([base=der]|[base=das])";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
assertEquals("Schild", res.at("/query/operands/0/wrap/key").asText());
assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
query = "([orth=der][base=katze])|([orth=eine][base=baum])";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
assertEquals("korap:group", res.at("/query/@type").asText());
- assertEquals("operation:or", res.at("/query/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation").asText());
assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
assertEquals("korap:token", res.at("/query/operands/0/operands/0/@type").asText());
@@ -857,7 +868,7 @@
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
assertEquals("korap:group", res.at("/query/@type").asText());
- assertEquals("operation:or", res.at("/query/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation").asText());
assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
assertEquals("korap:token", res.at("/query/operands/0/operands/0/@type").asText());
@@ -872,7 +883,7 @@
assertEquals("korap:group", res.at("/query/@type").asText());
assertEquals("operation:sequence", res.at("/query/operation").asText());
assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
assertEquals("korap:token", res.at("/query/operands/2/@type").asText());
assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
@@ -892,7 +903,7 @@
assertEquals("korap:group", res.at("/query/@type").asText());
assertEquals("operation:sequence", res.at("/query/operation").asText());
assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
assertEquals("korap:token", res.at("/query/operands/1/operands/0/@type").asText());
assertEquals("korap:token", res.at("/query/operands/1/operands/1/@type").asText());
@@ -1243,7 +1254,7 @@
query = "([base=a]^[base=b])|[base=c]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:or", res.at("/query/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation").asText());
assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
assertEquals("a", res.at("/query/operands/0/operands/0/wrap/key").asText());
@@ -1307,7 +1318,7 @@
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
assertEquals("große", res.at("/query/operands/1/operands/0/wrap/key").asText());
assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key").asText());
assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
@@ -1315,7 +1326,7 @@
query = "der große Baum | der kleine Baum";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:or", res.at("/query/operation").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation").asText());
assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
assertEquals("große", res.at("/query/operands/0/operands/1/wrap/key").asText());
assertEquals("Baum", res.at("/query/operands/0/operands/2/wrap/key").asText());