Fixed treatment of 'AND' and 'and' in VC serialization
Change-Id: I7fa92b7ee3413858472c9a3da39108ef8bb38bff
diff --git a/Changes b/Changes
index 912ea72..51e3dbb 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.28 2018-01-08
+0.28 2018-01-10
- Added some enums for koral:operation (margaretha)
- Fixed node serialization of Annis QL containing lemma (margaretha)
- Added serialization for Annis keyword "lemma" (margaretha)
@@ -6,6 +6,7 @@
- Fixed Annis regex bug regarding slash after foundry (margaretha)
- Fixed use of regular expressions in corpus queries
(margaretha, diewald)
+ - Fixed treatment of 'AND' and 'and' in vc serialization (diewald)
0.27 2017-09-12
- Changed Cosmas2 wildcards serialization as regex (margaretha)
diff --git a/src/main/antlr/collection/CollectionQueryLexer.g4 b/src/main/antlr/collection/CollectionQueryLexer.g4
index 059ad82..190481a 100644
--- a/src/main/antlr/collection/CollectionQueryLexer.g4
+++ b/src/main/antlr/collection/CollectionQueryLexer.g4
@@ -31,8 +31,8 @@
LEQ : '<=';
GEQ : '>=';
EQ : '=';
-AND : '&' | 'AND' | 'and' | 'UND' | 'und' ;
-OR : '|' | 'OR' | 'or' | 'ODER' | 'oder' ;
+AND : '&' | 'AND' | 'and';
+OR : '|' | 'OR' | 'or';
NEG : '!';
QMARK : '?';
SLASH : '/';
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
index b87d4a0..9f449c9 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
@@ -97,8 +97,13 @@
*/
if (nodeCat.equals("relation")) {
- String operator = getNodeCat(node.getChild(1).getChild(0)).equals(
- "&") ? "and" : "or";
+ String operator = getNodeCat(node.getChild(1).getChild(0));
+ if (operator.equals("&") || operator.equals("and") || operator.equals("AND")) {
+ operator = "and";
+ }
+ else {
+ operator = "or";
+ };
Map<String, Object> relationGroup = KoralObjectGenerator
.makeDocGroup(operator);
putIntoSuperObject(relationGroup);
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java
index 08d2cda..5e407aa 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java
@@ -79,8 +79,6 @@
assertEquals("match:eq", res.at("/collection/wrap/match").asText());
}
- ;
-
@Test
public void testContains () throws JsonProcessingException, IOException {
@@ -607,17 +605,16 @@
@Test
public void testRegexInGroup () throws JsonProcessingException, IOException {
- collection = "corpusSigle = /HMP[0-9][0-9]/ and (textTypeArt=/.*Kommentar.*/ or textTypeArt=/.*Leitartikel.*/)";
+ collection = "corpusSigle = /HMP[0-9][0-9]/ AND (textTypeArt=/.*Kommentar.*/ or textTypeArt=/.*Leitartikel.*/)";
qs.setQuery(query, ql);
qs.setCollection(collection);
res = mapper.readTree(qs.toJSON());
- /*
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("pubDate", res.at("/collection/key").asText());
- assertEquals("2000-02", res.at("/collection/value").asText());
- assertEquals("type:date", res.at("/collection/type").asText());
- assertEquals("match:eq", res.at("/collection/match").asText());
- */
+ assertEquals("corpusSigle", res.at("/collection/operands/0/key").asText());
+ assertEquals("HMP[0-9][0-9]", res.at("/collection/operands/0/value").asText());
+ assertEquals("operation:or", res.at("/collection/operands/1/operation").asText());
+ assertEquals("textTypeArt", res.at("/collection/operands/1/operands/0/key").asText());
+ assertEquals(".*Kommentar.*", res.at("/collection/operands/1/operands/0/value").asText());
+ assertEquals("operation:and", res.at("/collection/operation").asText());
}
@Test