Multiple distance with token distance exclusion constraint,
Add packages to the test classes
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanMultipleDistanceQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanMultipleDistanceQuery.java
index 08628ff..473e9c6 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanMultipleDistanceQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanMultipleDistanceQuery.java
@@ -18,6 +18,7 @@
* No repetition of constraints of the same type is allowed. For example,
* there must only exactly one constraint for word/token-based distance.
*
+ * Warning: Exclusion constraint is not suitable yet!
* @author margaretha
* */
public class SpanMultipleDistanceQuery extends SimpleSpanQuery{
@@ -71,8 +72,8 @@
sb.append(":");
sb.append(c.getMaxDistance());
sb.append("], ");
- sb.append( isOrdered ? "ordered, " : "notOrdered, " );
- sb.append( c.isExclusion() ? "excluded)]" : "notExcluded)");
+ sb.append(isOrdered ? "ordered, " : "notOrdered, ");
+ sb.append(c.isExclusion() ? "excluded)]" : "notExcluded)");
if (i < size-1) sb.append(", ");
}
sb.append("])");
@@ -92,6 +93,7 @@
SpanDistanceQuery sdq,sdq2;
Spans ds,ds2;
MultipleDistanceSpans mds = null;
+ boolean exclusion;
c = constraints.get(0);
sdq = createSpanDistanceQuery(c);
@@ -100,9 +102,10 @@
for (int i=1; i< constraints.size(); i++){
sdq2 = createSpanDistanceQuery(constraints.get(i));
ds2 = sdq2.getSpans(context, acceptDocs, termContexts);
-
+
+ exclusion = sdq.isExclusion() && sdq2.isExclusion();
mds = new MultipleDistanceSpans(this, context, acceptDocs,
- termContexts, ds, ds2, isOrdered);
+ termContexts, ds, ds2, isOrdered, exclusion);
ds = mds;
}
@@ -113,16 +116,19 @@
* @return a SpanDistanceQuery
* */
private SpanDistanceQuery createSpanDistanceQuery(DistanceConstraint c) {
-
+ SpanDistanceQuery sdq;
if (c.getUnit().equals("w")){
- return new SpanDistanceQuery(firstClause, secondClause,
+ sdq = new SpanDistanceQuery(firstClause, secondClause,
c.getMinDistance(), c.getMaxDistance(),isOrdered,
- collectPayloads);
+ collectPayloads);
}
-
- return new SpanDistanceQuery(c.getElementQuery(), firstClause,
- secondClause, c.getMinDistance(), c.getMaxDistance(),
- isOrdered, collectPayloads);
+ else {
+ sdq = new SpanDistanceQuery(c.getElementQuery(), firstClause,
+ secondClause, c.getMinDistance(), c.getMaxDistance(),
+ isOrdered, collectPayloads);
+ }
+ sdq.setExclusion(c.isExclusion());
+ return sdq;
}
public List<DistanceConstraint> getConstraints() {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/DistanceExclusionSpan.java b/src/main/java/de/ids_mannheim/korap/query/spans/DistanceExclusionSpan.java
index 02102bb..cb83e5c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/DistanceExclusionSpan.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/DistanceExclusionSpan.java
@@ -56,17 +56,13 @@
// skip the secondSpan to the right side of the firstspan
while (hasMoreSecondSpans && secondSpans.doc() == firstSpans.doc() &&
- firstSpans.start() >= secondSpans.end()){
-
- if (isOrdered){
- hasMoreSecondSpans = secondSpans.next();
- }
- else if (calculateActualDistance() > maxDistance){
- hasMoreSecondSpans = secondSpans.next();
- }
+ firstSpans.start() >= secondSpans.end()){
+
// the firstspan is within maxDistance
- //if (!isOrdered && calculateActualDistance() <= maxDistance){
- else { break; }
+ if (!isOrdered && calculateActualDistance() <= maxDistance){
+ break;
+ }
+ hasMoreSecondSpans = secondSpans.next();
}
}
@@ -108,7 +104,7 @@
matchPayload.addAll(firstSpans.getPayload());
setMatchFirstSpan(new CandidateSpan(firstSpans));
- setMatchSecondSpan(new CandidateSpan(secondSpans));
+ //setMatchSecondSpan(new CandidateSpan(secondSpans));
log.trace("doc# {}, start {}, end {}",matchDocNumber,matchStartPosition,
matchEndPosition);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/DistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/DistanceSpans.java
index f2169df..5f8b553 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/DistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/DistanceSpans.java
@@ -25,11 +25,13 @@
protected CandidateSpan matchFirstSpan,matchSecondSpan;
protected Logger log = LoggerFactory.getLogger(DistanceSpans.class);
+ protected boolean exclusion; // because MultipleDistanceQuery doesn't have this property
public DistanceSpans(SpanDistanceQuery query,
AtomicReaderContext context, Bits acceptDocs,
Map<Term, TermContext> termContexts) throws IOException {
super(query, context, acceptDocs, termContexts);
+ exclusion = query.isExclusion();
}
public DistanceSpans(SpanMultipleDistanceQuery query,
@@ -85,4 +87,12 @@
this.matchSecondSpan = matchSecondSpan;
}
+ public boolean isExclusion() {
+ return exclusion;
+ }
+
+ public void setExclusion(boolean exclusion) {
+ this.exclusion = exclusion;
+ }
+
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/MultipleDistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/MultipleDistanceSpans.java
index 698b88f..b15e94d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/MultipleDistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/MultipleDistanceSpans.java
@@ -8,6 +8,7 @@
import org.apache.lucene.index.TermContext;
import org.apache.lucene.search.spans.Spans;
import org.apache.lucene.util.Bits;
+import org.hamcrest.core.IsInstanceOf;
import de.ids_mannheim.korap.query.SpanDistanceQuery;
import de.ids_mannheim.korap.query.SpanMultipleDistanceQuery;
@@ -15,6 +16,11 @@
/** Span enumeration of matches whose two sub-spans has exactly the same
* first and second sub-sub-spans. This class basically filters the span
* matches of its child spans.
+ *
+ * TODO: This doesn't accommodate distance constraint with exclusion
+ * Case 1: return the match from another non-exclusion constraint.
+ * Case 2: return only the first-span when all constraints are exclusions.
+ * Case 3: spans are not in the same doc
*
* @author margaretha
* */
@@ -23,30 +29,17 @@
private DistanceSpans x,y;
private boolean isOrdered;
- public MultipleDistanceSpans(SpanDistanceQuery query,
- AtomicReaderContext context, Bits acceptDocs,
- Map<Term, TermContext> termContexts,
- Spans firstSpans, Spans secondSpans, boolean isOrdered)
- throws IOException {
- super(query, context, acceptDocs, termContexts);
- init(firstSpans, secondSpans, isOrdered);
- }
-
public MultipleDistanceSpans(SpanMultipleDistanceQuery query,
AtomicReaderContext context, Bits acceptDocs,
- Map<Term, TermContext> termContexts,
- Spans firstSpans, Spans secondSpans, boolean isOrdered)
+ Map<Term, TermContext> termContexts, Spans firstSpans,
+ Spans secondSpans, boolean isOrdered, boolean exclusion)
throws IOException {
super(query, context, acceptDocs, termContexts);
- init(firstSpans, secondSpans, isOrdered);
- }
-
- private void init(Spans firstSpans, Spans secondSpans,
- boolean isOrdered) throws IOException{
- this.isOrdered =isOrdered;
+ this.isOrdered = isOrdered;
+ this.exclusion = exclusion;
x = (DistanceSpans) firstSpans;
y = (DistanceSpans) secondSpans;
- hasMoreSpans = x.next() && y.next();
+ hasMoreSpans = x.next() && y.next();
}
@Override
@@ -58,8 +51,7 @@
/** Find the next match.
* */
- protected boolean advance() throws IOException {
-
+ protected boolean advance() throws IOException {
while (hasMoreSpans && ensureSameDoc(x, y)){
if (findMatch()){
moveForward();
@@ -101,24 +93,42 @@
CandidateSpan yf = y.getMatchFirstSpan();
CandidateSpan ys = y.getMatchSecondSpan();
- if (xf.getStart() == yf.getStart() &&
+ if (x.isExclusion() || y.isExclusion()){
+ if (xf.getStart() == yf.getStart() && xf.getEnd() == yf.getEnd()){
+ if (x.isExclusion() && y.isExclusion()){
+ // set x or y doesnt matter
+ setMatchProperties(x,true);
+ }
+ else if (x.isExclusion()){
+ // set y, the usual match
+ setMatchProperties(y,true);
+ }
+ else { setMatchProperties(x,true); }
+ return true;
+ }
+ }
+ else if (xf.getStart() == yf.getStart() &&
xf.getEnd() == yf.getEnd() &&
xs.getStart() == ys.getStart() &&
xs.getEnd() == ys.getEnd()){
-
- matchStartPosition = x.start();
- matchEndPosition = x.end();
- matchDocNumber = x.doc();
- matchPayload = x.matchPayload;
-
- setMatchFirstSpan(x.getMatchFirstSpan());
- setMatchSecondSpan(x.getMatchSecondSpan());
- log.trace("doc# {}, start {}, end {}",matchDocNumber,
- matchStartPosition,matchEndPosition);
+ setMatchProperties(x,false);
return true;
}
return false;
}
+
+
+ private void setMatchProperties(DistanceSpans span, boolean exclusion) {
+ matchStartPosition = span.start();
+ matchEndPosition = span.end();
+ matchDocNumber = span.doc();
+ matchPayload = span.matchPayload;
+
+ setMatchFirstSpan(span.getMatchFirstSpan());
+ if (!exclusion) setMatchSecondSpan(span.getMatchSecondSpan());
+ log.trace("doc# {}, start {}, end {}",matchDocNumber,
+ matchStartPosition,matchEndPosition);
+ }
@Override
public boolean skipTo(int target) throws IOException {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java
index ef29174..9c56fbd 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java
@@ -108,7 +108,9 @@
}
log.trace("doc# {}, start {}, end {}",matchDocNumber,matchStartPosition,
- matchEndPosition);
+ matchEndPosition);
+ System.out.println("firstspan "+getMatchFirstSpan().getStart()+" "+ getMatchFirstSpan().getEnd());
+ System.out.println("secondspan "+getMatchSecondSpan().getStart()+" "+ getMatchSecondSpan().getEnd());
}
@Override
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 bb2208d..0bb22f2 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
@@ -92,7 +92,7 @@
public SpanSequenceQueryWrapper withConstraint (int min, int max) {
if (this.constraints == null)
this.constraints = new ArrayList<DistanceConstraint>(1);
- this.constraints.add(new DistanceConstraint(min, max, false));
+ this.constraints.add(new DistanceConstraint(min, max,false));
return this;
};
@@ -100,12 +100,11 @@
if (this.constraints == null)
this.constraints = new ArrayList<DistanceConstraint>(1);
if (unit.equals("w"))
- this.constraints.add(new DistanceConstraint(min, max, false));
+ this.constraints.add(new DistanceConstraint(min, max,false));
else
this.constraints.add(
new DistanceConstraint(
- new SpanElementQuery(this.field, unit), min, max, false
- )
+ new SpanElementQuery(this.field, unit), min, max,false)
);
return this;
};
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestClassIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestClassIndex.java
index a99ce8a..6229ce1 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestClassIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestClassIndex.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.index;
+
import java.util.*;
import java.io.*;
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestDistanceExclusionIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestDistanceExclusionIndex.java
index 91bbed7..1ff0b64 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestDistanceExclusionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestDistanceExclusionIndex.java
@@ -138,7 +138,6 @@
sq.setExclusion(true);
return sq;
}
-
private FieldDocument createFieldDoc0(){
FieldDocument fd = new FieldDocument();
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestIndex.java
index b74ebc1..874695e 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestIndex.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.index;
+
import java.util.*;
import java.io.*;
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestKorapIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestKorapIndex.java
index 2200069..86eaf8d 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestKorapIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestKorapIndex.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.index;
+
import java.util.*;
import java.io.*;
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
index b556c6f..3596a73 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.index;
+
import java.util.*;
import java.io.*;
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
index 46f8f41..c1855da 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.index;
+
import java.util.*;
import java.io.*;
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java
index bcba704..c21ebb1 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java
@@ -36,13 +36,12 @@
return new SpanMultipleDistanceQuery(sx, sy, constraints, isOrdered, true);
}
- public DistanceConstraint createConstraint(String unit, int min, int max,
- boolean exclusion){
+ public DistanceConstraint createConstraint(String unit, int min, int max){
if (unit.equals("w")){
- return new DistanceConstraint(min, max, exclusion);
+ return new DistanceConstraint(min, max,false);
}
return new DistanceConstraint(new SpanElementQuery("base", unit),
- min, max, exclusion);
+ min, max,false);
}
private FieldDocument createFieldDoc0() {
@@ -102,7 +101,6 @@
return fd;
}
-
/** Unordered, same sentence
* */
@Test
@@ -112,8 +110,8 @@
ki.commit();
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
- constraints.add(createConstraint("w", 0, 2,false));
- constraints.add(createConstraint("s", 0, 0,false));
+ constraints.add(createConstraint("w", 0, 2));
+ constraints.add(createConstraint("s", 0, 0));
SpanQuery mdq;
mdq = createQuery("s:b", "s:c", constraints, false);
@@ -141,8 +139,8 @@
ki.commit();
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
- constraints.add(createConstraint("w", 0, 2,false));
- constraints.add(createConstraint("s", 1, 1,false));
+ constraints.add(createConstraint("w", 0, 2));
+ constraints.add(createConstraint("s", 1, 1));
SpanQuery mdq;
// Ordered
@@ -165,7 +163,7 @@
assertEquals(4, kr.getMatch(2).getEndPos());
// Three constraints
- constraints.add(createConstraint("p", 0, 0,false));
+ constraints.add(createConstraint("p", 0, 0));
mdq = createQuery("s:b", "s:c", constraints, true);
kr = ki.search(mdq, (short) 10);
assertEquals(2, kr.getTotalResults());
@@ -188,8 +186,8 @@
ki.commit();
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
- constraints.add(createConstraint("w", 1, 2, false));
- constraints.add(createConstraint("s", 1, 2, false));
+ constraints.add(createConstraint("w", 1, 2));
+ constraints.add(createConstraint("s", 1, 2));
SpanQuery mdq;
mdq = createQuery("s:b", "s:e", constraints, false);
@@ -218,8 +216,8 @@
ki.commit();
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
- constraints.add(createConstraint("w", 1, 2, false));
- constraints.add(createConstraint("s", 1, 2, false));
+ constraints.add(createConstraint("w", 1, 2));
+ constraints.add(createConstraint("s", 1, 2));
SpanQuery mdq;
mdq = createQuery("s:b", "s:c", constraints, false);
@@ -247,8 +245,8 @@
ki.commit();
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
- constraints.add(createConstraint("w", 1, 2, false));
- constraints.add(createConstraint("s", 1, 2, false));
+ constraints.add(createConstraint("w", 1, 2));
+ constraints.add(createConstraint("s", 1, 2));
SpanQuery mdq;
mdq = createQuery("s:c", "s:c", constraints, false);
@@ -267,75 +265,76 @@
}
- /** Gaps
- * TODO: exclusion is wrong, only need to match the first span,
- *
+ /** Exclusion
+ * Gaps
* */
@Test
public void testCase6() throws IOException {
ki = new KorapIndex();
ki.addDoc(createFieldDoc3());
- ki.commit();
-
+ ki.commit();
+
+ // First constraint - token exclusion
SpanQuery sx = new SpanTermQuery(new Term("base","s:b"));
SpanQuery sy = new SpanTermQuery(new Term("base","s:c"));
SpanDistanceQuery sq = new SpanDistanceQuery(sx, sy, 0, 1, false, true);
sq.setExclusion(true);
kr = ki.search(sq, (short) 10);
-
-// System.out.print(kr.getTotalResults()+"\n");
-// for (int i=0; i< kr.getTotalResults(); i++){
-// System.out.println(
-// kr.match(i).getLocalDocID()+" "+
-// kr.match(i).startPos + " " +
-// kr.match(i).endPos
-// );
-// }
+ assertEquals(1, kr.getTotalResults());
+ // 4-5
+ // Second constraint - element distance
sq = new SpanDistanceQuery(new SpanElementQuery("base", "s"), sx,
- sy, 1, 1, false, true);
-
- kr = ki.search(sq, (short) 10);
-
-// System.out.print(kr.getTotalResults()+"\n");
-// for (int i=0; i< kr.getTotalResults(); i++){
-// System.out.println(
-// kr.match(i).getLocalDocID()+" "+
-// kr.match(i).startPos + " " +
-// kr.match(i).endPos
-// );
-// }
+ sy, 1, 1, false, true);
+ kr = ki.search(sq, (short) 10);
+ // 0-3, 1-3, 1-4, 1-5, 3-7, 4-7
+ assertEquals(6, kr.getTotalResults());
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
- constraints.add(createConstraint("w", 0, 1, true));
- constraints.add(createConstraint("s", 1, 1, false));
-
+ constraints.add(new DistanceConstraint(0, 1,true));
+ constraints.add(createConstraint("s", 1, 1));
+
SpanQuery mdq;
mdq = createQuery("s:b", "s:c", constraints, false);
kr = ki.search(mdq, (short) 10);
-// System.out.print(kr.getTotalResults()+"\n");
-// for (int i=0; i< kr.getTotalResults(); i++){
-// System.out.println(
-// kr.match(i).getLocalDocID()+" "+
-// kr.match(i).startPos + " " +
-// kr.match(i).endPos
-// );
-// }
-
-// assertEquals(4, kr.getTotalResults());
-// assertEquals(0, kr.getMatch(0).getStartPos());
-// assertEquals(3, kr.getMatch(0).getEndPos());
-// assertEquals(1, kr.getMatch(1).getStartPos());
-// assertEquals(3, kr.getMatch(1).getEndPos());
-// assertEquals(1, kr.getMatch(2).getStartPos());
-// assertEquals(4, kr.getMatch(2).getEndPos());
-// assertEquals(3, kr.getMatch(3).getStartPos());
-// assertEquals(7, kr.getMatch(3).getEndPos());
-
-
- }
+ assertEquals(2, kr.getTotalResults());
+ assertEquals(1, kr.getMatch(0).getStartPos());
+ assertEquals(5, kr.getMatch(0).getEndPos());
+ assertEquals(4, kr.getMatch(1).getStartPos());
+ assertEquals(7, kr.getMatch(1).getEndPos());
+ }
+
+ /** Exclusion, multiple documents
+ * wait for element distance exclusion
+ * */
+/* @Test
+ public void testCase7() throws IOException {
+ ki = new KorapIndex();
+ //ki.addDoc(createFieldDoc3());
+ ki.addDoc(createFieldDoc0());
+ ki.addDoc(createFieldDoc2());
+ ki.commit();
+
+ List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
+ constraints.add(new DistanceConstraint(0, 1,true));
+ constraints.add(new DistanceConstraint(new SpanElementQuery("base", "s"),
+ 0, 0,true));
+
+ SpanQuery mdq;
+ mdq = createQuery("s:b", "s:c", constraints, false);
+ kr = ki.search(mdq, (short) 10);
+
+ System.out.print(kr.getTotalResults()+"\n");
+ for (int i=0; i< kr.getTotalResults(); i++){
+ System.out.println(
+ kr.match(i).getLocalDocID()+" "+
+ kr.match(i).startPos + " " +
+ kr.match(i).endPos
+ );
+ }
+ }*/
}
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java b/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java
index d656275..f096877 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.index;
+
import java.util.*;
import java.io.*;
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 c3c7443..3ac5a32 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.index;
+
import java.util.*;
import java.io.*;
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
index 13916cf..0cddcf9 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.index;
+
import java.util.*;
import java.io.*;
@@ -49,7 +51,7 @@
KorapQuery kq = new KorapQuery("base");
SpanQuery sq = kq.re("s:af*e").toQuery();
assertEquals("SpanMultiTermQueryWrapper(base:/s:af*e/)", sq.toString());
-
+
KorapSearch ks = new KorapSearch(sq);
ks.leftContext.setToken(true).setLength(1);
ks.rightContext.setToken(true).setLength(1);
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestTermInfo.java b/src/test/java/de/ids_mannheim/korap/index/TestTermInfo.java
index b9f4014..28f5b2b 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestTermInfo.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestTermInfo.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.index;
+
import java.util.*;
import java.io.*;
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
index 8f40a7f..be963c1 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.index;
+
import java.util.*;
import java.io.*;
@@ -946,4 +948,28 @@
assertEquals("totalResults", 0, kr.totalResults());
};
+
+ /** SpanElementQueries
+ * */
+ @Test
+ public void indexExample8() throws IOException{
+ KorapIndex ki = new KorapIndex();
+ FieldDocument fd = new FieldDocument();
+ // <a>xx <e>hi j <e>hi j</e></e></a>
+ fd.addTV("base",
+ "xx hi j hi j",
+ "[(0-1)s:x|i:x|_0#0-1|<>:a#1-12$<i>8]" +
+ "[(1-2)s:x|i:x|_1#1-2]" +
+ "[(3-4)s:h|i:h|_2#3-4|<>:e#3-12$<i>8]" +
+ "[(4-5)s:i|i:i|_3#4-5]" +
+ "[(6-7)s:j|i:j|_4#6-7]" +
+ "[(8-9)s:h|i:h|_5#8-9|<>:e#8-9$<i>8]" +
+ "[(9-10)s:i|i:i|_6#9-10]" +
+ "[(11-12)s:j|i:j|_7#11-12]");
+ ki.addDoc(fd);
+
+
+ }
+
+
};