Made koral:token optional in parsing an ExpressionGroup
Change-Id: I43ca4f268a9a2fd7c32617b2af5c0620a93e4d46
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/ExpressionParser.java b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/ExpressionParser.java
index 1fd9f6e..3565db1 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/ExpressionParser.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/ExpressionParser.java
@@ -6,6 +6,8 @@
import java.util.List;
import java.util.Set;
+import org.omg.CosNaming.IstringHelper;
+
import de.ids_mannheim.korap.query.object.KoralMatchOperator;
import de.ids_mannheim.korap.query.object.KoralObject;
import de.ids_mannheim.korap.query.object.KoralTermGroupRelation;
@@ -82,16 +84,16 @@
List<QueryNode> operands = queryNode.getChildren();
if (isNot) {
return parseBooleanExpression(operands,
- KoralTermGroupRelation.OR);
+ KoralTermGroupRelation.OR, isToken);
}
else {
return parseBooleanExpression(operands,
- KoralTermGroupRelation.AND);
+ KoralTermGroupRelation.AND, isToken);
}
}
else if (queryNode instanceof ExpressionGroup) {
// Ignore the group
- return parseExpression(queryNode.getFirstChild());
+ return parseExpression(queryNode.getFirstChild(), false, isToken);
}
else if (queryNode instanceof ExpressionNot) {
boolean negation = isNot ? false : true;
@@ -101,11 +103,11 @@
List<QueryNode> operands = queryNode.getChildren();
if (isNot) {
return parseBooleanExpression(operands,
- KoralTermGroupRelation.AND);
+ KoralTermGroupRelation.AND, isToken);
}
else {
return parseBooleanExpression(operands,
- KoralTermGroupRelation.OR);
+ KoralTermGroupRelation.OR, isToken);
}
}
else if (queryNode instanceof ExpressionWildcard) {
@@ -129,14 +131,20 @@
* @return a koral token
* @throws KoralException
*/
- private KoralToken parseBooleanExpression(List<QueryNode> operands,
- KoralTermGroupRelation relation) throws KoralException {
+ private KoralObject parseBooleanExpression(List<QueryNode> operands,
+ KoralTermGroupRelation relation, boolean isToken) throws KoralException {
List<KoralObject> terms = new ArrayList<>();
for (QueryNode node : operands) {
terms.add(parseExpression(node, false, false));
}
+
KoralTermGroup termGroup = new KoralTermGroup(relation, terms);
- return new KoralToken(termGroup);
+ if (isToken){
+ return new KoralToken(termGroup);
+ }
+ else {
+ return termGroup;
+ }
}
/**
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessorTest.java
index 8dc4cf0..407e6bd 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessorTest.java
@@ -237,26 +237,29 @@
@Test
public void testMultipleBooleanExpressions() throws IOException {
query = "[mate:lemma=\"sein\" & (mate:pos=\"PPOSS\"|mate:pos=\"VAFIN\")]";
- jsonLd = "{@type: koral:token,"
- + " wrap: { @type: koral:termGroup,"
+ jsonLd = "{@type: koral:termGroup,"
+ "relation: relation:or,"
+ " operands:["
+ "{@type: koral:term, key: PPOSS, foundry: mate, layer: p, type:type:regex, match: match:eq},"
- + "{@type: koral:term, key: VAFIN, foundry: mate, layer: p, type:type:regex, match: match:eq}]}}";
+ + "{@type: koral:term, key: VAFIN, foundry: mate, layer: p, type:type:regex, match: match:eq}]}";
FCSQLQueryProcessorTest.validateNode(query, "/query/wrap/operands/1",
jsonLd);
FCSQLQueryProcessorTest.validateNode(query, "/query/wrap/relation",
"relation:and");
- query = "[(cnx:lemma=\"sein\" | mate:pos=\"PPOSS\") | mate:pos=\"PPOSS\"]";
- jsonLd = "{@type: koral:token,"
- + " wrap: { @type: koral:termGroup,"
+ query = "[(cnx:lemma=\"sein\" | mate:pos=\"PPOSS\") | mate:pos=\"VAFIN\"]";
+ jsonLd = "{@type: koral:termGroup,"
+ "relation: relation:or,"
+ " operands:["
+ "{@type: koral:term, key: sein, foundry: cnx, layer: l, type:type:regex, match: match:eq},"
- + "{@type: koral:term, key: PPOSS, foundry: mate, layer: p, type:type:regex, match: match:eq}]}}";
+ + "{@type: koral:term, key: PPOSS, foundry: mate, layer: p, type:type:regex, match: match:eq}]}";
FCSQLQueryProcessorTest.validateNode(query, "/query/wrap/operands/0",
jsonLd);
+
+ query = "[(cnx:lemma=\"sein\" | mate:pos=\"PPOSS\") & text=\"ist\"]";
+ jsonLd = "{@type: koral:term, key: ist, foundry: opennlp, layer: orth, type:type:regex, match: match:eq}";
+ FCSQLQueryProcessorTest.validateNode(query, "/query/wrap/operands/1",
+ jsonLd);
}
// "!" expression /* not */