First attempt to support class numbers from 1 to 255 - 1 is the new default class number
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestClassIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestClassIndex.java
index 8d0a05b..7368843 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestClassIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestClassIndex.java
@@ -97,18 +97,18 @@
assertEquals("totalResults", 3, kr.totalResults());
assertEquals("StartPos (0)", 1, kr.match(0).startPos);
assertEquals("EndPos (0)", 2, kr.match(0).endPos);
- assertEquals("snippetBrackets (0)", "a[{b}]cabcab ...", kr.match(0).snippetBrackets());
+ assertEquals("snippetBrackets (0)", "a[{1:b}]cabcab ...", kr.match(0).snippetBrackets());
assertEquals("snippetHTML (0)", "<span class=\"context-left\">a</span><span class=\"match\">" +
- "<em class=\"class-0 level-0\">b</em></span><span class=\"context-right\">cabcab<span " +
+ "<em class=\"class-1 level-0\">b</em></span><span class=\"context-right\">cabcab<span " +
"class=\"more\"></span></span>", kr.match(0).snippetHTML());
assertEquals("StartPos (1)", 4, kr.match(1).startPos);
assertEquals("EndPos (1)", 5, kr.match(1).endPos);
- assertEquals("snippetBrackets (1)", "abca[{b}]cabac", kr.match(1).snippetBrackets());
+ assertEquals("snippetBrackets (1)", "abca[{1:b}]cabac", kr.match(1).snippetBrackets());
assertEquals("StartPos (2)", 7, kr.match(2).startPos);
assertEquals("EndPos (2)", 8, kr.match(2).endPos);
- assertEquals("snippetBrackets (2)", "... bcabca[{b}]ac", kr.match(2).snippetBrackets());
+ assertEquals("snippetBrackets (2)", "... bcabca[{1:b}]ac", kr.match(2).snippetBrackets());
sq = new SpanNextQuery(
@@ -167,20 +167,20 @@
// System.err.println(kr.toJSON());
assertEquals("totalResults", 1, kr.totalResults());
- assertEquals("SnippetBrackets (0)", "abcabc[a{2:b{a}}]c", kr.match(0).snippetBrackets());
- assertEquals("SnippetHTML (0)", "<span class=\"context-left\">abcabc</span><span class=\"match\">a<em class=\"class-2 level-0\">b<em class=\"class-0 level-1\">a</em></em></span><span class=\"context-right\">c</span>", kr.match(0).snippetHTML());
+ assertEquals("SnippetBrackets (0)", "abcabc[a{2:b{1:a}}]c", kr.match(0).snippetBrackets());
+ assertEquals("SnippetHTML (0)", "<span class=\"context-left\">abcabc</span><span class=\"match\">a<em class=\"class-2 level-0\">b<em class=\"class-1 level-1\">a</em></em></span><span class=\"context-right\">c</span>", kr.match(0).snippetHTML());
// Offset tokens
kr = ki.search(sq, 0, (short) 10, true, (short) 2, true, (short) 2);
assertEquals("totalResults", 1, kr.totalResults());
- assertEquals("SnippetBrackets (0)", "... bc[a{2:b{a}}]c", kr.match(0).snippetBrackets());
- assertEquals("SnippetHTML (0)", "<span class=\"context-left\"><span class=\"more\"></span>bc</span><span class=\"match\">a<em class=\"class-2 level-0\">b<em class=\"class-0 level-1\">a</em></em></span><span class=\"context-right\">c</span>", kr.match(0).snippetHTML());
+ assertEquals("SnippetBrackets (0)", "... bc[a{2:b{1:a}}]c", kr.match(0).snippetBrackets());
+ assertEquals("SnippetHTML (0)", "<span class=\"context-left\"><span class=\"more\"></span>bc</span><span class=\"match\">a<em class=\"class-2 level-0\">b<em class=\"class-1 level-1\">a</em></em></span><span class=\"context-right\">c</span>", kr.match(0).snippetHTML());
// Offset Characters
kr = ki.search(sq, 0, (short) 10, false, (short) 2, false, (short) 2);
assertEquals("totalResults", 1, kr.totalResults());
- assertEquals("SnippetBrackets (0)", "... bc[a{2:b{a}}]c", kr.match(0).snippetBrackets());
- assertEquals("SnippetHTML (0)", "<span class=\"context-left\"><span class=\"more\"></span>bc</span><span class=\"match\">a<em class=\"class-2 level-0\">b<em class=\"class-0 level-1\">a</em></em></span><span class=\"context-right\">c</span>", kr.match(0).snippetHTML());
+ assertEquals("SnippetBrackets (0)", "... bc[a{2:b{1:a}}]c", kr.match(0).snippetBrackets());
+ assertEquals("SnippetHTML (0)", "<span class=\"context-left\"><span class=\"more\"></span>bc</span><span class=\"match\">a<em class=\"class-2 level-0\">b<em class=\"class-1 level-1\">a</em></em></span><span class=\"context-right\">c</span>", kr.match(0).snippetHTML());
// System.err.println(kr.toJSON());
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
index 347f4ee..3acc821 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
@@ -101,8 +101,8 @@
KorapMatch km = kr.match(0);
- assertEquals("SnippetBrackets (0)", "... bcabca[{2:b{a}}]c", km.snippetBrackets());
- assertEquals("ID (0)", "match-c1!d1-p7-9(2)7-8(0)8-8", km.getID());
+ assertEquals("SnippetBrackets (0)", "... bcabca[{2:b{1:a}}]c", km.snippetBrackets());
+ assertEquals("ID (0)", "match-c1!d1-p7-9(2)7-8(1)8-8", km.getID());
};
@Test
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 529b74a..fb8850d 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
@@ -71,9 +71,9 @@
assertEquals("totalResults", 1, kr.totalResults());
assertEquals("StartPos (0)", 7, kr.match(0).startPos);
assertEquals("EndPos (0)", 9, kr.match(0).endPos);
- assertEquals("SnippetBrackets (0)", "... bcabca[b{a}]c", kr.match(0).snippetBrackets());
+ assertEquals("SnippetBrackets (0)", "... bcabca[b{1:a}]c", kr.match(0).snippetBrackets());
- assertEquals("Test no 'more' context", "<span class=\"context-left\"><span class=\"more\"></span>bcabca</span><span class=\"match\">b<em class=\"class-0 level-0\">a</em></span><span class=\"context-right\">c</span>", kr.match(0).snippetHTML());
+ assertEquals("Test no 'more' context", "<span class=\"context-left\"><span class=\"more\"></span>bcabca</span><span class=\"match\">b<em class=\"class-1 level-0\">a</em></span><span class=\"context-right\">c</span>", kr.match(0).snippetHTML());
sq = new SpanMatchModifyClassQuery(
new SpanNextQuery(
new SpanTermQuery(new Term("base", "s:b")),
@@ -133,23 +133,23 @@
// System.err.println(kr.toJSON());
assertEquals("totalResults", 1, kr.totalResults());
- assertEquals("SnippetBrackets (0)", "... bcabca[b{a}]c", kr.match(0).snippetBrackets());
+ assertEquals("SnippetBrackets (0)", "... bcabca[b{1:a}]c", kr.match(0).snippetBrackets());
- assertEquals("SnippetHTML (0) 1", "<span class=\"context-left\"><span class=\"more\"></span>bcabca</span><span class=\"match\">b<em class=\"class-0 level-0\">a</em></span><span class=\"context-right\">c</span>", kr.match(0).snippetHTML());
+ assertEquals("SnippetHTML (0) 1", "<span class=\"context-left\"><span class=\"more\"></span>bcabca</span><span class=\"match\">b<em class=\"class-1 level-0\">a</em></span><span class=\"context-right\">c</span>", kr.match(0).snippetHTML());
// Offset tokens
kr = ki.search(sq, 0, (short) 10, true, (short) 2, true, (short) 2);
assertEquals("totalResults", 1, kr.totalResults());
- assertEquals("SnippetBrackets (0)", "... ca[b{a}]c", kr.match(0).snippetBrackets());
+ assertEquals("SnippetBrackets (0)", "... ca[b{1:a}]c", kr.match(0).snippetBrackets());
// Offset Characters
kr = ki.search(sq, 0, (short) 10, false, (short) 1, false, (short) 0);
assertEquals("totalResults", 1, kr.totalResults());
- assertEquals("SnippetBrackets (0)", "... a[b{a}] ...", kr.match(0).snippetBrackets());
+ assertEquals("SnippetBrackets (0)", "... a[b{1:a}] ...", kr.match(0).snippetBrackets());
- 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());
+ assertEquals("SnippetHTML (0) 2", "<span class=\"context-left\"><span class=\"more\"></span>a</span><span class=\"match\">b<em class=\"class-1 level-0\">a</em></span><span class=\"context-right\"><span class=\"more\"></span></span>", kr.match(0).snippetHTML());
sq = new SpanMatchModifyClassQuery(
new SpanClassQuery(
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKorapQuery.java b/src/test/java/de/ids_mannheim/korap/query/TestKorapQuery.java
index 2eaa1cd..c5fd542 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKorapQuery.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKorapQuery.java
@@ -113,21 +113,21 @@
public void KorapClassQuery2 () throws QueryException {
KorapQuery kq = new KorapQuery("field");
SpanQuery sq = kq._(kq.seg("base:test")).toQuery();
- assertEquals("{0: field:base:test}", sq.toString());
+ assertEquals("{1: field:base:test}", sq.toString());
};
@Test
public void KorapClassQuery3 () throws QueryException {
KorapQuery kq = new KorapQuery("field");
SpanQuery sq = kq.seq(kq.seg("tree"), kq.contains(kq.tag("s"), kq._(kq.tag("np"))), kq.re("hey.*")).toQuery();
- assertEquals("spanNext(spanNext(field:tree, spanContain(<field:s />, {0: <field:np />})), SpanMultiTermQueryWrapper(field:/hey.*/))", sq.toString());
+ assertEquals("spanNext(spanNext(field:tree, spanContain(<field:s />, {1: <field:np />})), SpanMultiTermQueryWrapper(field:/hey.*/))", sq.toString());
};
@Test
public void KorapShrinkQuery () throws QueryException {
KorapQuery kq = new KorapQuery("field");
SpanQuery sq = kq.shrink(kq.tag("np")).toQuery();
- assertEquals("shrink(0: <field:np />)", sq.toString());
+ assertEquals("shrink(1: <field:np />)", sq.toString());
};
@Test
@@ -148,7 +148,7 @@
public void KorapShrinkQuery3 () throws QueryException {
KorapQuery kq = new KorapQuery("field");
SpanQuery sq = kq.shrink(1, kq._(1, kq.seq(kq.tag("np"), kq._(kq.seg("test").without("no"))))).toQuery();
- assertEquals("shrink(1: {1: spanNext(<field:np />, {0: spanNot(field:test, field:no, 0, 0)})})", sq.toString());
+ assertEquals("shrink(1: {1: spanNext(<field:np />, {1: spanNot(field:test, field:no, 0, 0)})})", sq.toString());
};
@Test
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 c0ad9d9..41cac0f 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
@@ -52,7 +52,7 @@
SpanQueryWrapper sqwi = jsonQuery(getClass().getResource("/queries/bsp3.jsonld").getFile());
// shrink({[base=Mann]})
- assertEquals(sqwi.toQuery().toString(), "shrink(0: {0: tokens:mate/l:Mann})");
+ assertEquals(sqwi.toQuery().toString(), "shrink(1: {1: tokens:mate/l:Mann})");
};
@Test
@@ -60,7 +60,7 @@
SpanQueryWrapper sqwi = jsonQuery(getClass().getResource("/queries/bsp4.jsonld").getFile());
// shrink({[base=foo]}[orth=bar])
- assertEquals(sqwi.toQuery().toString(), "shrink(0: spanNext({0: tokens:mate/l:foo}, tokens:s:bar))");
+ assertEquals(sqwi.toQuery().toString(), "shrink(1: spanNext({1: tokens:mate/l:foo}, tokens:s:bar))");
};
@Test
@@ -194,7 +194,7 @@
SpanQueryWrapper sqwi = jsonQuery(getClass().getResource("/queries/bsp-class.jsonld").getFile());
// within(<np>,[base=Mann])
- assertEquals(sqwi.toQuery().toString(), "{0: spanNext(tokens:tt/p:ADJA, tokens:mate/p:NN)}");
+ assertEquals(sqwi.toQuery().toString(), "{1: spanNext(tokens:tt/p:ADJA, tokens:mate/p:NN)}");
};
@Test
@@ -277,6 +277,16 @@
assertEquals(sqwi.toQuery().toString(), "spanDistance(tokens:s:Tal, tokens:s:Wald, [(w[2:100], ordered, notExcluded)])");
};
+ @Test
+ public void queryJSONcosmasBoundaryBug () throws QueryException {
+ SpanQueryWrapper sqwi = jsonQuery(getClass().getResource("/queries/bugs/cosmas_boundary.jsonld").getFile());
+
+ // Namen /s1 Leben
+ assertEquals(sqwi.toQuery().toString(), "shrink(129: spanElementDistance({129: tokens:s:Namen}, {129: tokens:s:Leben}, [(base/s:s[0:1], notOrdered, notExcluded)]))");
+ };
+
+
+
public static String getString (String path) {
StringBuilder contentBuilder = new StringBuilder();
try {
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
index 4fd0c21..8180a23 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
@@ -3,6 +3,8 @@
import java.util.*;
import java.io.*;
+import static de.ids_mannheim.korap.TestSimple.*;
+
import de.ids_mannheim.korap.KorapSearch;
import de.ids_mannheim.korap.KorapCollection;
import de.ids_mannheim.korap.KorapQuery;
@@ -604,6 +606,42 @@
};
@Test
+ public void searchJSONcosmasBoundaryBug () throws IOException {
+ // Construct index
+ KorapIndex ki = new KorapIndex();
+ // Indexing test files
+ FieldDocument fd = ki.addDocFile(
+ 1,getClass().getResource("/bzk/D59-00089.json.gz").getFile(), true
+ );
+ ki.commit();
+
+ String json = getString(
+ getClass().getResource("/queries/bugs/cosmas_boundary.jsonld").getFile()
+ );
+
+ KorapQuery kq = new KorapQuery("tokens");
+
+ // Check with 129
+ KorapSearch ks = new KorapSearch(
+ kq.shrink(1,kq.contains(kq.tag("base/s:s"), kq._(1, kq.seg("s:Leben"))))
+ );
+
+ KorapResult kr = ks.run(ki);
+ System.err.println(kr.getMatch(0).getSnippetBrackets());
+
+ /*
+
+ ks = new KorapSearch(json);
+
+ kr = ks.run(ki);
+ System.err.println(kr.toJSON());
+ assertEquals(276, kr.getTotalResults());
+ assertEquals(0, kr.getStartIndex());
+ assertEquals(10, kr.getItemsPerPage());
+ */
+ };
+
+ @Test
public void searchJSONCollection () throws IOException {
// Construct index
@@ -622,7 +660,9 @@
};
ki.commit();
- String json = getString(getClass().getResource("/queries/metaquery8-nocollection.jsonld").getFile());
+ String json = getString(
+ getClass().getResource("/queries/metaquery8-nocollection.jsonld").getFile()
+ );
KorapSearch ks = new KorapSearch(json);
KorapResult kr = ks.run(ki);
@@ -910,8 +950,6 @@
assertEquals(11, map.size());
};
-
-
public static String getString (String path) {
StringBuilder contentBuilder = new StringBuilder();
try {
diff --git a/src/test/resources/queries/bsp3.jsonld b/src/test/resources/queries/bsp3.jsonld
index 1a40038..0e76838 100644
--- a/src/test/resources/queries/bsp3.jsonld
+++ b/src/test/resources/queries/bsp3.jsonld
@@ -103,12 +103,12 @@
"query": {
"@type": "korap:group",
"operation": "operation:submatch",
- "classRef": [0],
+ "classRef": [1],
"operands": [
{
"@type": "korap:group",
"operation" : "operation:class",
- "class": 0,
+ "class": 1,
"operands": [
{
"@type": "korap:token",
diff --git a/src/test/resources/queries/bsp4.jsonld b/src/test/resources/queries/bsp4.jsonld
index c5cc7db..3a0c3c4 100644
--- a/src/test/resources/queries/bsp4.jsonld
+++ b/src/test/resources/queries/bsp4.jsonld
@@ -103,7 +103,7 @@
"query": {
"@type": "korap:group",
"operation": "operation:submatch",
- "classRef": [0],
+ "classRef": [1],
"operands": [
{
"@type": "korap:group",
@@ -112,7 +112,7 @@
{
"@type": "korap:group",
"operation":"operation:class",
- "class": 0,
+ "class": 1,
"operands": [
{
"@type": "korap:token",
diff --git a/src/test/resources/queries/bugs/cosmas_boundary.jsonld b/src/test/resources/queries/bugs/cosmas_boundary.jsonld
new file mode 100644
index 0000000..fb0f5ff
--- /dev/null
+++ b/src/test/resources/queries/bugs/cosmas_boundary.jsonld
@@ -0,0 +1,69 @@
+{
+ "@context": "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+ "query":{
+ "@type" : "korap:reference",
+ "classRef" : [
+ 129
+ ],
+ "operands" : [
+ {
+ "@type" : "korap:group",
+ "distances" : [
+ {
+ "@type" : "cosmas:distance",
+ "boundary" : {
+ "@type" : "korap:boundary",
+ "max" : 1,
+ "min" : 0
+ },
+ "foundry" : "base",
+ "layer" : "s",
+ "key" : "s",
+
+ "max" : 1,
+ "min" : 0
+ }
+ ],
+ "inOrder" : false,
+ "operands" : [
+ {
+ "@type" : "korap:group",
+ "class" : 129,
+ "classOut" : 129,
+ "operands" : [
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "key" : "Namen",
+ "layer" : "orth",
+ "match" : "match:eq"
+ }
+ }
+ ],
+ "operation" : "operation:class"
+ },
+ {
+ "@type" : "korap:group",
+ "class" : 129,
+ "classOut" : 129,
+ "operands" : [
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "key" : "Leben",
+ "layer" : "orth",
+ "match" : "match:eq"
+ }
+ }
+ ],
+ "operation" : "operation:class"
+ }
+ ],
+ "operation" : "operation:sequence"
+ }
+ ],
+ "operation" : "operation:focus"
+ }
+}