Fixed minor warnings bug
diff --git a/CHANGES b/CHANGES
index 0e86989..c7c5bbb 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,8 +1,12 @@
-0.49 2014-11-12
+0.49 2014-11-14
- [bugfix] Rewrite works in repeating expansions (margaretha)
- [feature] Clean timeout with parameter support (diewald)
- [workaround] Support unknown overlap frame, if frames are known (diewald)
- [bugfix] Class payload fixed in SpanRepetitions (margaretha)
+ - [bugfix] #179 Expansion bug fixed (margaretha)
+ - [bugfix] Corrected small bug where null warnings where
+ returned in JSON (diewald)
+ - [cleanup] Converted error to failure (diewald)
0.48 2014-11-07
- [feature] Retrieval of token lists (diewald)
diff --git a/src/main/java/de/ids_mannheim/korap/KorapQuery.java b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
index 0233234..d07c100 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
@@ -716,11 +716,13 @@
return this.warning;
};
- public void addWarning (String warning) {
+ public void addWarning (String msg) {
+ if (msg == null)
+ return;
if (this.warning == null)
- this.warning = warning;
+ this.warning = msg;
else
- this.warning += "; " + warning;
+ this.warning += "; " + msg;
};
public void setWarning (String warning) {
diff --git a/src/main/java/de/ids_mannheim/korap/KorapResult.java b/src/main/java/de/ids_mannheim/korap/KorapResult.java
index 0db50aa..ab4389a 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapResult.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapResult.java
@@ -141,9 +141,11 @@
return this.warning;
}
- public void addWarning (String warning) {
+ public void addWarning (String msg) {
+ if (msg == null)
+ return;
if (this.warning == null)
- this.warning = warning;
+ this.warning = msg;
else
this.warning += "; " + warning;
};
diff --git a/src/main/java/de/ids_mannheim/korap/KorapSearch.java b/src/main/java/de/ids_mannheim/korap/KorapSearch.java
index e8c0a6b..2d342b2 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapSearch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapSearch.java
@@ -109,12 +109,13 @@
};
// Legacy code: Report warning coming from the request
- if (this.request.has("warning"))
+ if (this.request.has("warning") && this.request.get("warning").asText().length() > 0)
this.addWarning(this.request.get("warning").asText());
if (this.request.has("warnings")) {
JsonNode warnings = this.request.get("warnings");
for (JsonNode node : warnings)
- this.addWarning(node.asText());
+ if (node.asText().length() > 0)
+ this.addWarning(node.asText());
};
// end of legacy code
@@ -215,11 +216,14 @@
return this.warning;
};
- public void addWarning (String warning) {
+ public void addWarning (String msg) {
+ if (msg == null)
+ return;
+
if (this.warning == null)
- this.warning = warning;
+ this.warning = msg;
else
- this.warning += "; " + warning;
+ this.warning += "; " + msg;
};
public SpanQuery getQuery () {
diff --git a/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java b/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java
index bb1112f..8f59345 100644
--- a/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java
+++ b/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java
@@ -68,7 +68,7 @@
);
SpanQuery sq = sqwi.toQuery();
- System.out.println(sq.toString());
+ // System.out.println(sq.toString());
ki = new KorapIndex();
@@ -78,11 +78,13 @@
ki.commit();
kr = ki.search(sq, (short) 10);
+ /*
for (KorapMatch km : kr.getMatches()){
System.out.println(km.getStartPos() +","+km.getEndPos()+" "
+km.getSnippetBrackets()
);
}
+ */
assertEquals(495, kr.getTotalResults());
assertEquals(3, kr.getMatch(0).getStartPos());
assertEquals(5, kr.getMatch(0).getEndPos());
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
index ee7f712..75ff3c9 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
@@ -1093,19 +1093,25 @@
ki.addDocFile(
getClass().getResource("/wiki/PPP-02924.json.gz").getFile(),true);
ki.commit();
- KorapResult kr = ki.search(sq, (short) 10);
+ try {
+ KorapResult kr = ki.search(sq, (short) 10);
+ assertEquals(2, kr.getTotalResults());
+ assertEquals(0, kr.getMatch(0).getLocalDocID());
+ assertEquals(76, kr.getMatch(0).getStartPos());
+ assertEquals(93, kr.getMatch(0).getEndPos());
+ assertEquals(1, kr.getMatch(0).getLocalDocID());
+ assertEquals(237, kr.getMatch(1).getStartPos());
+ assertEquals(252, kr.getMatch(1).getEndPos());
+ }
+
+ catch (Exception e) {
+ fail("Nullpointer (known)");
+ };
// for (KorapMatch km : kr.getMatches()){
// System.out.println(km.getStartPos() +","+km.getEndPos()+" "
// +km.getSnippetBrackets());
// }
- assertEquals(2, kr.getTotalResults());
- assertEquals(0, kr.getMatch(0).getLocalDocID());
- assertEquals(76, kr.getMatch(0).getStartPos());
- assertEquals(93, kr.getMatch(0).getEndPos());
- assertEquals(1, kr.getMatch(0).getLocalDocID());
- assertEquals(237, kr.getMatch(1).getStartPos());
- assertEquals(252, kr.getMatch(1).getEndPos());
}
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java b/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java
index 983d3eb..b353ee1 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java
@@ -95,6 +95,35 @@
};
@Test
+ public void checkJSONResultWarningBug () throws Exception {
+ KorapIndex ki = new KorapIndex();
+ FieldDocument fd = new FieldDocument();
+ fd.addString("ID", "doc-1");
+ fd.addString("UID", "1");
+ fd.addTV("tokens",
+ "abab",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]" +
+ "[(3-4)s:b|i:a|_3#3-4]");
+ ki.addDoc(fd);
+ ki.commit();
+
+ String json = getString(getClass().getResource("/queries/bugs/optionality_warning.jsonld").getFile());
+ KorapSearch ks = new KorapSearch(json);
+
+ KorapResult kr = ks.run(ki);
+ assertEquals(2, kr.getTotalResults());
+
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res = mapper.readTree(kr.toJSON());
+
+ assertEquals("Optionality of query is ignored", res.at("/warning").asText());
+
+ };
+
+
+ @Test
public void checkJSONResultForJSONInput () throws Exception {
KorapIndex ki = new KorapIndex();
FieldDocument fd = new FieldDocument();
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 8765457..06908d7 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
@@ -1011,7 +1011,7 @@
);
kr = new KorapSearch(json).run(ki);
- System.out.println(kr.getQuery());
+ // System.out.println(kr.getQuery());
// if (kr.getTotalResults() != 1)
// fail("Expansion fails");
diff --git a/src/test/resources/queries/bugs/optionality_warning.jsonld b/src/test/resources/queries/bugs/optionality_warning.jsonld
new file mode 100644
index 0000000..08b9df9
--- /dev/null
+++ b/src/test/resources/queries/bugs/optionality_warning.jsonld
@@ -0,0 +1,27 @@
+{
+ "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
+ "query" : {
+ "@type" : "korap:group",
+ "boundary" : {
+ "@type" : "korap:boundary",
+ "max" : 1,
+ "min" : 0
+ },
+ "max" : 1,
+ "min" : 0,
+ "operands" : [
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "foundry" : "opennlp",
+ "layer" : "orth",
+ "key" : "a",
+ "match" : "match:eq"
+ }
+ }
+ ],
+ "operation" : "operation:repetition"
+ }
+}
+