MORPH operator, more examples
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
index 6aad6f2..a0d6cee 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
@@ -218,9 +218,9 @@
// negate field (see above)
if (negate) {
- fieldMap.put("match", "match:"+"ne");
+ fieldMap.put("match", "match:ne");
} else {
- fieldMap.put("match", "match:"+"eq");
+ fieldMap.put("match", "match:eq");
}
//Step II: decide where to put
putIntoSuperObject(token, 1);
@@ -235,13 +235,17 @@
fieldMap.put("@type", "korap:term");
// fieldMap.put("key", "morph:"+node.getChild(0).toString().replace(" ", "_"));
- fieldMap.put("key", node.getChild(0).toString().replace(" ", "_"));
+ String[] morphValues = node.getChild(0).toString().split(" ");
+ String pos = morphValues[0];
+
+ fieldMap.put("key", pos);
+ fieldMap.put("layer", "pos");
// make category-specific fieldMap entry
// negate field (see above)
if (negate) {
- fieldMap.put("match", "match:"+"ne");
+ fieldMap.put("match", "match:ne");
} else {
- fieldMap.put("match", "match:"+"eq");
+ fieldMap.put("match", "match:eq");
}
// List<String> morphValues = QueryUtils.parseMorph(node.getChild(0).toStringTree());
// System.err.println(morphValues);
@@ -768,7 +772,12 @@
"(Der /+w1:3,s1 Mann) /+w5 geht",
"(Der /+w1:3,s1 Mann) /-w5 geht",
"(Der /+w1:3,s1 Mann) /+w5 (geht weg)",
- "Tag der $offenen Tür"
+ "Tag der $offenen Tür",
+ "#BED($wegen , sa)",
+ "#BEG(#ELEM(S))",
+ "#BEG(<s>)",
+ "MORPH(V PRES)",
+ "Mond?"
};
CosmasTree.debug=true;
for (String q : queries) {
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 ff7d432..21e0852 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
@@ -3,6 +3,8 @@
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+
import de.ids_mannheim.korap.util.QueryException;
import org.slf4j.LoggerFactory;
@@ -23,6 +25,7 @@
public QuerySerializer() {
mapper = new ObjectMapper();
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
/**
@@ -45,12 +48,29 @@
* regex
* & field_group
*/
- "Der Mann",
- "Der /+w1:3 Mann",
- "Der /+w1:3,s1 Mann",
- "(Der /+w1:3,s1 Mann) /+w5 geht",
- "(Der /+w1:3,s1 Mann) /-w5 geht",
- "(Der /+w1:3,s1 Mann) /+w5 (geht weg)",
+ "Buch",
+ "das Buch",
+ "das /+w1:3 Buch",
+ "das /+w1:3,s1 Buch",
+ "(das /+w1:3,s1 Buch) /+w5 Tisch",
+ "(das /+w1:3,s1 Buch) /-w5 Tisch",
+ "(das /+w1:3,s1 Buch) /+w5 (auf dem Tisch)",
+
+
+ "Institut für Deutsche Sprache",
+ "Institut für deutsche Sprache",
+ "Institut für $deutsche Sprache",
+ "Institut für &deutsch Sprache",
+ "Institut für /+w2 Sprache",
+ "Institut für %+w1 deutsche Sprache",
+ "Institut für MORPH(A) Sprache",
+
+ "wegen #IN(L) <s>",
+ "$wegen #IN(L) <s>",
+ "#BED($wegen , +sa)",
+ "#BEG(#ELEM(S))",
+ "MORPH(V) #IN(L) #ELEM(S)",
+ "MORPH(V) #IN(R) #ELEM(S)",
};
} else {
@@ -61,7 +81,8 @@
i++;
try {
System.out.println(q);
- jg.run(q, "cosmas", System.getProperty("user.home") + "/bsp" + i + ".json");
+ String ql = "cosmas";
+ jg.run(q, ql, System.getProperty("user.home") + "/" + ql + i + ".json");
System.out.println();
} catch (NullPointerException npe) {
npe.printStackTrace();
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
index cee10ef..5d9f0ba 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
@@ -134,7 +134,6 @@
public static List<String> parseMorph(String stringTree) {
ArrayList<String> morph = new ArrayList<String>();
- System.err.println(stringTree);
return morph;
}
diff --git a/src/test/java/CosmasTreeTest.java b/src/test/java/CosmasTreeTest.java
index 999b328..63bf459 100644
--- a/src/test/java/CosmasTreeTest.java
+++ b/src/test/java/CosmasTreeTest.java
@@ -73,14 +73,29 @@
@Test
public void testCaseSensitivityFlag() throws QueryException {
- //TODO ignorieroperator $ http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/ignorierung.html
+ query="$deutscher";
+ String cs1 =
+ "{@type=korap:token, wrap={@type=korap:term, caseInsensitive=true, key=deutscher, layer=orth, match=match:eq}}";
+ ct = new CosmasTree(query);
+ map = ct.getRequestMap().get("query").toString();
+ assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+
+ query="$deutscher Bundestag";
+ String cs2 =
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, caseInsensitive=true, key=deutscher, layer=orth, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" +
+ "]}";
+ ct = new CosmasTree(query);
+ map = ct.getRequestMap().get("query").toString();
+ assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
}
@Test
public void testMORPH() throws QueryException {
query="#MORPH(V)";
String morph1 =
- "{@type=korap:token, wrap={@type=korap:term, key=V, match=match:eq}}";
+ "{@type=korap:token, wrap={@type=korap:term, key=V, layer=pos, match=match:eq}}";
ct = new CosmasTree(query);
map = ct.getRequestMap().get("query").toString();
assertEquals(morph1.replaceAll(" ", ""), map.replaceAll(" ", ""));
diff --git a/src/test/java/PoliqarpPlusTreeTest.java b/src/test/java/PoliqarpPlusTreeTest.java
index b51bc9a..d2ffe72 100644
--- a/src/test/java/PoliqarpPlusTreeTest.java
+++ b/src/test/java/PoliqarpPlusTreeTest.java
@@ -75,6 +75,26 @@
}
@Test
+ public void testCaseSensitivityFlag() throws QueryException {
+ String query="[orth=deutscher/i]";
+ String cs1 =
+ "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}";
+ ppt = new PoliqarpPlusTree(query);
+ map = ppt.getRequestMap().get("query").toString();
+ assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+
+ query="[orth=deutscher/i][orth=Bundestag]";
+ String cs2 =
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" +
+ "]}";
+ ppt = new PoliqarpPlusTree(query);
+ map = ppt.getRequestMap().get("query").toString();
+ assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ }
+
+ @Test
public void testElements() throws QueryException {
// <s>
String elem1 = "{@type=korap:span, key=s}";