Deserialization of flags
Change-Id: I15cc5ff7b8f6c6b1935b26d3637e7ddee0650c75
diff --git a/Changes b/Changes
index 221a821..834683c 100644
--- a/Changes
+++ b/Changes
@@ -3,6 +3,7 @@
- [workaround] Reintroduced empty collection support,
as Koral still creates them (diewald)
- [bugfix] Escaped characters now supported in MutiTerm (diewald)
+ - [feature] Deserialization of flags (diewald)
0.51 2015-03-17
- This is a major version (prepared for the GitHub release)
diff --git a/src/main/java/de/ids_mannheim/korap/KrillQuery.java b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
index ef00667..e6ff9d0 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Iterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1028,9 +1029,22 @@
: false;
Boolean isCaseInsensitive = false;
+ // Legacy
if (json.has("caseInsensitive")
- && json.get("caseInsensitive").asBoolean())
+ && json.get("caseInsensitive").asBoolean()) {
isCaseInsensitive = true;
+ }
+
+ // Flags
+ else if (json.has("flags") && json.get("flags").isArray()) {
+ Iterator<JsonNode> flags = json.get("flags").elements();
+ while (flags.hasNext()) {
+ if (flags.next().asText().equals("flags:caseInsensitive")) {
+ isCaseInsensitive = true;
+ break;
+ };
+ };
+ };
StringBuilder value = new StringBuilder();
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
index a33e080..ae21667 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
@@ -450,6 +450,17 @@
"spanOverlap(<tokens:s />, spanNext(tokens:tt/p:CARD, SpanMultiTermQueryWrapper(tokens:/tt/p:N.*/)))");
};
+ @Test
+ public void queryJSONflags1 () throws QueryException {
+ // buchstabe/i
+ SpanQueryWrapper sqwi = jsonQuery(getClass().getResource(
+ "/queries/flags/caseInsensitive.jsonld").getFile());
+
+ assertEquals(
+ sqwi.toQuery().toString(),
+ "tokens:i:buchstabe");
+ };
+
public static String getString (String path) {
StringBuilder contentBuilder = new StringBuilder();
diff --git a/src/test/resources/queries/flags/caseInsensitive.jsonld b/src/test/resources/queries/flags/caseInsensitive.jsonld
new file mode 100644
index 0000000..7320f52
--- /dev/null
+++ b/src/test/resources/queries/flags/caseInsensitive.jsonld
@@ -0,0 +1,23 @@
+{
+ "@context":"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld",
+ "errors":[],
+ "warnings":[],
+ "messages":[],
+ "collection":{},
+ "query":{
+ "@type":"koral:token",
+ "wrap":{
+ "@type":"koral:term",
+ "layer":"orth",
+ "key":"buchstabe",
+ "match":"match:eq",
+ "flags":["flags:caseInsensitive"]
+ }
+ },
+ "meta":{
+ "startPage":1,
+ "count":25,
+ "cutOff":true,
+ "context":"paragraph"
+ }
+}