Added error messages to unsupported queries in SpanAttributeQuery
Change-Id: I5481e99269be8de1246533d3b6b3532d2c45ae3f
diff --git a/Changes b/Changes
index 5724b9c..cc5c464 100644
--- a/Changes
+++ b/Changes
@@ -1,10 +1,12 @@
-0.59.7 2021-12-01
+0.60 2021-12-03
- [feature] Implemented a new cache with on disk
storage and auto-update (margaretha).
- [feature] Support for tokenized snippet output
(fixed #72; diewald)
+ - [cleanup] Added error messages to unsupported queries in
+ SpanAttributeQuery (margaretha)
-0.59.6
+0.59.6 2021-11-10
- [bugfix] Fixed skipping of focus spans (fixed #78; margaretha,
diewald)
- [bugfix] Clear matchlist if skip fails in NextSpans
diff --git a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanAttributeQueryWrapper.java b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanAttributeQueryWrapper.java
index 0e22fd7..616fad5 100644
--- a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanAttributeQueryWrapper.java
+++ b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanAttributeQueryWrapper.java
@@ -51,8 +51,8 @@
return new SpanAttributeQuery((SpanTermQuery) sq, isNegative, true);
}
else {
- throw new IllegalArgumentException(
- "The subquery is not a SpanTermQuery.");
+ throw new QueryException(
+ "SpanAttributeQuery only supports SpanTermQuery.");
}
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanWithAttributeQueryWrapper.java b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanWithAttributeQueryWrapper.java
index efb476d..70e816a 100644
--- a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanWithAttributeQueryWrapper.java
+++ b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanWithAttributeQueryWrapper.java
@@ -10,6 +10,7 @@
import de.ids_mannheim.korap.query.SpanAttributeQuery;
import de.ids_mannheim.korap.query.SpanWithAttributeQuery;
import de.ids_mannheim.korap.util.QueryException;
+import de.ids_mannheim.korap.util.StatusCodes;
/**
* No optimization using expansion
@@ -182,8 +183,8 @@
attrQueryWrapper.isNegative, true);
}
else {
- throw new IllegalArgumentException(
- "The subquery is not a SpanTermQuery.");
+ throw new QueryException(StatusCodes.UNSUPPORTED_QUERY,
+ "SpanAttributeQuery only supports SpanTermQuery.");
}
}
return null;
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanWithAttributeJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanWithAttributeJSON.java
index 481949d..89e110b 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestSpanWithAttributeJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanWithAttributeJSON.java
@@ -1,20 +1,32 @@
package de.ids_mannheim.korap.query;
-import static de.ids_mannheim.korap.TestSimple.*;
+import static de.ids_mannheim.korap.TestSimple.getJsonQuery;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
import org.apache.lucene.search.spans.SpanQuery;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
import de.ids_mannheim.korap.util.QueryException;
+import de.ids_mannheim.korap.util.StatusCodes;
public class TestSpanWithAttributeJSON {
- @Rule
- public ExpectedException exception = ExpectedException.none();
+ @Test
+ public void testElementRegexAttribute () throws QueryException {
+ String filepath = getClass()
+ .getResource(
+ "/queries/attribute/element-regex-attribute.jsonld")
+ .getFile();
+ SpanQueryWrapper sqwi = getJsonQuery(filepath);
+ QueryException exception = assertThrows(QueryException.class, () -> {
+ sqwi.toQuery();
+ });
+ assertEquals("SpanAttributeQuery only supports SpanTermQuery.",
+ exception.getMessage());
+ assertEquals(StatusCodes.UNSUPPORTED_QUERY, exception.getErrorCode());
+ }
@Test
public void testElementSingleAttribute () throws QueryException {
@@ -179,13 +191,16 @@
@Test
public void testAnyElementSingleNotAttribute () throws QueryException {
- exception.expectMessage("The query requires a positive attribute.");
String filepath = getClass()
.getResource(
"/queries/attribute/any-element-with-single-not-attribute.jsonld")
.getFile();
- SpanQueryWrapper sqwi = getJsonQuery(filepath);
- SpanQuery sq = sqwi.toQuery();
+
+ Exception exception = assertThrows(QueryException.class, () -> {
+ getJsonQuery(filepath);
+ });
+ assertEquals("The query requires a positive attribute.",
+ exception.getMessage());
// assertEquals("tokens:???", sq.toString());
}
}
diff --git a/src/test/resources/queries/attribute/element-regex-attribute.jsonld b/src/test/resources/queries/attribute/element-regex-attribute.jsonld
new file mode 100644
index 0000000..4598947
--- /dev/null
+++ b/src/test/resources/queries/attribute/element-regex-attribute.jsonld
@@ -0,0 +1,19 @@
+{
+ "@context": "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
+ "errors": [],
+ "warnings": [],
+ "messages": [],
+ "collection": {},
+ "query": {
+ "@type": "koral:span",
+ "key": "head",
+ "attr": {
+ "@type": "koral:term",
+ "type" : "type:regex",
+ "layer": "type",
+ "key": "top.*",
+ "match": "match:eq"
+ }
+ },
+ "meta": {}
+}