Added tests for the subspanquerywrapper dealing with classes.
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/CandidateSpan.java b/src/main/java/de/ids_mannheim/korap/query/spans/CandidateSpan.java
index 7beedc0..914556b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/CandidateSpan.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/CandidateSpan.java
@@ -7,10 +7,9 @@
import org.apache.lucene.search.spans.Spans;
/**
- * A CandidateSpan works as an object storing the current state of the
- * corresponding Lucene {@link Spans}, which is an enumeration. CandidateSpan is
- * used for various purposes, such as for collecting spans which will be used in
- * a latter process or next matching.
+ * CandidateSpan stores the current state of a Lucene {@link Spans}, which is an
+ * enumeration. CandidateSpan is used for various purposes, such as for
+ * collecting spans which will be used in a latter process or next matching.
*
* @author margaretha
* */
diff --git a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanClassQueryWrapper.java b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanClassQueryWrapper.java
index fd1ed56..fa4323a 100644
--- a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanClassQueryWrapper.java
+++ b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanClassQueryWrapper.java
@@ -18,7 +18,7 @@
if (number != (byte) 0)
this.hasClass = true;
this.min = subquery.min;
- this.max=subquery.max;
+ this.max = subquery.max;
};
public SpanClassQueryWrapper (SpanQueryWrapper subquery, short number) {
@@ -50,7 +50,7 @@
};
public SpanQuery toQuery () throws QueryException {
- if (this.subquery.isNull())
+ if (this.subquery.isNull())
return (SpanQuery) null;
SpanQuery sq = (SpanQuery) this.subquery.toQuery();
diff --git a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSubspanQueryWrapper.java b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSubspanQueryWrapper.java
index f4b9f39..b137353 100644
--- a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSubspanQueryWrapper.java
+++ b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSubspanQueryWrapper.java
@@ -110,7 +110,9 @@
if (sq == null)
return null;
if (sq instanceof SpanTermQuery) {
- if ((startOffset == 0 || startOffset == -1) &&
+ if (subquery.isNegative()) return sq;
+ else if ((startOffset == 0 || startOffset == -1)
+ &&
(length == 1 || length == 0)) {
// if (DEBUG) log.warn("Not SpanSubspanQuery. " +
// "Creating only a SpanQuery for the subquery.");
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
index c537ac6..cdf5556 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
@@ -76,7 +76,8 @@
}
/**
- * Classnumber Cannot check the expansion offset correctness directly
+ * Classnumber
+ * Check the expansion offsets
* */
@Test
public void testCase2() {
@@ -167,7 +168,8 @@
}
/**
- * Left expansion with exclusion No expansion
+ * Left expansion with exclusion
+ * No expansion
* */
@Test
public void testCase4() throws IOException {
@@ -207,8 +209,8 @@
}
/**
- * Expansion over start and end documents start => cut to 0 TODO: end => to
- * be handled in rendering process
+ * Expansion over start and end documents start => cut to 0
+ * TODO: end => to be handled in rendering process
*
* @throws IOException
* */
@@ -380,7 +382,6 @@
while ((str = in.readLine()) != null) {
sb.append(str);
}
- ;
in.close();
} catch (IOException e) {
fail(e.getMessage());
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanSubspanQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanSubspanQueryJSON.java
index 444ec79..1732e63 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestSpanSubspanQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanSubspanQueryJSON.java
@@ -150,15 +150,13 @@
}
@Test
- public void testNegativeEmbeddedSequence() throws QueryException {
- // submatch(1,1:das [base != Baum])
+ public void testNegativeToken() throws QueryException {
+ // submatch(0,1:[base != Baum])
String filepath = getClass().getResource(
- "/queries/submatch/embedded-negative-seq.jsonld").getFile();
+ "/queries/submatch/negative-token.jsonld").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
- assertEquals(
- "subspan(spanExpansion(tokens:s:das, !tokens:l:Baum{1, 1}, right), 1, 1)",
- sq.toString());
+ assertEquals("tokens:l:Baum", sq.toString());
}
@Test
@@ -174,25 +172,52 @@
}
@Test
- public void testNegativeToken() throws QueryException {
- // submatch(0,1:[base != Baum])
+ public void testNegativeSequenceWithClass() throws QueryException {
+ // das {1:submatch(0,1:[base != Baum])}
String filepath = getClass().getResource(
- "/queries/submatch/negative-token.jsonld").getFile();
+ "/queries/submatch/negative-sequence-class.jsonld").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
- assertEquals("tokens:l:Baum", sq.toString());
+ assertEquals(
+ "spanExpansion(tokens:s:das, !{1: tokens:l:Baum}{1, 1}, right, class:1)",
+ sq.toString());
}
@Test
+ public void testNegativeEmbeddedSequence() throws QueryException {
+ // submatch(1,1:das [base != Baum])
+ String filepath = getClass().getResource(
+ "/queries/submatch/embedded-negative-seq.jsonld").getFile();
+ SpanQueryWrapper sqwi = getJSONQuery(filepath);
+ SpanQuery sq = sqwi.toQuery();
+ assertEquals(
+ "subspan(spanExpansion(tokens:s:das, !tokens:l:Baum{1, 1}, right), 1, 1)",
+ sq.toString());
+ }
+
+ @Test
+ public void testNegativeEmbeddedSequenceWithClass() throws QueryException {
+ // submatch(0,1:{1:[base != Baum] dass})
+ String filepath = getClass().getResource(
+ "/queries/submatch/embedded-negative-class-seq.jsonld")
+ .getFile();
+ SpanQueryWrapper sqwi = getJSONQuery(filepath);
+ SpanQuery sq = sqwi.toQuery();
+ assertEquals(
+ "subspan({1: spanExpansion(tokens:s:dass, !tokens:l:Baum{1, 1}, left)}, 0, 1)",
+ sq.toString());
+ }
+
+
+ @Test
public void testEmbeddedNegativeRepetition() throws QueryException {
// submatch(1,1:das [base != Baum]{1,3})
- // need a spanExpansionQueryWrapper to handle a null notquery and
- // a repetition of a negative query
String filepath = getClass().getResource(
"/queries/submatch/embedded-negative-repetition.jsonld")
.getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
+ // 1,1 expansion is enough
assertEquals(
"subspan(spanExpansion(tokens:s:das, !tokens:l:Baum{1, 3}, right), 1, 1)",
sq.toString());
@@ -200,7 +225,7 @@
@Test
public void testNegativeRepetition() throws QueryException {
- // das submatch(1,1:[base != Baum]{1,3})
+ // das submatch(1,2:[base != Baum]{1,3})
// need a spanExpansionQueryWrapper to handle a null notquery and
// a repetition of a negative query
String filepath = getClass().getResource(
@@ -209,10 +234,7 @@
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
assertEquals(
- "spanExpansion(tokens:s:das, !tokens:l:Baum{1, 1}, right)",
+ "spanExpansion(tokens:s:das, !tokens:l:Baum{2, 2}, right)",
sq.toString());
}
-
-
-
}
diff --git a/src/test/resources/queries/submatch/embedded-negative-class-seq.jsonld b/src/test/resources/queries/submatch/embedded-negative-class-seq.jsonld
new file mode 100644
index 0000000..62e48c7
--- /dev/null
+++ b/src/test/resources/queries/submatch/embedded-negative-class-seq.jsonld
@@ -0,0 +1,49 @@
+{
+ "@context": "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
+ "errors": [],
+ "warnings": [],
+ "messages": [[
+ 303,
+ "Deprecated 2014-10-07: 'class' only to be supported until 3 months from deprecation date. Classes are now defined using the 'classOut' attribute."
+ ]],
+ "collection": {},
+ "query": {
+ "@type": "korap:reference",
+ "operation": "operation:focus",
+ "operands": [{
+ "@type": "korap:group",
+ "operation": "operation:class",
+ "class": 1,
+ "classOut": 1,
+ "operands": [{
+ "@type": "korap:group",
+ "operation": "operation:sequence",
+ "operands": [
+ {
+ "@type": "korap:token",
+ "wrap": {
+ "@type": "korap:term",
+ "layer": "lemma",
+ "key": "Baum",
+ "match": "match:ne"
+ }
+ },
+ {
+ "@type": "korap:token",
+ "wrap": {
+ "@type": "korap:term",
+ "layer": "orth",
+ "key": "dass",
+ "match": "match:eq"
+ }
+ }
+ ]
+ }]
+ }],
+ "spanRef": [
+ 0,
+ 1
+ ]
+ },
+ "meta": {"highlight": [1]}
+}
diff --git a/src/test/resources/queries/submatch/negative-repetition.jsonld b/src/test/resources/queries/submatch/negative-repetition.jsonld
index 88cf217..d919167 100644
--- a/src/test/resources/queries/submatch/negative-repetition.jsonld
+++ b/src/test/resources/queries/submatch/negative-repetition.jsonld
@@ -40,7 +40,7 @@
}],
"spanRef": [
1,
- 1
+ 2
]
}
]
diff --git a/src/test/resources/queries/submatch/negative-sequence-class.jsonld b/src/test/resources/queries/submatch/negative-sequence-class.jsonld
new file mode 100644
index 0000000..63b6e56
--- /dev/null
+++ b/src/test/resources/queries/submatch/negative-sequence-class.jsonld
@@ -0,0 +1,49 @@
+{
+ "@context": "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
+ "errors": [],
+ "warnings": [],
+ "messages": [[
+ 303,
+ "Deprecated 2014-10-07: 'class' only to be supported until 3 months from deprecation date. Classes are now defined using the 'classOut' attribute."
+ ]],
+ "collection": {},
+ "query": {
+ "@type": "korap:group",
+ "operation": "operation:sequence",
+ "operands": [
+ {
+ "@type": "korap:token",
+ "wrap": {
+ "@type": "korap:term",
+ "layer": "orth",
+ "key": "das",
+ "match": "match:eq"
+ }
+ },
+ {
+ "@type": "korap:group",
+ "operation": "operation:class",
+ "class": 1,
+ "classOut": 1,
+ "operands": [{
+ "@type": "korap:reference",
+ "operation": "operation:focus",
+ "operands": [{
+ "@type": "korap:token",
+ "wrap": {
+ "@type": "korap:term",
+ "layer": "lemma",
+ "key": "Baum",
+ "match": "match:ne"
+ }
+ }],
+ "spanRef": [
+ 0,
+ 1
+ ]
+ }]
+ }
+ ]
+ },
+ "meta": {"highlight": [1]}
+}
\ No newline at end of file