Bugfixes for negative segments, focus() and some logging issues
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
index 10b80ec..0f3fe12 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
@@ -151,12 +151,12 @@
assertEquals("SnippetHTML (0) 2", "<span class=\"context-left\"><span class=\"more\"></span>a</span><span class=\"match\">b<em class=\"class-0 level-0\">a</em></span><span class=\"context-right\"><span class=\"more\"></span></span>", kr.match(0).snippetHTML());
- // System.err.println(kr.toJSON());
-
sq = new SpanMatchModifyClassQuery(
- new SpanNextQuery(
- new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 1),
- new SpanClassQuery(new SpanTermQuery(new Term("base", "s:c")), (byte) 2)
+ new SpanClassQuery(
+ new SpanNextQuery(
+ new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 1),
+ new SpanClassQuery(new SpanTermQuery(new Term("base", "s:c")), (byte) 2)
+ ), (byte) 3
), (byte) 3
);
@@ -173,6 +173,17 @@
assertEquals("Document count", 1, ki.numberOf("base", "documents"));
assertEquals("Token count", 10, ki.numberOf("base", "t"));
+ // Don't match the expected class!
+ sq = new SpanMatchModifyClassQuery(
+ new SpanNextQuery(
+ new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 1),
+ new SpanClassQuery(new SpanTermQuery(new Term("base", "s:c")), (byte) 2)
+ ), (byte) 3
+ );
+
+ kr = ki.search(sq, (short) 10);
+
+ assertEquals("totalResults", 0, kr.totalResults());
sq = new SpanMatchModifyClassQuery(
new SpanNextQuery(
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
index 04cdb97..da0d5d7 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
@@ -18,12 +18,15 @@
private String defaultFoundry = "mate/";
- @Ignore
+ @Test
public void queryJSONBsp1 () {
SpanQueryWrapperInterface sqwi = jsonQuery(getClass().getResource("/queries/bsp1.jsonld").getFile());
+ // There is a repetition in here
// ([base=foo]|[base=bar])[base=foobar]
- assertEquals(sqwi.toQuery().toString(), "");
+ assertEquals(sqwi.toQuery().toString(),
+ "spanOr([tokens:base:foo, spanQuantifier(spanNext(tokens:base:foo, tokens:base:bar)[1:100])])");
+ assertTrue(sqwi.isOptional());
};
@Test
@@ -76,7 +79,7 @@
assertEquals(sqwi.toQuery().toString(), "tokens:"+defaultFoundry+"l:Katze");
};
- @Ignore
+ @Test
public void queryJSONBsp7 () {
SpanQueryWrapperInterface sqwi = jsonQuery(getClass().getResource("/queries/bsp7.jsonld").getFile());
@@ -85,14 +88,6 @@
assertTrue(sqwi.isNegative());
};
- @Ignore
- public void queryJSONBsp8 () {
- SpanQueryWrapperInterface sqwi = jsonQuery(getClass().getResource("/queries/bsp8.json").getFile());
-
- // [!base=Katze]
- assertEquals(sqwi.toQuery().toString(), "");
- };
-
@Test
public void queryJSONBsp9 () {
SpanQueryWrapperInterface sqwi = jsonQuery(getClass().getResource("/queries/bsp9.jsonld").getFile());
@@ -118,12 +113,18 @@
assertEquals(sqwi.toQuery().toString(), "spanNext(spanNext(tokens:"+defaultFoundry+"l:Katze, tokens:s:und), tokens:s:Hunde)");
};
- @Ignore
+ @Test
public void queryJSONBsp11 () {
SpanQueryWrapperInterface sqwi = jsonQuery(getClass().getResource("/queries/bsp11.jsonld").getFile());
- // [!(base=Katze&orth=Katzen)]
- assertEquals(sqwi.toQuery().toString(), "");
+ // [base!=Katze | orth!=Katzen]
+ /*
+ Imagine a([^b]|[^c])d
+ Matches abd and acd
+ Interpretation would be not(spanAnd(...))
+ */
+ assertEquals(sqwi.toQuery().toString(), "spanOr([tokens:mate/l:Katze, tokens:s:Katzen])");
+ assertTrue(sqwi.isNegative());
};
@Test
@@ -134,12 +135,11 @@
assertEquals(sqwi.toQuery().toString(), "spanContain(<tokens:np />, tokens:"+defaultFoundry+"l:Mann)");
};
- @Ignore
+ @Test
public void queryJSONBsp13 () {
SpanQueryWrapperInterface sqwi = jsonQuery(getClass().getResource("/queries/bsp13.jsonld").getFile());
- // startswith(<np>,[!pos=Det])
- assertEquals(sqwi.toQuery().toString(), "");
+ assertEquals(sqwi.toQuery().toString(), "spanStartsWith(<tokens:np />, tokens:mate/p:Det)");
};
@Test
diff --git a/src/test/resources/queries/bsp1.jsonld b/src/test/resources/queries/bsp1.jsonld
index 5361a5c..3cc2171 100644
--- a/src/test/resources/queries/bsp1.jsonld
+++ b/src/test/resources/queries/bsp1.jsonld
@@ -1,46 +1,46 @@
{
- "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
- "query": {
+ "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+ "query": {
+ "@type": "korap:group",
+ "operation": "operation:or",
+ "operands": [
+ {
+ "@type": "korap:token",
+ "wrap": {
+ "@type": "korap:term",
+ "layer": "base",
+ "key": "foo"
+ }
+ },
+ {
"@type": "korap:group",
- "operation": "operation:or",
+ "min" : 0,
+ "operation": "operation:repetition",
"operands": [
- {
+ {
+ "@type": "korap:group",
+ "operation" : "operation:sequence",
+ "operands": [
+ {
"@type": "korap:token",
"wrap": {
- "@type": "korap:term",
- "layer": "base",
- "key": "foo"
+ "@type": "korap:term",
+ "key": "foo",
+ "layer" : "base"
}
- },
- {
- "@type": "korap:group",
- "min" : 0,
- "operation": "operation:repetition",
- "operands": [
- {
- "@type": "korap:group",
- "operation" : "operation:sequence",
- "operands": [
- {
- "@type": "korap:token",
- "wrap": {
- "@type": "korap:term",
- "key": "foo",
- "layer" : "base"
- }
- },
- {
- "@type": "korap:token",
- "wrap": {
- "@type": "korap:term",
- "layer": "base",
- "key" : "bar"
- }
- }
- ]
- }
- ]
- }
+ },
+ {
+ "@type": "korap:token",
+ "wrap": {
+ "@type": "korap:term",
+ "layer": "base",
+ "key" : "bar"
+ }
+ }
+ ]
+ }
]
- }
+ }
+ ]
+ }
}
diff --git a/src/test/resources/queries/bsp13.jsonld b/src/test/resources/queries/bsp13.jsonld
index f67adef..bb177ee 100644
--- a/src/test/resources/queries/bsp13.jsonld
+++ b/src/test/resources/queries/bsp13.jsonld
@@ -115,7 +115,7 @@
"@type": "korap:term",
"layer": "pos",
"key" : "Det",
- "match" : "match:ne"
+ "match" : "match:ne"
}
}
]