Added check for errors on QuerySerializer
Change-Id: Ie3dc8ebfe4e40076ce3c7e8808eb38f300b98f5e
diff --git a/Changes b/Changes
index 51e3dbb..4521dbb 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+0.29 2018-07-05
+ - Added check for errors on QuerySerializer object (diewald)
+
0.28 2018-01-10
- Added some enums for koral:operation (margaretha)
- Fixed node serialization of Annis QL containing lemma (margaretha)
diff --git a/pom.xml b/pom.xml
index 7087576..7cffd74 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Koral</artifactId>
- <version>0.28</version>
+ <version>0.29</version>
<packaging>jar</packaging>
<name>Koral</name>
<url>http://maven.apache.org</url>
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
index 699581b..4c02a31 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
@@ -21,8 +21,9 @@
* Main class for Koral, serializes queries from concrete QLs to KoralQuery
*
* @author Joachim Bingel (bingel@ids-mannheim.de), Michael Hanl
- * (hanl@ids-mannheim.de), Eliza Margaretha (margaretha@ids-mannheim.de)
- * @version 0.3.0
+ * (hanl@ids-mannheim.de), Eliza Margaretha (margaretha@ids-mannheim.de),
+ * Nils Diewald (diewald@ids-mannheim.de)
+ * @version 0.3.1
* @since 0.1.0
*/
public class QuerySerializer {
@@ -201,6 +202,18 @@
return raw();
}
+ /**
+ * Checks, if a query object contains errors.
+ */
+ public boolean hasErrors () {
+ if (ast != null) {
+ if (!ast.getErrors().isEmpty()) {
+ return true;
+ };
+ };
+ return false;
+ }
+
@SuppressWarnings("unchecked")
private Map<String, Object> raw () {
if (ast != null) {
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
index 0af2c18..f964f8b 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
@@ -44,6 +44,7 @@
public void testSingleTokens () throws JsonProcessingException, IOException {
query = "[base=Mann]";
qs.setQuery(query, "poliqarpplus");
+ assertFalse(qs.hasErrors());
res = mapper.readTree(qs.toJSON());
assertEquals("koral:token", res.at("/query/@type").asText());
assertEquals("Mann", res.at("/query/wrap/key").asText());
@@ -52,6 +53,7 @@
query = "[orth!=Frau]";
qs.setQuery(query, "poliqarpplus");
+ assertFalse(qs.hasErrors());
res = mapper.readTree(qs.toJSON());
assertEquals("koral:token", res.at("/query/@type").asText());
assertEquals("Frau", res.at("/query/wrap/key").asText());
@@ -60,6 +62,7 @@
query = "[p!=NN]";
qs.setQuery(query, "poliqarpplus");
+ assertFalse(qs.hasErrors());
res = mapper.readTree(qs.toJSON());
assertEquals("koral:token", res.at("/query/@type").asText());
assertEquals("NN", res.at("/query/wrap/key").asText());
@@ -68,6 +71,7 @@
query = "[!p!=NN]";
qs.setQuery(query, "poliqarpplus");
+ assertFalse(qs.hasErrors());
res = mapper.readTree(qs.toJSON());
assertEquals("koral:token", res.at("/query/@type").asText());
assertEquals("NN", res.at("/query/wrap/key").asText());
@@ -76,6 +80,7 @@
query = "[base=schland/x]";
qs.setQuery(query, "poliqarpplus");
+ assertFalse(qs.hasErrors());
res = mapper.readTree(qs.toJSON());
assertEquals("koral:token", res.at("/query/@type").asText());
assertEquals(".*?schland.*?", res.at("/query/wrap/key").asText());
@@ -84,6 +89,21 @@
assertEquals("match:eq", res.at("/query/wrap/match").asText());
}
+ @Test
+ public void testFailure () throws JsonProcessingException, IOException {
+ query = "[base=Mann";
+ qs.setQuery(query, "poliqarpplus");
+ assertTrue(qs.hasErrors());
+ res = mapper.readTree(qs.toJSON());
+ assertEquals(302, res.at("/errors/0/0").asInt());
+ assertEquals(302, res.at("/errors/1/0").asInt());
+ /*
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("Mann", res.at("/query/wrap/key").asText());
+ assertEquals("lemma", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ */
+ }
@Test
public void testNegatedTokens () throws JsonProcessingException,
@@ -389,12 +409,6 @@
assertEquals(7, operands.get(1).at("/value").asInt());
assertEquals("match:ne", operands.get(1).at("/match").asText());
}
-
-
-
-
-
-
@Test
public void testRepetition () throws JsonProcessingException, IOException {