Fixed use of s-layer for structs
Change-Id: I8da43fe43bc6006cdd99f2694ba20e3d6392481e
diff --git a/Changes b/Changes
index c21f150..c565ebe 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,8 @@
0.55.2 2016-02-13
- [bugfix] Fixed support for corpus and doc IDs containing
- dashes (diewald)
+ dashes (diewald)
+ - [bugfix] Support "s" layer without meaning "surface" -
+ this is a hack (diewald)
0.55.1 2016-02-10
- [bugfix] Fixed attribute serialization in MatchInfo (diewald)
diff --git a/src/main/java/de/ids_mannheim/korap/KrillQuery.java b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
index 56fb027..b12829b 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
@@ -1035,6 +1035,7 @@
// TODO: Not optimal as it does not respect non-term
private SpanQueryWrapper _termFromJson (JsonNode json, String direction)
throws QueryException {
+
if (!json.has("key") || json.get("key").asText().length() < 1) {
if (!json.has("attr"))
throw new QueryException(740,
@@ -1105,8 +1106,8 @@
break;
case "orth":
- // TODO: THIS IS A BUG! AND SHOULD BE NAMED "SURFACE" or . OR *
- layer = "s";
+ // TODO: THIS IS AN UGLY HACK! AND SHOULD BE NAMED "SURFACE" or . OR *
+ layer = ".";
break;
case "struct":
@@ -1119,7 +1120,7 @@
};
if (isCaseInsensitive && isTerm) {
- if (layer.equals("s"))
+ if (layer.equals("."))
layer = "i";
else {
this.addWarning(767,
@@ -1128,8 +1129,13 @@
};
// Ignore foundry for orth layer
- if (layer.equals("s") || layer.equals("i"))
+ if (layer.equals(".")) {
+ layer = "s";
value.setLength(0);
+ }
+ else if (layer.equals("i")) {
+ value.setLength(0);
+ };
value.append(layer).append(':');
};
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 3663623..0ca30cc 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
@@ -520,6 +520,23 @@
};
+ @Test
+ public void queryJSONelement () throws QueryException {
+ // <base/s=s>
+ try {
+ String json = getString(getClass().getResource(
+ "/queries/element/simple-element.jsonld").getFile());
+ KrillQuery kq = new KrillQuery("tokens");
+
+ assertEquals(kq.fromJson(json).toQuery().toString(),
+ "<tokens:base/s:s />");
+ }
+ catch (QueryException e) {
+ fail(e.getMessage());
+ };
+ };
+
+
public static String getString (String path) {
StringBuilder contentBuilder = new StringBuilder();
try {
diff --git a/src/test/resources/queries/element/simple-element.jsonld b/src/test/resources/queries/element/simple-element.jsonld
new file mode 100644
index 0000000..1841740
--- /dev/null
+++ b/src/test/resources/queries/element/simple-element.jsonld
@@ -0,0 +1,13 @@
+{
+ "@context":"http://ids-mannheim.de/ns/KorAP/json-ld/v0.3/context.jsonld",
+ "collection":null,
+ "query":{
+ "wrap": {
+ "layer": "s",
+ "foundry": "base",
+ "key": "s",
+ "@type": "koral:term"
+ },
+ "@type": "koral:span"
+ }
+}