verbosity can be switched on/off on command line.
Change-Id: Ie5c97453e654d4e04ae058f490ff3d47b1b34956
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
index 41704fe..cc03439 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
@@ -24,6 +24,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
@@ -140,11 +142,22 @@
KoralObjectGenerator.setQueryProcessor(this);
this.query = query;
process(query);
- if (DEBUG) {
- log.debug(">>> " + requestMap.get("query") + " <<<");
- System.out.printf("Cosmas2QueryProcessor: >>%s<<.\n", requestMap.get("query"));
- }
- }
+ if (verbose)
+ {
+ //log.debug(">>> " + requestMap.get("query") + " <<<");
+ try {
+ // query from requestMap is unformatted JSON. Make it pretty before displaying:
+ ObjectMapper mapper = new ObjectMapper();
+ String jsonQuery = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestMap.get("query"));
+ System.out.printf("Cosmas2QueryProcessor: JSON output: %s\n\n", jsonQuery);
+ }
+ catch (JsonProcessingException e)
+ {
+ System.out.printf("Cosmas2QueryProcessor: >>%s<<.\n", requestMap.get("query"));
+ //e.printStackTraObjectMapper mapper = new ObjectMapper();ce();
+ }
+ }
+ }
@Override
@@ -157,11 +170,10 @@
}
if (tree != null)
{
-
- if (DEBUG) {
- log.debug("ANTLR parse tree: " + tree.toStringTree());
- System.out.printf("\nANTLR parse tree: %s.\n\n", tree.toStringTree());
- }
+ if (verbose) {
+ log.debug("ANTLR parse tree: " + tree.toStringTree());
+ System.out.printf("\nANTLR parse tree: %s.\n\n", tree.toStringTree());
+ }
processNode(tree);
}
@@ -181,11 +193,13 @@
stackedObjects = 0;
stackedToWrap = 0;
- if (verbose) {
+ /*
+ if (verbose) {
System.err.println(" " + objectStack);
System.out.println(openNodeCats);
}
-
+ */
+
/* ***************************************
* Processing individual node categories *
* ***************************************
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 94bf15d..ba98f24 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
@@ -18,6 +18,7 @@
import de.ids_mannheim.korap.query.serialize.util.KoralObjectGenerator;
import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
+import com.fasterxml.jackson.core.JsonPointer;
/**
* Main class for Koral, serializes queries from concrete QLs to KoralQuery
@@ -33,7 +34,7 @@
private String version = "Unknown";
private String name = "Unknown";
private static Properties info;
-
+ private boolean bDebug = false;
{
loadInfo();
@@ -104,24 +105,31 @@
int i = 0;
String[] queries = null;
String ql = "poliqarpplus";
- boolean bDebug = true;
+ boolean bDebug = false;
if (args.length < 2) {
System.err
- .println("Usage: QuerySerializer \"query\" queryLanguage");
+ .println("Usage: QuerySerializer \"query\" queryLanguage [-show]");
System.exit(1);
}
else {
queries = new String[] { args[0] };
ql = args[1];
}
+ if( args.length >= 3 )
+ {
+ if( args[2].compareToIgnoreCase("-show") == 0 )
+ bDebug = true;
+ }
+
for (String q : queries) {
i++;
try {
- if( bDebug ) System.out.printf("QuerySerialize: query = >>%s<< lang = %s.\n", q, ql);
-
- jg.run(q, ql);
- System.out.println();
+ if( bDebug )
+ System.out.printf("QuerySerialize: query = >>%s<< lang = %s.\n", q, ql);
+
+ jg.run(q, ql, bDebug);
+ System.out.println();
}
catch (NullPointerException npe) {
npe.printStackTrace();
@@ -145,9 +153,9 @@
* 'poliqarpplus', 'cqp', 'cosmas2', 'annis' or 'cql'.
* @throws IOException
*/
- public void run (String query, String queryLanguage) throws IOException {
+ public void run (String query, String queryLanguage, boolean bDebug) throws IOException {
- ast.verbose = DEBUG ? true : false; // debugging: 01.09.23/FB
+ ast.verbose = bDebug; // debugging: 01.09.23/FB
if (queryLanguage.equalsIgnoreCase("poliqarp")) {
ast = new PoliqarpPlusQueryProcessor(query);
@@ -174,7 +182,9 @@
throw new IllegalArgumentException(
queryLanguage + " is not a supported query language!");
}
- System.out.println(this.toJSON());
+
+ if( bDebug )
+ System.out.println(this.toJSON());
}
public QuerySerializer setQuery (String query, String ql, String version) {
@@ -230,7 +240,7 @@
public final String toJSON () {
String ser;
try {
- ser = mapper.writeValueAsString(raw());
+ ser = mapper.writeValueAsString(raw());
// System.out.println(ser);
}
catch (JsonProcessingException e) {