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
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
index aead247..74a827b 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
@@ -108,8 +108,10 @@
// Create a container for virtual collections:
KorapCollection kc = new KorapCollection(ki);
- String json = getString(getClass().getResource("/queries/bsp-class-2.jsonld").getFile());
+ // String json = getString(getClass().getResource("/queries/bsp-class-2.jsonld").getFile());
+ String json = getString(getClass().getResource("/queries/bsp-repetition.jsonld").getFile());
+ System.err.println(new KorapSearch(json).getQuery().toString());
KorapResult kr = new KorapSearch(json).run(ki);
System.err.println(kr.toJSON());
@@ -117,6 +119,7 @@
// assertEquals(14, kc.numberOf("documents"));
};
+
public static String getString (String path) {
StringBuilder contentBuilder = new StringBuilder();
try {
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
index 2ed6e06..ae5365d 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
@@ -262,6 +262,15 @@
assertEquals(sqwi.toQuery().toString(), "shrink(1: spanEndsWith(<tokens:s />, {1: tokens:mate/p:V}))");
};
+
+ @Test
+ public void queryJSONrepetition () {
+ SpanQueryWrapperInterface sqwi = jsonQuery(getClass().getResource("/queries/bsp-repetition.jsonld").getFile());
+
+ // der[cnx/p=A]{0,2}[tt/p=NN]
+ assertEquals(sqwi.toQuery().toString(), "spanNext(spanOr([tokens:s:der, spanNext(tokens:s:der, spanQuantifier(tokens:cnx/p:A[1:2]))]), tokens:tt/p:NN)");
+ };
+
public static String getString (String path) {
StringBuilder contentBuilder = new StringBuilder();
try {
diff --git a/src/test/resources/queries/bsp-repetition.jsonld b/src/test/resources/queries/bsp-repetition.jsonld
new file mode 100644
index 0000000..342b7d5
--- /dev/null
+++ b/src/test/resources/queries/bsp-repetition.jsonld
@@ -0,0 +1,62 @@
+{
+ "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+ "collections" : [
+ {
+ "@type" : "korap:meta-filter",
+ "@value" : {
+ "@field" : "korap:field#corpusID",
+ "@type" : "korap:term",
+ "@value" : "WPD"
+ }
+ }
+ ],
+ "meta" : {},
+ "query" : {
+ "@type" : "korap:group",
+ "operands" : [
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "key" : "der",
+ "layer" : "orth",
+ "match" : "match:eq"
+ }
+ },
+ {
+ "@type" : "korap:group",
+ "boundary" : {
+ "@type" : "korap:boundary",
+ "max" : 2,
+ "min" : 0
+ },
+ "max" : 2,
+ "min" : 0,
+ "operands" : [
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "foundry" : "cnx",
+ "key" : "A",
+ "layer" : "p",
+ "match" : "match:eq"
+ }
+ }
+ ],
+ "operation" : "operation:repetition"
+ },
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "foundry" : "tt",
+ "key" : "NN",
+ "layer" : "p",
+ "match" : "match:eq"
+ }
+ }
+ ],
+ "operation" : "operation:sequence"
+ }
+}
\ No newline at end of file