Added support for group:disjunction in deserialization
Change-Id: Ib30ef0225a430e40920c02a42c0850add53dc37e
diff --git a/src/main/java/de/ids_mannheim/korap/KrillQuery.java b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
index 3bf8bcd..19377fd 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
@@ -395,37 +395,39 @@
// Branch on operation
switch (operation) {
- case "operation:junction":
- return this._operationJunctionFromJson(operands);
+ case "operation:junction":
+ return this._operationJunctionFromJson(operands);
- case "operation:position":
- return this._operationPositionFromJson(json, operands);
+ case "operation:position":
+ return this._operationPositionFromJson(json, operands);
- case "operation:sequence":
- return this._operationSequenceFromJson(json, operands);
+ case "operation:sequence":
+ return this._operationSequenceFromJson(json, operands);
- case "operation:class":
- return this._operationClassFromJson(json, operands);
+ case "operation:class":
+ return this._operationClassFromJson(json, operands);
- case "operation:repetition":
- return this._operationRepetitionFromJson(json, operands);
+ case "operation:repetition":
+ return this._operationRepetitionFromJson(json, operands);
- case "operation:relation":
- if (!json.has("relation")) {
- throw new QueryException(717, "Missing relation node");
- }
+ case "operation:relation":
+ if (!json.has("relation")) {
+ throw new QueryException(717, "Missing relation node");
+ }
- return _operationRelationFromJson(operands,
- json.get("relation"));
- /*throw new QueryException(765,
- "Relations are currently not supported");*/
+ return _operationRelationFromJson(operands,
+ json.get("relation"));
+ /*throw new QueryException(765,
+ "Relations are currently not supported");*/
- case "operation:or": // Deprecated in favor of operation:junction
- return this._operationJunctionFromJson(operands);
- /*
- case "operation:submatch": // Deprecated in favor of koral:reference
- return this._operationSubmatchFromJson(json, operands);
- */
+ case "operation:or": // Deprecated in favor of operation:junction
+ return this._operationJunctionFromJson(operands);
+ /*
+ case "operation:submatch": // Deprecated in favor of koral:reference
+ return this._operationSubmatchFromJson(json, operands);
+ */
+ case "operation:disjunction":
+ return this._operationJunctionFromJson(operands);
};
// Unknown
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 df00673..4ffbb78 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
@@ -32,6 +32,19 @@
assertTrue(sqwi.isOptional());
};
+ @Test
+ public void queryJSONBsp1Disjunction () throws QueryException {
+ SpanQueryWrapper sqwi = jsonQuery(getClass().getResource(
+ "/queries/bsp1c.jsonld").getFile());
+
+ // There is a repetition in here
+ // ([base=foo]|[base=bar])[base=foobar]
+ assertEquals(
+ sqwi.toQuery().toString(),
+ "spanOr([tokens:base:foo, spanRepetition(spanNext(tokens:base:foo, tokens:base:bar){1,100})])");
+ assertTrue(sqwi.isOptional());
+ };
+
@Test
public void queryJSONBsp1b () throws QueryException {
diff --git a/src/test/resources/queries/bsp1c.jsonld b/src/test/resources/queries/bsp1c.jsonld
new file mode 100644
index 0000000..7b0b48f
--- /dev/null
+++ b/src/test/resources/queries/bsp1c.jsonld
@@ -0,0 +1,46 @@
+{
+ "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+ "query": {
+ "@type": "koral:group",
+ "operation": "operation:disjunction",
+ "operands": [
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "layer": "base",
+ "key": "foo"
+ }
+ },
+ {
+ "@type": "koral:group",
+ "min" : 0,
+ "operation": "operation:repetition",
+ "operands": [
+ {
+ "@type": "koral:group",
+ "operation" : "operation:sequence",
+ "operands": [
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "foo",
+ "layer" : "base"
+ }
+ },
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "layer": "base",
+ "key" : "bar"
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+}