Some debug flags inserted
diff --git a/src/main/java/de/ids_mannheim/korap/KorapQuery.java b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
index b1b7e2f..6df320e 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
@@ -213,6 +213,11 @@
);
case "operation:sequence":
+ if (DEBUG) {
+ log.trace("Found new sequence");
+ System.err.println("----");
+ };
+
if (operands.size() < 2)
throw new QueryException(
"SpanSequenceQuery needs at least two operands"
@@ -320,6 +325,9 @@
throw new QueryException("The maximum repetition value has to " +
"be greater or equal to the minimum repetition value");
+ if (DEBUG)
+ log.trace("Found new repetition %d-%d", min, max);
+
return new SpanRepetitionQueryWrapper(
this.fromJSON(operands.get(0)), min, max
);
diff --git a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSequenceQueryWrapper.java b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSequenceQueryWrapper.java
index 9732556..9b695d8 100644
--- a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSequenceQueryWrapper.java
+++ b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSequenceQueryWrapper.java
@@ -17,6 +17,9 @@
import org.apache.lucene.search.spans.SpanTermQuery;
import de.ids_mannheim.korap.query.wrap.SpanQueryWrapperInterface;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* @author Nils Diewald
*/
@@ -24,6 +27,13 @@
private String field;
private ArrayList<SpanQuery> segments;
private ArrayList<DistanceConstraint> constraints;
+
+ // Logger
+ private final static Logger log = LoggerFactory.getLogger(SpanSequenceQueryWrapper.class);
+
+ // This advices the java compiler to ignore all loggings
+ public static final boolean DEBUG = false;
+
private boolean
isInOrder = true,
isNull = true,
@@ -47,6 +57,8 @@
public SpanSequenceQueryWrapper (String field, SpanQuery sq) {
this(field);
+ if (DEBUG)
+ log.trace("New spanquery sequence " + sq.toString());
this.segments.add((SpanQuery) sq);
this.isOptional = false;
this.isNull = false;
@@ -58,12 +70,18 @@
this.segments.add((SpanQuery) sswq.toQuery());
this.isNull = false;
if (sswq.isOptional()) {
+ if (DEBUG)
+ log.trace("New optional query sequence " +
+ sswq.toQuery().toString());
this.isOptional = true;
this.lastIsOptional = true;
this.firstIsOptional = true;
}
else {
this.isOptional = false;
+ if (DEBUG)
+ log.trace("New non-optional query sequence " +
+ sswq.toQuery().toString());
};
};
};
@@ -95,7 +113,9 @@
};
public SpanSequenceQueryWrapper append (String term) {
- return this.append((SpanQuery) new SpanTermQuery(new Term(field, term)));
+ return this.append(
+ (SpanQuery) new SpanTermQuery(new Term(field, term))
+ );
};
public SpanSequenceQueryWrapper append (SpanQuery query) {
@@ -104,6 +124,10 @@
// Check if there has to be alternation magic in action
if (this.lastIsOptional) {
+ if (DEBUG)
+ log.trace("Append non-opt query to opt query " +
+ query.toString());
+
SpanAlterQueryWrapper saqw = new SpanAlterQueryWrapper(field, query);
SpanSequenceQueryWrapper ssqw = new SpanSequenceQueryWrapper(field, query);
// Remove last element of the list and prepend it
@@ -119,6 +143,10 @@
this.segments.add((SpanQuery) saqw.toQuery());
}
else {
+ if (DEBUG)
+ log.trace("Append non-opt query to non-opt query " +
+ query.toString());
+
this.segments.add(query);
};
@@ -129,6 +157,9 @@
if (!ssq.isNull()) {
SpanQuery appendQuery = ssq.toQuery();
if (!ssq.isOptional()) {
+ if (DEBUG)
+ log.trace("Append non-opt query to non-opt query " +
+ appendQuery.toString());
return this.append(appendQuery);
};
@@ -141,9 +172,18 @@
ssqw.prepend(lastQuery);
// Situation is a?b?
- if (this.lastIsOptional)
+ if (this.lastIsOptional) {
saqw.or(appendQuery);
- // last stays optional
+ // last stays optional
+ if (DEBUG)
+ log.trace("Append opt query to opt query " +
+ appendQuery.toString());
+
+ }
+ else if (DEBUG) {
+ log.trace("Append opt query to non-opt query " +
+ appendQuery.toString());
+ };
saqw.or(ssqw);
this.segments.add((SpanQuery) saqw.toQuery());
@@ -153,6 +193,10 @@
else {
this.segments.add(appendQuery);
+ if (DEBUG)
+ log.trace("Append opt query " +
+ appendQuery.toString());
+
// Update boundary optionality
this.firstIsOptional = true;
this.isOptional = true;
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index e885412..3619d79 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -12,6 +12,10 @@
#log4j.logger.de.ids_mannheim.korap.query.spans.ClassSpans = TRACE, stdout
#log4j.logger.de.ids_mannheim.korap.query.spans.MatchSpans = TRACE, stdout
+# Wrapper
+#log4j.logger.de.ids_mannheim.korap.KorapQuery = TRACE, stdout
+#log4j.logger.de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper = TRACE, stdout
+
# Collections
#log4j.logger.de.ids_mannheim.korap.KorapFilter = TRACE, stdout
#log4j.logger.de.ids_mannheim.korap.KorapCollection = TRACE, stdout