implemented heuristics for token/span distinction in qNames (layer in [pos, lemma, ...] ? token : span)
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
index 04e6b21..e52e018 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
@@ -2,6 +2,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@@ -248,9 +249,17 @@
LinkedHashMap<String, Object> term = makeTerm();
object.put("wrap", term);
} else if (firstChildNodeCat.equals("qName")) { // only (foundry/)?layer specified
- // TODO may also be token!
- object = makeSpan();
- object.putAll(parseQNameNode(node.getChild(0)));
+ // may be token or span, depending on indicated layer! (e.g. cnx/cat=NP or mate/pos=NN)
+ HashMap<String, Object> qNameParse = parseQNameNode(node.getChild(0));
+ if (Arrays.asList(new String[]{"pos", "lemma", "morph", "tok"}).contains(qNameParse.get("layer"))) {
+ object = makeToken();
+ LinkedHashMap<String, Object> term = makeTerm();
+ object.put("wrap", term);
+ term.putAll(qNameParse);
+ } else {
+ object = makeSpan();
+ object.putAll(qNameParse);
+ }
} else if (firstChildNodeCat.equals("textSpec")) {
object = makeToken();
LinkedHashMap<String, Object> term = makeTerm();
@@ -259,7 +268,7 @@
}
if (node.getChildCount() == 3) { // (foundry/)?layer=key specification
- if (firstChildNodeCat.equals("tok")) {
+ if (object.get("@type").equals("korap:token")) {
HashMap<String, Object> term = (HashMap<String, Object>) object.get("wrap");
term.putAll(parseTextSpec(node.getChild(2)));
term.put("match", parseMatchOperator(node.getChild(1)));
diff --git a/src/test/java/AqlTreeTest.java b/src/test/java/AqlTreeTest.java
index 27bb1dd..43b72ab 100644
--- a/src/test/java/AqlTreeTest.java
+++ b/src/test/java/AqlTreeTest.java
@@ -72,7 +72,7 @@
assertEquals(layers1.replaceAll(" ", ""), map.replaceAll(" ", ""));
query = "treetagger/pos=\"NN\"";
- String layers2 = "{@type=korap:token, wrap={@type=korap:term, foundry=treetagger, layer=pos, key=NN, match=match:eq}}";
+ String layers2 = "{@type=korap:token, wrap={@type=korap:term, foundry=treetagger, layer=pos, match=match:eq, key=NN}}";
aqlt = new AqlTree(query);
map = aqlt.getRequestMap().get("query").toString();
assertEquals(layers2.replaceAll(" ", ""), map.replaceAll(" ", ""));