Support #COND() operator alias in C2 (fixes #70)
Change-Id: I29ff9237448964195a818ac51a79646ee95f68ae
diff --git a/Changes b/Changes
index 2c1bb16..461b547 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
0.34 2019-07-17
- [bugfix] Ignore min:max order in distance operators
(#67; diewald)
+ - [feature] Support #COND() operator alias in C2 (#70; diewald)
0.33 2019-02-20
- Added debug flags (margaretha)
diff --git a/src/main/antlr/cosmas/c2ps.g b/src/main/antlr/cosmas/c2ps.g
index ed56030..c264ea6 100644
--- a/src/main/antlr/cosmas/c2ps.g
+++ b/src/main/antlr/cosmas/c2ps.g
@@ -246,7 +246,7 @@
// #BED(serchExpr, B).
// B muss nachträglich in einer lokalen Grammatik überprüft werden.
-opBED : '#BED(' searchExpr opBEDEnd -> ^(OPBED searchExpr ^(OPTS {$opBEDEnd.tree})) ;
+opBED : ( '#COND(' | '#BED(' ) searchExpr opBEDEnd -> ^(OPBED searchExpr ^(OPTS {$opBEDEnd.tree})) ;
// c2ps_opBED.check() returns an AST that is returned by rule opBEDEnd.
// for this action inside a rewrite rule, no ';' behind the function call.
@@ -258,4 +258,4 @@
opNHIT : ( '#NHIT(' | '#INKLUSIVE(' ) searchExpr ')' -> ^(OPNHIT searchExpr) ;
-opALL : ( '#ALL(' | '#EXKLUSIVE(' ) searchExpr ')' -> ^(OPALL searchExpr) ;
\ No newline at end of file
+opALL : ( '#ALL(' | '#EXKLUSIVE(' ) searchExpr ')' -> ^(OPALL searchExpr) ;
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
index da64bbe..d82596b 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
@@ -1227,6 +1227,34 @@
assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key")
.asText());
+ query = "#COND(der , sa)";
+ qs.setQuery(query, "cosmas2");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(129, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(129, res.at("/query/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals("koral:token",
+ res.at("/query/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("der",
+ res.at("/query/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+
+
query = "#BED(der Mann , +pe)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());