Mirror collection
Change-Id: Ib597547f09eaa1191b2c43f0d818d0f3002114c7
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java
index bb35479..41ce2dd 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java
@@ -4,6 +4,12 @@
import java.io.*;
import de.ids_mannheim.korap.KrillCollection;
+import de.ids_mannheim.korap.Krill;
+import de.ids_mannheim.korap.KrillIndex;
+import de.ids_mannheim.korap.response.Result;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.JsonNode;
import static de.ids_mannheim.korap.TestSimple.*;
@@ -72,6 +78,41 @@
};
+ @Test
+ public void collectionMirror () throws Exception {
+ // Construct index
+ KrillIndex ki = new KrillIndex();
+ // Indexing test files
+ for (String i : new String[] { "00001", "00002", "00003", "00004",
+ "00005", "00006", "02439" }) {
+ ki.addDoc(
+ getClass().getResourceAsStream("/wiki/" + i + ".json.gz"),
+ true);
+ };
+ ki.commit();
+
+ Krill krill = new Krill(_getJSONString("collection_6.jsonld"));
+ Result kr = krill.apply(ki);
+ assertEquals(kr.getTotalResults(), 86);
+
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res = mapper.readTree(kr.toJsonString());
+ assertTrue(res.at("/collection").isMissingNode());
+
+ krill = new Krill(_getJSONString("collection_6_withCollection.jsonld"));
+
+ kr = krill.apply(ki);
+ assertEquals(kr.getTotalResults(), 57);
+
+ res = mapper.readTree(kr.toJsonString());
+ assertFalse(res.at("/collection").isMissingNode());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("textClass", res.at("/collection/key").asText());
+ assertEquals("reisen", res.at("/collection/value").asText());
+ assertEquals("match:eq", res.at("/collection/match").asText());
+ };
+
+
private String _getJSONString (String file) {
return getString(getClass().getResource(path + file).getFile());
};
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestClassFilterIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestClassFilterIndex.java
index 77ef45d..5a2565e 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestClassFilterIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestClassFilterIndex.java
@@ -20,8 +20,9 @@
private KrillIndex ki;
private Result kr;
+
@Test
- public void testInclude() throws IOException {
+ public void testInclude () throws IOException {
ki = new KrillIndex();
ki.addDoc(TestReferenceIndex.createFieldDoc0());
ki.commit();
@@ -36,8 +37,7 @@
SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq,
ClassOperation.INCLUDE, 2, 1, true);
- assertEquals(
- sq.toString(),
+ assertEquals(sq.toString(),
"spanClassFilter(spanDistance({1: <tokens:np />}, {2: <tokens:vp />}, "
+ "[(w[0:1], notOrdered, notExcluded)]),INCLUDE,2,1)");
@@ -63,7 +63,8 @@
"Frankenstein, treat my daughter well. She [{2:is {1:the one that "
+ "saved your master who you hold so dear}}].", kr
.getMatch(2).getSnippetBrackets());
- assertEquals("Frankenstein, treat my daughter well. She [{2:is the one that "
+ assertEquals(
+ "Frankenstein, treat my daughter well. She [{2:is the one that "
+ "saved {1:your master} who you hold so dear}].", kr
.getMatch(3).getSnippetBrackets());
assertEquals(
@@ -72,8 +73,9 @@
}
+
@Test
- public void testDisjoint() throws IOException {
+ public void testDisjoint () throws IOException {
ki = new KrillIndex();
ki.addDoc(TestReferenceIndex.createFieldDoc0());
ki.commit();
@@ -94,7 +96,7 @@
SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq,
ClassOperation.DISJOINT, 2, 1, true);
-
+
kr = ki.search(sq, (short) 10);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
@@ -119,10 +121,11 @@
kr.getMatch(2).getSnippetBrackets());
}
+
// Problem with SpanDistanceQuery - unordered distance spans,
// -> unsorted
@Test
- public void testEqual() throws IOException {
+ public void testEqual () throws IOException {
ki = new KrillIndex();
ki.addDoc(TestReferenceIndex.createFieldDoc0());
ki.commit();
@@ -155,8 +158,9 @@
}
+
@Test
- public void testDiffer() throws IOException {
+ public void testDiffer () throws IOException {
ki = new KrillIndex();
ki.addDoc(TestReferenceIndex.createFieldDoc0());
ki.commit();
@@ -194,7 +198,7 @@
@Test
- public void testIntersect() throws IOException {
+ public void testIntersect () throws IOException {
ki = new KrillIndex();
ki.addDoc(TestReferenceIndex.createFieldDoc0());
ki.commit();
@@ -217,13 +221,14 @@
SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq3,
ClassOperation.INTERSECT, 1, 2, true);
- assertEquals("spanClassFilter(spanDistance({1: spanDistance(<tokens:np />, " +
- "{3: <tokens:vb />}, [(w[0:1], notOrdered, notExcluded)])}, " +
- "{2: spanDistance(<tokens:prp />, <tokens:vb />, [(w[0:1], " +
- "notOrdered, notExcluded)])}, [(w[0:1], notOrdered, notExcluded)]),INTERSECT,1,2)",
+ assertEquals(
+ "spanClassFilter(spanDistance({1: spanDistance(<tokens:np />, "
+ + "{3: <tokens:vb />}, [(w[0:1], notOrdered, notExcluded)])}, "
+ + "{2: spanDistance(<tokens:prp />, <tokens:vb />, [(w[0:1], "
+ + "notOrdered, notExcluded)])}, [(w[0:1], notOrdered, notExcluded)]),INTERSECT,1,2)",
sq.toString());
-
-
+
+
kr = ki.search(sq, (short) 20);
// for (Match km : kr.getMatches()) {
@@ -247,7 +252,7 @@
@Test
- public void testMultipleSameClasses() throws IOException {
+ public void testMultipleSameClasses () throws IOException {
ki = new KrillIndex();
ki.addDoc(TestReferenceIndex.createFieldDoc0());
@@ -269,10 +274,10 @@
SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq2,
ClassOperation.INCLUDE, 2, 1, true);
-
+
kr = ki.search(sdq2, (short) 20);
assertEquals(6, kr.getTotalResults());
-
+
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + " "
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestIndex.java
index be5fd8c..aac981e 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestIndex.java
@@ -75,6 +75,7 @@
private Directory index = new RAMDirectory();
+
@Test
public void multiTerm () throws CorpusDataException {
MultiTerm test = new MultiTerm("test");
@@ -110,6 +111,7 @@
assertTrue(test.toString().startsWith("xip/l:\\#normal#0-5$"));
};
+
@Test
public void multiTermToken () throws CorpusDataException {
MultiTermToken test = new MultiTermToken("hunde", "pos:n", "m:gen:pl");
@@ -123,6 +125,7 @@
assertEquals(test.terms.get(2).term, "m:gen:pl");
};
+
private List initIndexer () throws IOException {
List<Map<String, String>> list = new ArrayList<>();
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestReferenceIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestReferenceIndex.java
index 4a56a04..f718ce3 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestReferenceIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestReferenceIndex.java
@@ -28,6 +28,7 @@
private KrillIndex ki;
private Result kr;
+
@Test
public void testCase1 () throws IOException {
ki = new KrillIndex();
@@ -55,7 +56,8 @@
// SpanSegmentQuery ssq2 = new SpanSegmentQuery(sfq2, scq3,
// true);
- SpanRelationMatchQuery rq = new SpanRelationMatchQuery(srq, sfq1, scq3, true);
+ SpanRelationMatchQuery rq = new SpanRelationMatchQuery(srq, sfq1, scq3,
+ true);
// System.out.println(rq.toString());
SpanFocusQuery sfq3 = new SpanFocusQuery(rq, (byte) 1);
@@ -85,8 +87,9 @@
assertEquals(7, kr.getMatch(0).getEndPos());
}
+
@Test
- public void testCase2() throws IOException, QueryException {
+ public void testCase2 () throws IOException, QueryException {
String filepath = getClass().getResource(
"/queries/reference/distance-reference.jsonld").getFile();
@@ -97,13 +100,12 @@
// .{0,2} #3 & #3 -> #2
assertEquals(
- "spanReference(focus(#[1,2]spanSegment(focus(#2: "
- + "spanSegment(spanRelation(tokens:>:stanford/d:tag), "
- + "focus(3: spanDistance(focus(1: spanDistance({1: <tokens:vb />}, "
- + "{2: <tokens:prp />}, [(w[0:1], notOrdered, notExcluded)])), "
- + "{3: <tokens:nn />}, [(w[0:2], notOrdered, notExcluded)])))), "
- + "{2: <tokens:prp />})), 2)",
- sq.toString());
+ "spanReference(focus(#[1,2]spanSegment(focus(#2: "
+ + "spanSegment(spanRelation(tokens:>:stanford/d:tag), "
+ + "focus(3: spanDistance(focus(1: spanDistance({1: <tokens:vb />}, "
+ + "{2: <tokens:prp />}, [(w[0:1], notOrdered, notExcluded)])), "
+ + "{3: <tokens:nn />}, [(w[0:2], notOrdered, notExcluded)])))), "
+ + "{2: <tokens:prp />})), 2)", sq.toString());
SpanElementQuery seq1 = new SpanElementQuery("tokens", "vb");
// new SpanTermQuery(new Term("tokens", "c:vb"));
@@ -174,9 +176,10 @@
// }
}
+
// multiple references
@Test
- public void testCase3() throws IOException, QueryException {
+ public void testCase3 () throws IOException, QueryException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.commit();
@@ -209,17 +212,17 @@
assertEquals(13, kr.getMatch(1).getEndPos());
}
+
// multiple document
@Test
- public void testCase4() throws Exception {
+ public void testCase4 () throws Exception {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.commit();
String filepath = getClass().getResource(
- "/queries/reference/distance-reference.jsonld")
- .getFile();
+ "/queries/reference/distance-reference.jsonld").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
@@ -231,7 +234,8 @@
assertEquals(4, kr.getMatch(3).getEndPos());
}
- public static FieldDocument createFieldDoc1() {
+
+ public static FieldDocument createFieldDoc1 () {
FieldDocument fd = new FieldDocument();
fd.addString("ID", "doc-1");
fd.addTV(
@@ -256,69 +260,69 @@
return fd;
}
+
public static FieldDocument createFieldDoc0 () {
FieldDocument fd = new FieldDocument();
fd.addString("ID", "doc-0");
fd.addTV(
"tokens",
"Frankenstein, treat my daughter well. She is the one that saved your master who you hold so dear.",
-
+
"[(0-12)s:Frankenstein|_0#0-12|<>:nn#0-12$<i>1<s>18|<>:s#0-37$<i>5<s>1|"
+ "<>:np#0-13$<i>1<s>2|"
+ "<:stanford/d:tag$<i>1<s>1<s>18<s>19]"
- + "[(14-19)s:treat|_1#14-19|<>:vb#14-19$<i>2<s>19|<>:vp#14-36$<i>5<s>3|"
+ + "[(14-19)s:treat|_1#14-19|<>:vb#14-19$<i>2<s>19|<>:vp#14-36$<i>5<s>3|"
+ ">:stanford/d:tag$<i>0<s>2<s>19<s>18|"
+ ">:stanford/d:tag$<i>3<s>3<s>19<s>21|"
+ ">:stanford/d:tag$<i>4<s>4<s>19<s>22]"
- + "[(20-22)s:my|_2#20-22|<>:prp#20-22$<i>3<s>20|<>:np#20-31$<i>4<s>4]"
+ + "[(20-22)s:my|_2#20-22|<>:prp#20-22$<i>3<s>20|<>:np#20-31$<i>4<s>4]"
- + "[(23-31)s:daughter|_3#23-31|<>:nn#23-31$<i>4<s>21|"
+ + "[(23-31)s:daughter|_3#23-31|<>:nn#23-31$<i>4<s>21|"
+ ">:stanford/d:tag$<i>2<s>5<s>21<s>20]"
- + "[(32-36)s:well|_4#32-36|<>:rb#32-36$<i>5<s>22|<>:advp#32-36$<i>5<s>5]"
+ + "[(32-36)s:well|_4#32-36|<>:rb#32-36$<i>5<s>22|<>:advp#32-36$<i>5<s>5]"
- + "[(38-41)s:She|_5#38-41|<>:prp#38-41$<i>6<s>23|<>:np#38-41$<i>6<s>36|<>:s#38-97$<i>18<s>6]"
+ + "[(38-41)s:She|_5#38-41|<>:prp#38-41$<i>6<s>23|<>:np#38-41$<i>6<s>36|<>:s#38-97$<i>18<s>6]"
- + "[(42-44)s:is|_6#42-44|<>:vb#42-44$<i>7<s>24|<>:vp#42-96$<i>18<s>7]"
+ + "[(42-44)s:is|_6#42-44|<>:vb#42-44$<i>7<s>24|<>:vp#42-96$<i>18<s>7]"
- + "[(45-48)s:the|_7#45-48|<>:dt#45-48$<i>8<s>25|<>:np#45-52$<i>9<s>8|<>:np#45-96$<i>18<s>9]"
+ + "[(45-48)s:the|_7#45-48|<>:dt#45-48$<i>8<s>25|<>:np#45-52$<i>9<s>8|<>:np#45-96$<i>18<s>9]"
- + "[(49-52)s:one|_8#49-52|<>:nn#49-52$<i>9<s>26|"
+ + "[(49-52)s:one|_8#49-52|<>:nn#49-52$<i>9<s>26|"
+ ">:stanford/d:tag$<i>5<s>6<s>26<s>23|"
+ ">:stanford/d:tag$<i>6<s>7<s>26<s>24|"
+ ">:stanford/d:tag$<i>7<s>8<s>26<s>25|"
+ ">:stanford/d:tag$<i>10<s>9<s>26<s>28]"
-
- + "[(53-57)s:that|_9#53-57|<>:rp#53-57$<i>10<s>27|<>:sb#53-96$<i>18<s>10]"
-
- + "[(58-63)s:saved|_10#58-63|<>:vb#58-63$<i>11<s>28|<>:s#58-96$<i>18<s>11|"
+
+ + "[(53-57)s:that|_9#53-57|<>:rp#53-57$<i>10<s>27|<>:sb#53-96$<i>18<s>10]"
+
+ + "[(58-63)s:saved|_10#58-63|<>:vb#58-63$<i>11<s>28|<>:s#58-96$<i>18<s>11|"
+ "<>:vp#58-96$<i>18<s>12|"
+ ">:stanford/d:tag$<i>9<s>10<s>28<s>27|"
+ ">:stanford/d:tag$<i>12<s>11<s>28<s>30|"
+ ">:stanford/d:tag$<i>15<s>12<s>28<s>33]"
- + "[(64-68)s:your|_11#64-68|<>:prp#64-68$<i>12<s>29|<>:np#64-75$<i>13<s>13]"
+ + "[(64-68)s:your|_11#64-68|<>:prp#64-68$<i>12<s>29|<>:np#64-75$<i>13<s>13]"
- + "[(69-75)s:master|_12#69-75|<>:nn#69-75$<i>13<s>30|"
+ + "[(69-75)s:master|_12#69-75|<>:nn#69-75$<i>13<s>30|"
+ ">:stanford/d:tag$<i>11<s>13<s>30<s>29]"
- + "[(76-79)s:who|_13#76-79|<>:rp#76-79$<i>14<s>31|<>:sb#76-96$<i>18<s>14]"
+ + "[(76-79)s:who|_13#76-79|<>:rp#76-79$<i>14<s>31|<>:sb#76-96$<i>18<s>14]"
- + "[(80-83)s:you|_14#80-83|<>:prp#80-83$<i>15<s>32|<>:np#80-83$<i>15<s>37|<>:s#80-96$<i>18<s>15]"
+ + "[(80-83)s:you|_14#80-83|<>:prp#80-83$<i>15<s>32|<>:np#80-83$<i>15<s>37|<>:s#80-96$<i>18<s>15]"
- + "[(84-88)s:hold|_15#84-88|<>:vb#84-88$<i>16<s>33|<>:vp#84-96$<i>18<s>16|"
+ + "[(84-88)s:hold|_15#84-88|<>:vb#84-88$<i>16<s>33|<>:vp#84-96$<i>18<s>16|"
+ ">:stanford/d:tag$<i>13<s>14<s>33<s>31|"
+ ">:stanford/d:tag$<i>14<s>15<s>33<s>32|"
+ ">:stanford/d:tag$<i>17<s>16<s>33<s>35]"
- + "[(89-91)s:so|_16#89-91|<>:rb#89-91$<i>17<s>341|<>:adjp#89-96$<i>18<s>17]"
+ + "[(89-91)s:so|_16#89-91|<>:rb#89-91$<i>17<s>341|<>:adjp#89-96$<i>18<s>17]"
- + "[(92-96)s:dear|_17#92-96|<>:jj#92-96$<i>18<s>35|"
- + ">:stanford/d:tag$<i>16<s>17<s>35<s>34]"
- );
-
+ + "[(92-96)s:dear|_17#92-96|<>:jj#92-96$<i>18<s>35|"
+ + ">:stanford/d:tag$<i>16<s>17<s>35<s>34]");
+
return fd;
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
index 63d2a64..8618592 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
@@ -289,6 +289,7 @@
assertEquals(4, kr.getMatch(5).getEndPos());
}
+
/**
* Relations only with/out attribute
* */
@@ -307,9 +308,8 @@
// child-of with attr func=sbj
SpanWithAttributeQuery wq = new SpanWithAttributeQuery(fq,
- new SpanAttributeQuery(
- new SpanTermQuery(new Term("base", "r@:func=sbj")),
- true), true);
+ new SpanAttributeQuery(new SpanTermQuery(new Term("base",
+ "r@:func=sbj")), true), true);
kr = ki.search(wq, (short) 20);
assertEquals((long) 1, kr.getTotalResults());
@@ -385,11 +385,12 @@
assertEquals(7, kr.getMatch(6).getEndPos());
}
+
/**
* Dependency relations with attribute
* */
@Test
- public void testCase5() throws IOException {
+ public void testCase5 () throws IOException {
ki.addDoc(createFieldDoc2());
ki.commit();
@@ -430,6 +431,7 @@
}
+
/**
* Relation with specific sources, return any targets
* */
@@ -485,11 +487,11 @@
ki.commit();
//return source of dep relations to pos:NN
-
+
SpanTermWithIdQuery tq = new SpanTermWithIdQuery(new Term("base",
"pos:NN"), true);
- SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base",
- "<:dep")), true);
+ SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(
+ new Term("base", "<:dep")), true);
srq.setSourceClass((byte) 1);
SpanRelationMatchQuery rm = new SpanRelationMatchQuery(srq, tq, true);
SpanQuery rv = new SpanFocusQuery(rm, (byte) 1);
@@ -505,8 +507,7 @@
// return target of dep relations from pos:NN
srq = new SpanRelationQuery(
- new SpanTermQuery(
- new Term("base", ">:dep")), true);
+ new SpanTermQuery(new Term("base", ">:dep")), true);
srq.setTargetClass((byte) 1);
rm = new SpanRelationMatchQuery(srq, tq, true);
rv = new SpanFocusQuery(rm, (byte) 1);
@@ -525,7 +526,8 @@
/**
* Relation with specific sources and return any targets <br/>
- * Relation with specific sources and targets, return the targets <br/>
+ * Relation with specific sources and targets, return the targets
+ * <br/>
* Relation with specific sources and targets, return the sources
*
* @throws IOException
@@ -606,8 +608,9 @@
}
+
@Test
- public void testCase10() throws IOException {
+ public void testCase10 () throws IOException {
ki.addDoc(createFieldDoc2());
ki.commit();
SpanElementQuery seq1 = new SpanElementQuery("base", "np");
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 c0e1cf5..df00673 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
@@ -245,6 +245,7 @@
assertEquals(sqwi.toQuery().toString(), "tokens:base/p:foo");
};
+
@Test
public void queryJSONBspClass () throws QueryException {
SpanQueryWrapper sqwi = jsonQuery(getClass().getResource(
@@ -450,46 +451,40 @@
"spanOverlap(<tokens:s />, spanNext(tokens:tt/p:CARD, SpanMultiTermQueryWrapper(tokens:/tt/p:N.*/)))");
};
+
@Test
public void queryJSONflags1 () throws QueryException {
// buchstabe/i
SpanQueryWrapper sqwi = jsonQuery(getClass().getResource(
"/queries/flags/caseInsensitive.jsonld").getFile());
- assertEquals(
- sqwi.toQuery().toString(),
- "tokens:i:buchstabe");
+ assertEquals(sqwi.toQuery().toString(), "tokens:i:buchstabe");
};
+
@Test
public void queryJSONflags2 () throws QueryException {
// buchstabe/i
try {
- String json = getString(
- getClass().getResource(
- "/queries/flags/unknown1.jsonld"
- ).getFile()
- );
+ String json = getString(getClass().getResource(
+ "/queries/flags/unknown1.jsonld").getFile());
KrillQuery kq = new KrillQuery("tokens");
- assertEquals(kq.fromJson(json).toQuery().toString(),"tokens:s:buchstabe");
- assertEquals(kq.getWarning(0).getCode(), 748);
-
- json = getString(
- getClass().getResource(
- "/queries/flags/unknown2.jsonld"
- ).getFile()
- );
- kq = new KrillQuery("tokens");
- assertEquals(kq.fromJson(json).toQuery().toString(),"tokens:i:buchstabe");
+ assertEquals(kq.fromJson(json).toQuery().toString(),
+ "tokens:s:buchstabe");
assertEquals(kq.getWarning(0).getCode(), 748);
- json = getString(
- getClass().getResource(
- "/queries/flags/unknown3.jsonld"
- ).getFile()
- );
+ json = getString(getClass().getResource(
+ "/queries/flags/unknown2.jsonld").getFile());
kq = new KrillQuery("tokens");
- assertEquals(kq.fromJson(json).toQuery().toString(),"tokens:i:buchstabe");
+ assertEquals(kq.fromJson(json).toQuery().toString(),
+ "tokens:i:buchstabe");
+ assertEquals(kq.getWarning(0).getCode(), 748);
+
+ json = getString(getClass().getResource(
+ "/queries/flags/unknown3.jsonld").getFile());
+ kq = new KrillQuery("tokens");
+ assertEquals(kq.fromJson(json).toQuery().toString(),
+ "tokens:i:buchstabe");
assertEquals(kq.getWarning(0).getCode(), 748);
}
@@ -498,6 +493,7 @@
};
};
+
public static String getString (String path) {
StringBuilder contentBuilder = new StringBuilder();
try {
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanReferenceQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanReferenceQueryJSON.java
index 57c29bc..a401916 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestSpanReferenceQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanReferenceQueryJSON.java
@@ -14,7 +14,7 @@
public class TestSpanReferenceQueryJSON {
@Test
- public void testFirstOperandRef() throws IOException, QueryException {
+ public void testFirstOperandRef () throws IOException, QueryException {
String filepath = getClass().getResource(
"/queries/reference/first-operand-reference.jsonld").getFile();
@@ -30,8 +30,9 @@
sq.toString());
}
+
@Test
- public void testSecondOperandRef() throws QueryException {
+ public void testSecondOperandRef () throws QueryException {
String filepath = getClass().getResource(
"/queries/reference/second-operand-reference.jsonld").getFile();
@@ -47,8 +48,9 @@
+ "{3: tokens:p:P}), 3)", sq.toString());
}
+
@Test
- public void testMultipleReferences() throws QueryException {
+ public void testMultipleReferences () throws QueryException {
String filepath = getClass().getResource(
"/queries/reference/multiple-references.jsonld").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
@@ -60,55 +62,38 @@
"spanReference(focus(#[1,2]spanSegment(focus(#2: spanSegment(spanRelation(tokens:>:mate/d:HEAD), "
+ "focus(2: spanReference(spanNext(focus(1: spanNext(focus(2: spanNext({1: <tokens:c:VP />}, "
+ "{2: <tokens:c:NP />})), {3: <tokens:c:PP />})), {3: <tokens:c:PP />}), 3)))), "
- + "{1: <tokens:c:VP />})), 1)",
- sq.toString());
+ + "{1: <tokens:c:VP />})), 1)", sq.toString());
}
+
@Test
- public void testDistanceReferences() throws QueryException {
+ public void testDistanceReferences () throws QueryException {
String filepath = getClass().getResource(
- "/queries/reference/bug-multiple-distance-simple.jsonld"
- ).getFile();
+ "/queries/reference/bug-multiple-distance-simple.jsonld")
+ .getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
- assertEquals("spanDistance(<tokens:c:vb />, <tokens:c:prp />, [(w[1:1], notOrdered, notExcluded)])", sq.toString());
+ assertEquals(
+ "spanDistance(<tokens:c:vb />, <tokens:c:prp />, [(w[1:1], notOrdered, notExcluded)])",
+ sq.toString());
// "/queries/reference/distance-reference.jsonld").getFile();
filepath = getClass().getResource(
- "/queries/reference/bug-multiple-distance.jsonld"
- ).getFile();
+ "/queries/reference/bug-multiple-distance.jsonld").getFile();
sqwi = getJSONQuery(filepath);
sq = sqwi.toQuery();
// 'cat="VP" & cat="NP" & cat="PP" & #1 . #2 & #2 . #3 & #1 .
// #3 & #2 ->dep #1'
- assertEquals(
- "spanReference("+
- "focus("+
- "#[1,2]spanSegment("+
- "focus("+
- "#2: spanSegment("+
- "spanRelation(tokens:>:stanford/d:tag), " +
- "focus("+
- "2: spanDistance("+
- "focus("+
- "1: spanDistance("+
- "<tokens:c:vb />, "+
- "{1: <tokens:c:prp />}, " +
- "[(w[1:1], notOrdered, notExcluded)]"+
- ")"+
- "), "+
- "{2: <tokens:c:nn />}, "+
- "[(w[0:2], ordered, notExcluded)]"+
- ")"+
- ")"+
- ")"+
- "), " +
- "{1: <tokens:c:prp />}"+
- ")"+
- "), 1"+
- ")",
- sq.toString());
+ assertEquals("spanReference(" + "focus(" + "#[1,2]spanSegment("
+ + "focus(" + "#2: spanSegment("
+ + "spanRelation(tokens:>:stanford/d:tag), " + "focus("
+ + "2: spanDistance(" + "focus(" + "1: spanDistance("
+ + "<tokens:c:vb />, " + "{1: <tokens:c:prp />}, "
+ + "[(w[1:1], notOrdered, notExcluded)]" + ")" + "), "
+ + "{2: <tokens:c:nn />}, " + "[(w[0:2], ordered, notExcluded)]"
+ + ")" + ")" + ")" + "), " + "{1: <tokens:c:prp />}" + ")"
+ + "), 1" + ")", sq.toString());
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanRelationQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanRelationQueryJSON.java
index fccd34a..b051509 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestSpanRelationQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanRelationQueryJSON.java
@@ -89,6 +89,7 @@
sq.toString());
}
+
@Test
public void testFocusSource () throws QueryException {
//
@@ -101,8 +102,9 @@
sq.toString());
}
+
@Test
- public void testFocusTarget() throws QueryException {
+ public void testFocusTarget () throws QueryException {
String filepath = getClass().getResource(
"/queries/relation/focus-target.json").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
@@ -113,8 +115,9 @@
sq.toString());
}
+
@Test
- public void testFocusEmptyTarget() throws QueryException {
+ public void testFocusEmptyTarget () throws QueryException {
String filepath = getClass().getResource(
"/queries/relation/focus-empty-target.json").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
@@ -124,8 +127,9 @@
sq.toString());
}
+
@Test
- public void testFocusEmptyBoth() throws QueryException {
+ public void testFocusEmptyBoth () throws QueryException {
String filepath = getClass().getResource(
"/queries/relation/focus-empty-both.json").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
diff --git a/src/test/java/de/ids_mannheim/korap/response/TestResponse.java b/src/test/java/de/ids_mannheim/korap/response/TestResponse.java
index 423af96..b93ddfb 100644
--- a/src/test/java/de/ids_mannheim/korap/response/TestResponse.java
+++ b/src/test/java/de/ids_mannheim/korap/response/TestResponse.java
@@ -84,6 +84,7 @@
assertEquals("Fehler 4", respJson.at("/errors/0/1").asText());
};
+
// TODO: Skip this for the moment and refactor later
@Ignore
public void testResponseDeserialzation () throws IOException {
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKrill.java b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
index 8c4cd40..fd2e7c3 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
@@ -188,10 +188,12 @@
assertEquals(kr.getTotalResults(), 1);
};
+
// Todo: There SHOULD be a failure here, but Koral currently creates empty collections
@Test
public void queryJSONapiTest1 () {
- Krill test = new Krill("{\"@context\":\"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld\",\"errors\":[],\"warnings\":[],\"messages\":[],\"collection\":{},\"query\":{\"@type\":\"koral:token\",\"wrap\":{\"@type\":\"koral:term\",\"layer\":\"orth\",\"key\":\"Baum\",\"match\":\"match:eq\"}},\"meta\":{}}");
+ Krill test = new Krill(
+ "{\"@context\":\"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld\",\"errors\":[],\"warnings\":[],\"messages\":[],\"collection\":{},\"query\":{\"@type\":\"koral:token\",\"wrap\":{\"@type\":\"koral:term\",\"layer\":\"orth\",\"key\":\"Baum\",\"match\":\"match:eq\"}},\"meta\":{}}");
assertFalse(test.hasErrors());
};
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestResult.java b/src/test/java/de/ids_mannheim/korap/search/TestResult.java
index 7425cfd..6d9a4d5 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestResult.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestResult.java
@@ -149,13 +149,13 @@
Krill ks = new Krill(json);
Result kr = ks.apply(ki);
assertEquals((long) 7, kr.getTotalResults());
-
+
ObjectMapper mapper = new ObjectMapper();
JsonNode res = mapper.readTree(kr.toJsonString());
assertEquals(7, res.at("/meta/totalResults").asInt());
- assertEquals("spanOr([tokens:s:a, tokens:s:b])", res.at("/meta/serialQuery")
- .asText());
+ assertEquals("spanOr([tokens:s:a, tokens:s:b])",
+ res.at("/meta/serialQuery").asText());
assertEquals(5, res.at("/meta/itemsPerPage").asInt());
assertEquals(0, res.at("/meta/startIndex").asInt());
@@ -175,24 +175,19 @@
// Query
assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:or", res.at("/query/operation")
- .asText());
+ assertEquals("operation:or", res.at("/query/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/@type")
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:term", res.at("/query/operands/0/wrap/@type")
.asText());
- assertEquals("koral:term",
- res.at("/query/operands/0/wrap/@type").asText());
- assertEquals("orth", res.at("/query/operands/0/wrap/layer")
- .asText());
+ assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
assertEquals("a", res.at("/query/operands/0/wrap/key").asText());
assertEquals("match:eq", res.at("/query/operands/0/wrap/match")
.asText());
- assertEquals("koral:token", res.at("/query/operands/1/@type")
+ assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:term", res.at("/query/operands/1/wrap/@type")
.asText());
- assertEquals("koral:term",
- res.at("/query/operands/1/wrap/@type").asText());
- assertEquals("orth", res.at("/query/operands/1/wrap/layer")
- .asText());
+ assertEquals("orth", res.at("/query/operands/1/wrap/layer").asText());
assertEquals("b", res.at("/query/operands/1/wrap/key").asText());
assertEquals("match:eq", res.at("/query/operands/1/wrap/match")
.asText());
@@ -240,8 +235,8 @@
JsonNode res = mapper.readTree(kr.toTokenListJsonString());
assertEquals(3, res.at("/meta/totalResults").asInt());
- assertEquals("spanNext(base:s:a, base:s:b)", res.at("/meta/serialQuery")
- .asText());
+ assertEquals("spanNext(base:s:a, base:s:b)", res
+ .at("/meta/serialQuery").asText());
assertEquals(0, res.at("/meta/startIndex").asInt());
assertEquals(25, res.at("/meta/itemsPerPage").asInt());