Skip to content

Commit

Permalink
verbosity can be switched on/off on command line.
Browse files Browse the repository at this point in the history
Change-Id: Ie5c97453e654d4e04ae058f490ff3d47b1b34956
  • Loading branch information
Bodmo committed Nov 9, 2023
1 parent d80a258 commit b44d0c9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -140,11 +142,22 @@ public Cosmas2QueryProcessor (String query) {
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
Expand All @@ -157,11 +170,10 @@ public void process (String query) {
}
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);
}
Expand All @@ -181,11 +193,13 @@ private void processNode (Tree node) {
stackedObjects = 0;
stackedToWrap = 0;

if (verbose) {
/*
if (verbose) {
System.err.println(" " + objectStack);
System.out.println(openNodeCats);
}

*/

/* ***************************************
* Processing individual node categories *
* ***************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +34,7 @@ public class QuerySerializer {
private String version = "Unknown";
private String name = "Unknown";
private static Properties info;

private boolean bDebug = false;
{

loadInfo();
Expand Down Expand Up @@ -104,24 +105,31 @@ public static void main (String[] args) {
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();
Expand All @@ -145,9 +153,9 @@ public static void main (String[] args) {
* '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);
Expand All @@ -174,7 +182,9 @@ else if (queryLanguage.equalsIgnoreCase("annis")) {
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) {
Expand Down Expand Up @@ -230,7 +240,7 @@ public void setVerbose (boolean verbose) {
public final String toJSON () {
String ser;
try {
ser = mapper.writeValueAsString(raw());
ser = mapper.writeValueAsString(raw());
// System.out.println(ser);
}
catch (JsonProcessingException e) {
Expand Down

0 comments on commit b44d0c9

Please sign in to comment.