serialising dates as "@type":"xsd:string" and "type":"type:date"
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java
index 5742b1e..c598ba2 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java
@@ -96,6 +96,7 @@
term.putAll(parseValue(valueNodes.get(0)));
String match = operatorNodes.get(0).getText();
term.put("match", "match:" + interpretMatch(match));
+ checkOperatorValueConformance(term);
putIntoSuperObject(term);
} else { // (valueNodes.size()==2)
LinkedHashMap<String, Object> termGroup = makeDocGroup("and");
@@ -107,6 +108,7 @@
String match1 = operatorNodes.get(0).getText();
term1.put("match", "match:" + invertInequation(interpretMatch(match1)));
termGroupOperands.add(term1);
+ checkOperatorValueConformance(term1);
LinkedHashMap<String, Object> term2 = makeDoc();
term2.put("key", field);
@@ -114,6 +116,7 @@
String match2 = operatorNodes.get(1).getText();
term2.put("match", "match:" + interpretMatch(match2));
termGroupOperands.add(term2);
+ checkOperatorValueConformance(term2);
putIntoSuperObject(termGroup);
}
@@ -196,17 +199,27 @@
}
- private LinkedHashMap<String, Object> parseValue(ParseTree valueNode) {
+ private void checkOperatorValueConformance(LinkedHashMap<String, Object> term) {
+ String match = (String) term.get("match");
+ String type = (String) term.get("type");
+ if (type == null || type.equals("type:regex")) {
+ if (!(match.equals("match:eq") || match.equals("match:ne"))) {
+ errorMsgs.add("You used an inequation operator with a string value.");
+ System.err.println("You used an inequation operator with a string value.");
+ }
+ }
+ }
+
+ private LinkedHashMap<String, Object> parseValue(ParseTree valueNode) {
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
if (getNodeCat(valueNode.getChild(0)).equals("regex")) {
String regex = valueNode.getChild(0).getChild(0).toStringTree(parser);
map.put("value", regex.substring(1, regex.length()-1));
map.put("type", "type:regex");
} else if (getNodeCat(valueNode.getChild(0)).equals("date")) {
- LinkedHashMap<String,String> valueMap = new LinkedHashMap<String,String>();
- valueMap.put("@type", "xsd:date");
- valueMap.put("@value", valueNode.getChild(0).getChild(0).toStringTree(parser));
- map.put("value", valueMap);
+ map.put("type", "type:date");
+ String value = valueNode.getChild(0).getChild(0).toStringTree(parser);
+ map.put("value", value);
} else {
map.put("value", valueNode.getChild(0).toStringTree(parser));
}
@@ -404,7 +417,7 @@
query = "(textClass=wissenschaft & textClass=politik) | textClass=ausland";
query = "1990<year<2010 & genre=Sport";
query = "1990<year<2010";
- query = "pubDate<2010-09";
+ query = "pubDate<Sport";
// query = "foo=b-ar";
CollectionQueryTree filter = new CollectionQueryTree();
// filter.verbose = true;
diff --git a/src/test/java/CollectionQueryTreeTest.java b/src/test/java/CollectionQueryTreeTest.java
index f71eabb..cf7c398 100644
--- a/src/test/java/CollectionQueryTreeTest.java
+++ b/src/test/java/CollectionQueryTreeTest.java
@@ -43,7 +43,7 @@
expected =
"{@type=korap:docGroup, operation=operation:and, operands=[" +
"{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," +
- "{@type=korap:doc, key=year, value={@type=xsd:date, @value=2014}, match=match:eq}" +
+ "{@type=korap:doc, key=year, type=type:date, value=2014, match=match:eq}" +
"]}";
cqt = new CollectionQueryTree();
cqt.process(query);
@@ -58,7 +58,7 @@
"{@type=korap:docGroup, operation=operation:and, operands=[" +
"{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," +
"{@type=korap:docGroup, operation=operation:and, operands=[" +
- "{@type=korap:doc, key=year, value={@type=xsd:date, @value=2014}, match=match:eq}," +
+ "{@type=korap:doc, key=year, type=type:date, value=2014, match=match:eq}," +
"{@type=korap:doc, key=corpusID, value=WPD, match=match:eq}" +
"]}" +
"]}";
@@ -75,7 +75,7 @@
expected =
"{@type=korap:docGroup, operation=operation:or, operands=[" +
"{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," +
- "{@type=korap:doc, key=year, value={@type=xsd:date, @value=2014}, match=match:eq}" +
+ "{@type=korap:doc, key=year, type=type:date, value=2014, match=match:eq}" +
"]}";
cqt = new CollectionQueryTree();
cqt.process(query);
@@ -90,7 +90,7 @@
"{@type=korap:docGroup, operation=operation:or, operands=[" +
"{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," +
"{@type=korap:docGroup, operation=operation:or, operands=[" +
- "{@type=korap:doc, key=year, value={@type=xsd:date, @value=2014}, match=match:eq}," +
+ "{@type=korap:doc, key=year, type=type:date, value=2014, match=match:eq}," +
"{@type=korap:doc, key=corpusID, value=WPD, match=match:eq}" +
"]}" +
"]}";
@@ -162,7 +162,7 @@
"{@type=korap:doc, key=corpusID, value=WPD, match=match:eq}," +
"{@type=korap:docGroup, operation=operation:and, operands=[" +
"{@type=korap:doc, key=author, value=White, match=match:eq}," +
- "{@type=korap:doc, key=year, value={@type=xsd:date, @value=2010}, match=match:eq}" +
+ "{@type=korap:doc, key=year, type=type:date, value=2010, match=match:eq}" +
"]}" +
"]}" +
"]}";
@@ -178,8 +178,8 @@
query = "1990<pubDate<2010";
expected =
"{@type=korap:docGroup, operation=operation:and, operands=[" +
- "{@type=korap:doc, key=pubDate, value={@type=xsd:date, @value=1990}, match=match:gt}," +
- "{@type=korap:doc, key=pubDate, value={@type=xsd:date, @value=2010}, match=match:lt}" +
+ "{@type=korap:doc, key=pubDate, type=type:date, value=1990, match=match:gt}," +
+ "{@type=korap:doc, key=pubDate, type=type:date, value=2010, match=match:lt}" +
"]}";
cqt = new CollectionQueryTree();
cqt.process(query);
@@ -188,7 +188,7 @@
query = "pubDate>=1990";
expected =
- "{@type=korap:doc, key=pubDate, value={@type=xsd:date, @value=1990}, match=match:geq}";
+ "{@type=korap:doc, key=pubDate, type=type:date, value=1990, match=match:geq}";
cqt = new CollectionQueryTree();
cqt.process(query);
map = cqt.getRequestMap().toString();
@@ -196,7 +196,7 @@
query = "pubDate>=1990-05";
expected =
- "{@type=korap:doc, key=pubDate, value={@type=xsd:date, @value=1990-05}, match=match:geq}";
+ "{@type=korap:doc, key=pubDate, type=type:date, value=1990-05, match=match:geq}";
cqt = new CollectionQueryTree();
cqt.process(query);
map = cqt.getRequestMap().toString();
@@ -204,7 +204,7 @@
query = "pubDate>=1990-05-01";
expected =
- "{@type=korap:doc, key=pubDate, value={@type=xsd:date, @value=1990-05-01}, match=match:geq}";
+ "{@type=korap:doc, key=pubDate, type=type:date, value=1990-05-01, match=match:geq}";
cqt = new CollectionQueryTree();
cqt.process(query);
map = cqt.getRequestMap().toString();