Added tests for sequence queries with empty token.
Change-Id: I0b7cf243dd77f8ee20bac1e94eb85209dfaae351
diff --git a/Changes b/Changes
index 47f9b2f..4218b88 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.55.7 2016-10-14
+0.55.7 2016-10-28
- [bugfix] Throw error on optional operands in distance
queries (diewald)
- [performance] Remember solved problematic queries in the
@@ -10,6 +10,8 @@
a single extension, if possible (diewald)
- [bugfix] Fixed paths in test suite for supporting
spaces (margaretha)
+ - Added check for minimum repetition (margaretha)
+ - Added deserialization tests for query with empty token (margaretha)
0.55.6 2016-08-10
- [bugfix] distance with key "t" uses default foundry (diewald)
diff --git a/src/test/java/de/ids_mannheim/korap/query/BaseTest.java b/src/test/java/de/ids_mannheim/korap/query/BaseTest.java
new file mode 100644
index 0000000..f3473c1
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/query/BaseTest.java
@@ -0,0 +1,15 @@
+package de.ids_mannheim.korap.query;
+
+import static de.ids_mannheim.korap.TestSimple.getJSONQuery;
+
+import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
+
+public abstract class BaseTest {
+
+ protected String path;
+
+ // get query wrapper based on json file
+ public SpanQueryWrapper jsonQueryFile (String filename) {
+ return getJSONQuery(getClass().getResource(path + filename).getFile());
+ }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java
index 6501d77..56cc1dc 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java
@@ -1,6 +1,5 @@
package de.ids_mannheim.korap.query;
-import static de.ids_mannheim.korap.TestSimple.getJSONQuery;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -18,10 +17,11 @@
*/
@RunWith(JUnit4.class)
-public class TestSpanSequenceQueryJSON {
-
- static String path = "/queries/sequence/";
-
+public class TestSpanSequenceQueryJSON extends BaseTest{
+
+ public TestSpanSequenceQueryJSON () {
+ path = "/queries/sequence/";
+ }
// Test Extensions
@@ -379,11 +379,4 @@
sqwi.toQuery().toString());
// Could also be a distance at the end ... that's a query planner thing.
};
-
-
-
- // get query wrapper based on json file
- public SpanQueryWrapper jsonQueryFile (String filename) {
- return getJSONQuery(getClass().getResource(path + filename).getFile());
- };
};
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryWithEmptyToken.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryWithEmptyToken.java
new file mode 100644
index 0000000..ddfe001
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryWithEmptyToken.java
@@ -0,0 +1,73 @@
+package de.ids_mannheim.korap.query;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
+import de.ids_mannheim.korap.util.QueryException;
+
+
+/**
+ * @author margaretha
+ *
+ */
+public class TestSpanSequenceQueryWithEmptyToken extends BaseTest {
+ public TestSpanSequenceQueryWithEmptyToken () {
+ path = "/queries/sequence/";
+ }
+
+
+ @Test
+ public void testEmptyInSequence () throws QueryException {
+ // der [] Mann?
+ SpanQueryWrapper sqwi = jsonQueryFile("empty-token-in-sequence.jsonld");
+
+ assertEquals("focus(254: spanContain(<tokens:base/s:t />, {254: spanOr("
+ + "[spanExpansion(tokens:l:der, []{1, 1}, right), "
+ + "spanNext(spanExpansion(tokens:l:der, []{1, 1}, right), "
+ + "tokens:l:Mann)])}))", sqwi.toQuery().toString());
+ }
+
+
+ @Test
+ public void testEmptyInSequence2 () throws QueryException {
+ // der [][] Mann?
+ SpanQueryWrapper sqwi = jsonQueryFile(
+ "empty-token-in-sequence2.jsonld");
+
+ assertEquals("focus(254: spanContain(<tokens:base/s:t />, {254: spanOr("
+ + "[spanExpansion(tokens:l:der, []{2, 2}, right), "
+ + "spanNext(spanExpansion(tokens:l:der, []{2, 2}, right), "
+ + "tokens:l:Mann)])}))", sqwi.toQuery().toString());
+ }
+
+
+ @Test
+ public void testEmptyInSequence3 () throws QueryException {
+ // [base=der][]{2,5}[base=Mann]?[]?[][base=Frau]
+ SpanQueryWrapper sqwi = jsonQueryFile(
+ "empty-token-in-sequence3.jsonld");
+
+ assertEquals(
+ "spanNext(" + "spanOr("
+ + "[spanExpansion(tokens:l:der, []{2, 5}, right), "
+ + "spanNext(spanExpansion(tokens:l:der, []{2, 5}, right), "
+ + "tokens:l:Mann)]), "
+ + "spanExpansion(tokens:l:Frau, []{1, 2}, left)" + ")",
+ sqwi.toQuery().toString());
+ }
+
+
+ @Test
+ public void testEmptyInSequence4 () throws QueryException {
+ // der? [] Mann?
+ SpanQueryWrapper sqwi = jsonQueryFile(
+ "empty-token-in-sequence4.jsonld");
+ assertEquals(
+ "spanOr([spanExpansion(tokens:l:der, []{1, 1}, right), "
+ + "spanExpansion(tokens:l:Mann, []{1, 1}, left), "
+ + "spanNext(spanExpansion(tokens:l:der, []{1, 1}, right), tokens:l:Mann)]])",
+ sqwi.toQuery().toString());
+ }
+}
diff --git a/src/test/resources/queries/sequence/empty-token-in-sequence.jsonld b/src/test/resources/queries/sequence/empty-token-in-sequence.jsonld
new file mode 100644
index 0000000..cc29f23
--- /dev/null
+++ b/src/test/resources/queries/sequence/empty-token-in-sequence.jsonld
@@ -0,0 +1,34 @@
+{
+ "@type": "koral:group",
+ "operation": "operation:sequence",
+ "operands": [
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "der",
+ "layer": "lemma",
+ "match": "match:eq"
+ }
+ },
+ {"@type": "koral:token"},
+ {
+ "@type": "koral:group",
+ "operation": "operation:repetition",
+ "operands": [{
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "Mann",
+ "layer": "lemma",
+ "match": "match:eq"
+ }
+ }],
+ "boundary": {
+ "@type": "koral:boundary",
+ "min": 0,
+ "max": 1
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/queries/sequence/empty-token-in-sequence2.jsonld b/src/test/resources/queries/sequence/empty-token-in-sequence2.jsonld
new file mode 100644
index 0000000..4944691
--- /dev/null
+++ b/src/test/resources/queries/sequence/empty-token-in-sequence2.jsonld
@@ -0,0 +1,45 @@
+{
+ "@type": "koral:group",
+ "operation": "operation:sequence",
+ "operands": [
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "der",
+ "layer": "lemma",
+ "match": "match:eq"
+ }
+ },
+ {
+ "@type": "koral:group",
+ "operation": "operation:repetition",
+ "operands": [{"@type": "koral:token"}],
+ "boundary": {
+ "@type": "koral:boundary",
+ "min": 2,
+ "max": 2
+ },
+ "min": 2,
+ "max": 2
+ },
+ {
+ "@type": "koral:group",
+ "operation": "operation:repetition",
+ "operands": [{
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "Mann",
+ "layer": "lemma",
+ "match": "match:eq"
+ }
+ }],
+ "boundary": {
+ "@type": "koral:boundary",
+ "min": 0,
+ "max": 1
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/queries/sequence/empty-token-in-sequence3.jsonld b/src/test/resources/queries/sequence/empty-token-in-sequence3.jsonld
new file mode 100644
index 0000000..2e9f1bf
--- /dev/null
+++ b/src/test/resources/queries/sequence/empty-token-in-sequence3.jsonld
@@ -0,0 +1,68 @@
+{
+ "@type": "koral:group",
+ "operation": "operation:sequence",
+ "operands": [
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "der",
+ "layer": "lemma",
+ "match": "match:eq"
+ }
+ },
+ {
+ "@type": "koral:group",
+ "operation": "operation:repetition",
+ "operands": [{"@type": "koral:token"}],
+ "boundary": {
+ "@type": "koral:boundary",
+ "min": 2,
+ "max": 5
+ },
+ "min": 2,
+ "max": 5
+ },
+ {
+ "@type": "koral:group",
+ "operation": "operation:repetition",
+ "operands": [{
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "Mann",
+ "layer": "lemma",
+ "match": "match:eq"
+ }
+ }],
+ "boundary": {
+ "@type": "koral:boundary",
+ "min": 0,
+ "max": 1
+ },
+ "min": 0,
+ "max": 1
+ },
+ {
+ "@type": "koral:group",
+ "operation": "operation:repetition",
+ "operands": [{"@type": "koral:token"}],
+ "boundary": {
+ "@type": "koral:boundary",
+ "min": 1,
+ "max": 2
+ },
+ "min": 1,
+ "max": 2
+ },
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "Frau",
+ "layer": "lemma",
+ "match": "match:eq"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/queries/sequence/empty-token-in-sequence4.jsonld b/src/test/resources/queries/sequence/empty-token-in-sequence4.jsonld
new file mode 100644
index 0000000..1a96e1b
--- /dev/null
+++ b/src/test/resources/queries/sequence/empty-token-in-sequence4.jsonld
@@ -0,0 +1,43 @@
+{
+ "@type": "koral:group",
+ "operation": "operation:sequence",
+ "operands": [
+ {
+ "@type": "koral:group",
+ "operation": "operation:repetition",
+ "operands": [{
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "der",
+ "layer": "lemma",
+ "match": "match:eq"
+ }
+ }],
+ "boundary": {
+ "@type": "koral:boundary",
+ "min": 0,
+ "max": 1
+ }
+ },
+ {"@type": "koral:token"},
+ {
+ "@type": "koral:group",
+ "operation": "operation:repetition",
+ "operands": [{
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "Mann",
+ "layer": "lemma",
+ "match": "match:eq"
+ }
+ }],
+ "boundary": {
+ "@type": "koral:boundary",
+ "min": 0,
+ "max": 1
+ }
+ }
+ ]
+}
\ No newline at end of file