disjunction operator precedence
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
index 6f7b25a..502702a 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
@@ -157,6 +157,7 @@
tree = parsePoliqarpQuery(query.replaceAll(" ", ""));
}
super.parser = this.parser;
+ log.info("Processing PoliqarpPlus");
System.out.println("Processing PoliqarpPlus");
requestMap.put("@context", "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld");
// prepareContext(requestMap);
@@ -215,7 +216,9 @@
// ignore this node if it only serves as an aligned sequence container
if (node.getChildCount() > 1) {
if (getNodeCat(node.getChild(1)).equals("cq_segments") && hasChild(node.getChild(1), "alignment")) {
-// if (getNodeCat(node.getChild(0)).equals("align")) {
+ ignoreCq_segment = true;
+ }
+ if (getNodeCat(node.getChild(0)).equals("(") && getNodeCat(node.getChild(node.getChildCount()-1)).equals(")")) {
ignoreCq_segment = true;
}
}
@@ -970,12 +973,14 @@
// Some things went wrong ...
catch (Exception e) {
+ log.error(e.getMessage());
System.err.println(e.getMessage());
}
- if (tree == null) throw new QueryException(
- "The query you specified could not be processed. Please make sure it is well-formed.");
-
+ if (tree == null) {
+ log.error("The query you specified could not be processed. Please make sure it is well-formed.");
+ throw new QueryException("The query you specified could not be processed. Please make sure it is well-formed.");
+ }
// Return the generated tree
return tree;
}
@@ -994,9 +999,12 @@
"contains(<cnx/c=np>, [mate/pos=NE])",
"matches(<A>,[pos=N]*)",
"[base=Auto]matches(<A>,[][pos=N]{4})",
- "[base=der][]*[base=Mann]"
+ "[base=der][]*[base=Mann]",
+ "[base=der] within s",
+ "([orth=der][base=katze])|([orth=eine][base=baum])",
+ "[orth=der][base=katze]|[orth=eine][base=baum]"
};
-// PoliqarpPlusTree.verbose=true;
+ PoliqarpPlusTree.verbose=true;
for (String q : queries) {
try {
System.out.println(q);
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpTree.java
index 1d23f9e..aba18bb 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpTree.java
@@ -18,6 +18,7 @@
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;
+import org.slf4j.LoggerFactory;
//import de.ids_mannheim.korap.query.poliqarp.PoliqarpLexer;
//import de.ids_mannheim.korap.query.poliqarp.PoliqarpParser;
@@ -31,7 +32,8 @@
*
*/
public class PoliqarpTree extends Antlr4AbstractSyntaxTree {
-
+ private static org.slf4j.Logger log = LoggerFactory
+ .getLogger(PoliqarpTree.class);
/**
* Top-level map representing the whole request.
*/
@@ -124,8 +126,10 @@
@Override
public void process(String query) {
ParseTree tree = parsePoliqarpQuery(query);
+ log.info("Processing Poliqarp query.");
System.out.println("Processing Poliqarp");
processNode(tree);
+ log.info(requestMap.toString());
}
@SuppressWarnings("unchecked")
@@ -421,7 +425,8 @@
// Some things went wrong ...
catch (Exception e) {
- System.err.println( e.getMessage() );
+ log.error(e.getMessage());
+ System.err.println( e.getMessage() );
}
// Return the generated tree
diff --git a/src/test/java/PoliqarpPlusTreeTest.java b/src/test/java/PoliqarpPlusTreeTest.java
index 2c6eeaf..4a45d78 100644
--- a/src/test/java/PoliqarpPlusTreeTest.java
+++ b/src/test/java/PoliqarpPlusTreeTest.java
@@ -425,6 +425,76 @@
ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
map = ppt.getRequestMap().get("query").toString();
assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+
+ // "([orth=der][base=katze])|([orth=eine][base=baum])"
+ String disj3 =
+ "{@type=korap:group, operation=operation:or, operands=[" +
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
+ "]}," +
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=eine, layer=orth, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
+ "]}" +
+ "]}";
+ ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
+ map = ppt.getRequestMap().get("query").toString();
+ assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+
+ // "[orth=der][base=katze]|[orth=eine][base=baum]"
+ String disj4 =
+ "{@type=korap:group, operation=operation:or, operands=[" +
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
+ "]}," +
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=eine, layer=orth, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
+ "]}" +
+ "]}";
+ ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
+ map = ppt.getRequestMap().get("query").toString();
+ assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
+
+ PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
+ PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
+ assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
+
+ // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
+ String disj5 =
+ "{@type=korap:group, operation=operation:or, operands=[" +
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
+ "]}," +
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=hund, layer=lemma, match=match:eq}}" +
+ "]}," +
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
+ "]}" +
+ "]}";
+ ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
+ map = ppt.getRequestMap().get("query").toString();
+ assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
+
+ // [orth=der]([base=katze]|[base=hund]|[base=baum])
+ String disj6 =
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
+ "{@type=korap:group, operation=operation:or, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=hund, layer=lemma, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
+ "]}" +
+ "]}";
+ ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
+ map = ppt.getRequestMap().get("query").toString();
+ assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
}
@Test