Fix running QuerySerializer via commandline
Add CollectionQueryProcessor and tests.
Change-Id: I1a43651b6bdc8f152493d57795dc7b7b0a7b7b6a
Reviewed-on: https://korap.ids-mannheim.de/gerrit/c/KorAP/Koral/+/9397
Reviewed-by: margaretha <margaretha@ids-mannheim.de>
Reviewed-by: Nils Diewald <nils@diewald-online.de>
diff --git a/Changes b/Changes
index 829a7cc..36be4ab 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,7 @@
+0.45 2025-05-23
+ - [bugfix] Fix running QuerySerializer via commandline
+ - [feature] Add serializing corpus query via commandline
+
0.44 2024-07-12
- [security] Dependencies updated
diff --git a/pom.xml b/pom.xml
index 1d31d08..496551a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
<groupId>de.ids-mannheim.korap.koral</groupId>
<artifactId>Koral</artifactId>
- <version>0.44.0</version>
+ <version>0.45</version>
<packaging>jar</packaging>
<name>Koral</name>
<url>https://korap.ids-mannheim.de</url>
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 a51bae1..2e31060 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
@@ -175,13 +175,15 @@
else if (queryLanguage.equalsIgnoreCase("annis")) {
ast = new AnnisQueryProcessor(query);
}
+ else if (queryLanguage.equalsIgnoreCase("cq")) {
+ ast = new CollectionQueryProcessor(query);
+ }
else {
throw new IllegalArgumentException(
queryLanguage + " is not a supported query language!");
}
- if( bDebug )
- System.out.println(this.toJSON());
+ System.out.println(this.toJSON());
}
public QuerySerializer setQuery (String query, String ql, String version) {
@@ -219,6 +221,9 @@
else if (ql.equalsIgnoreCase("annis")) {
ast = new AnnisQueryProcessor(query);
}
+ else if (ql.equalsIgnoreCase("cq")) {
+ ast = new CollectionQueryProcessor(query);
+ }
else {
ast.addError(StatusCodes.UNKNOWN_QUERY_LANGUAGE,
ql + " is not a supported query language!");
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/QuerySerializerTest.java b/src/test/java/de/ids_mannheim/korap/query/test/QuerySerializerTest.java
new file mode 100644
index 0000000..c5e5e87
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/query/test/QuerySerializerTest.java
@@ -0,0 +1,82 @@
+package de.ids_mannheim.korap.query.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import org.junit.Test;
+
+import de.ids_mannheim.korap.query.serialize.QuerySerializer;
+
+public class QuerySerializerTest {
+
+ @Test
+ public void serializePoliqarp () {
+ // Backup the original System.out
+ PrintStream originalOut = System.out;
+
+ // Create a stream to hold the output
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ String query = "Sonne";
+ String ql = "poliqarp";
+ String[] args = { query, ql };
+ QuerySerializer.main(args);
+
+ System.setOut(originalOut);
+ String expectedOutput = "{\"query\":{\"@type\":\"koral:token\","
+ + "\"wrap\":{\"@type\":\"koral:term\",\"match\":"
+ + "\"match:eq\",\"layer\":\"orth\",\"key\":\"Sonne\"}},"
+ + "\"@context\":\"http://korap.ids-mannheim.de/ns/koral"
+ + "/0.3/context.jsonld\"}\n" + System.lineSeparator();
+ assertEquals(expectedOutput, outputStream.toString());
+ }
+
+ @Test
+ public void serializeFCSQL () {
+ // Backup the original System.out
+ PrintStream originalOut = System.out;
+
+ // Create a stream to hold the output
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ String query = "\"Sonne\"";
+ String ql = "fcsql";
+ String[] args = { query, ql };
+ QuerySerializer.main(args);
+
+ System.setOut(originalOut);
+ String expectedOutput = "{\"query\":{\"@type\":\"koral:token\","
+ + "\"wrap\":{\"@type\":\"koral:term\",\"key\":\"Sonne\","
+ + "\"foundry\":\"opennlp\",\"layer\":\"orth\",\"type\":"
+ + "\"type:regex\",\"match\":\"match:eq\"}},\"@context\":"
+ + "\"http://korap.ids-mannheim.de/ns/koral/0.3/"
+ + "context.jsonld\"}\n" + System.lineSeparator();
+ assertEquals(expectedOutput, outputStream.toString());
+ }
+
+ @Test
+ public void serializeCorpusQuery () {
+ // Backup the original System.out
+ PrintStream originalOut = System.out;
+
+ // Create a stream to hold the output
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ String query = "corpusSigle=WPD17";
+ String ql = "cq";
+ String[] args = { query, ql };
+ QuerySerializer.main(args);
+
+ System.setOut(originalOut);
+ String expectedOutput = "{\"collection\":{\"@type\":\"koral:doc\","
+ + "\"match\":\"match:eq\",\"value\":\"WPD17\",\"key\":"
+ + "\"corpusSigle\"},\"@context\":\"http://korap.ids-mannheim.de"
+ + "/ns/koral/0.3/context.jsonld\"}\n" + System.lineSeparator();
+ assertEquals(expectedOutput, outputStream.toString());
+ }
+}