Search in sources :

Example 11 with SpanDistanceQuery

use of de.ids_mannheim.korap.query.SpanDistanceQuery in project Krill by KorAP.

the class TestClassFilterIndex method testDisjoint.

@Test
public void testDisjoint() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(TestReferenceIndex.createFieldDoc0());
    ki.commit();
    SpanElementQuery seq1 = new SpanElementQuery("tokens", "np");
    SpanElementQuery seq2 = new SpanElementQuery("tokens", "vp");
    SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
    SpanClassQuery scq2 = new SpanClassQuery(seq2, (byte) 2);
    SpanDistanceQuery sdq = new SpanDistanceQuery(scq1, scq2, new DistanceConstraint(0, 1, false, false), true);
    // kr = ki.search(sdq, (short) 10);
    // for (Match km : kr.getMatches()) {
    // System.out.println(km.getStartPos() + "," + km.getEndPos()
    // + " "
    // + km.getSnippetBrackets());
    // }
    SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq, ClassOperation.DISJOINT, 2, 1, true);
    kr = ki.search(sq, (short) 10);
    // for (Match km : kr.getMatches()) {
    // System.out.println(km.getStartPos() + "," + km.getEndPos()
    // + " "
    // + km.getSnippetBrackets());
    // }
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(5, kr.getMatch(0).getEndPos());
    assertEquals("[[{1:Frankenstein}, {2:treat my daughter well}]]. She is the one that saved ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals(1, kr.getMatch(1).getStartPos());
    assertEquals(6, kr.getMatch(1).getEndPos());
    assertEquals("Frankenstein, [[{2:treat my daughter well}. {1:She}]] is the one that saved your ...", kr.getMatch(1).getSnippetBrackets());
    assertEquals(5, kr.getMatch(2).getStartPos());
    assertEquals(18, kr.getMatch(2).getEndPos());
    assertEquals("Frankenstein, treat my daughter well. [[{1:She} {2:is the one that saved your master who you hold so dear}]].", kr.getMatch(2).getSnippetBrackets());
}
Also used : SpanClassFilterQuery(de.ids_mannheim.korap.query.SpanClassFilterQuery) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) Test(org.junit.Test)

Example 12 with SpanDistanceQuery

use of de.ids_mannheim.korap.query.SpanDistanceQuery in project Krill by KorAP.

the class TestClassFilterIndex method testMultipleSameClasses.

@Test
public void testMultipleSameClasses() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(TestReferenceIndex.createFieldDoc0());
    ki.commit();
    SpanElementQuery seq1 = new SpanElementQuery("tokens", "nn");
    SpanElementQuery seq = new SpanElementQuery("tokens", "prp");
    SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
    SpanClassQuery scq = new SpanClassQuery(seq, (byte) 1);
    SpanDistanceQuery sdq = new SpanDistanceQuery(scq, scq1, new DistanceConstraint(3, 5, false, false), true);
    SpanElementQuery seq2 = new SpanElementQuery("tokens", "vp");
    SpanClassQuery scq2 = new SpanClassQuery(seq2, (byte) 2);
    SpanDistanceQuery sdq2 = new SpanDistanceQuery(sdq, scq2, new DistanceConstraint(0, 1, false, false), true);
    SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq2, ClassOperation.INCLUDE, 2, 1, true);
    kr = ki.search(sdq2, (short) 20);
    assertEquals(6, kr.getTotalResults());
    // for (Match km : kr.getMatches()) {
    // System.out.println(km.getStartPos() + "," + km.getEndPos()
    // + " "
    // + km.getSnippetBrackets());
    // }
    kr = ki.search(sq, (short) 20);
    // for (Match km : kr.getMatches()) {
    // System.out.println(km.getStartPos() + "," + km.getEndPos()
    // + " "
    // + km.getSnippetBrackets());
    // }
    assertEquals(6, kr.getMatch(0).getStartPos());
    assertEquals(18, kr.getMatch(0).getEndPos());
    assertEquals("Frankenstein, treat my daughter well. She [[{2:is the {1:one} that saved {1:your} master who you hold so dear}]].", kr.getMatch(0).getSnippetBrackets());
}
Also used : SpanClassFilterQuery(de.ids_mannheim.korap.query.SpanClassFilterQuery) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) Test(org.junit.Test)

Example 13 with SpanDistanceQuery

use of de.ids_mannheim.korap.query.SpanDistanceQuery in project Krill by KorAP.

the class TestElementDistanceExclusionIndex method createQuery.

private SpanQuery createQuery(String e, String x, String y, int min, int max, boolean isOrdered, boolean exclusion) {
    SpanElementQuery eq = new SpanElementQuery("base", e);
    SpanDistanceQuery sq = new SpanDistanceQuery(new SpanTermQuery(new Term("base", x)), new SpanTermQuery(new Term("base", y)), new DistanceConstraint(eq, min, max, isOrdered, exclusion), true);
    return sq;
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) Term(org.apache.lucene.index.Term) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery)

Example 14 with SpanDistanceQuery

use of de.ids_mannheim.korap.query.SpanDistanceQuery in project Krill by KorAP.

the class TestMultipleDistanceIndex method testCase7.

/**
 * Exclusion, multiple documents
 */
@Test
public void testCase7() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc2());
    ki.commit();
    SpanQuery sx = new SpanTermQuery(new Term("base", "s:b"));
    SpanQuery sy = new SpanTermQuery(new Term("base", "s:c"));
    // Second constraint
    SpanDistanceQuery sq = new SpanDistanceQuery(sx, sy, createConstraint("s", 0, 0, false, true), true);
    kr = ki.search(sq, (short) 10);
    assertEquals((long) 3, kr.getTotalResults());
    // 0-1, 1-2, 6-7
    // Exclusion within the same sentence
    List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
    constraints.add(createConstraint("w", 0, 2, false, true));
    constraints.add(createConstraint("s", 0, 0, false, true));
    SpanQuery mdq;
    mdq = createQuery("s:b", "s:c", constraints, false);
    kr = ki.search(mdq, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(1, kr.getMatch(0).getEndPos());
    assertEquals(6, kr.getMatch(1).getStartPos());
    assertEquals(7, kr.getMatch(1).getEndPos());
    // Third constraint
    sq = new SpanDistanceQuery(sx, sy, createConstraint("p", 0, 0, false, true), true);
    kr = ki.search(sq, (short) 10);
    assertEquals((long) 1, kr.getTotalResults());
    // 6-7
    constraints.add(createConstraint("p", 0, 0, false, true));
    mdq = createQuery("s:b", "s:c", constraints, false);
    kr = ki.search(mdq, (short) 10);
    assertEquals((long) 1, kr.getTotalResults());
    assertEquals(6, kr.getMatch(0).getStartPos());
    assertEquals(7, kr.getMatch(0).getEndPos());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) ArrayList(java.util.ArrayList) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 15 with SpanDistanceQuery

use of de.ids_mannheim.korap.query.SpanDistanceQuery in project Krill by KorAP.

the class TestMultipleDistanceIndex method testUnorderedTokenDistance.

@Test
public void testUnorderedTokenDistance() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc4());
    ki.commit();
    List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
    constraints.add(createConstraint("w", 0, 5, true, false));
    constraints.add(createConstraint("s", 0, 0, true, false));
    SpanQuery mdq;
    mdq = createQuery("s:Begin", "s:Moderator", constraints, false);
    kr = ki.search(mdq, (short) 10);
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(7, kr.getMatch(0).getEndPos());
    SpanQuery sq = new SpanDistanceQuery(mdq, new SpanTermQuery(new Term("base", "s:ruft")), new DistanceConstraint(0, 0, false, false), true);
    kr = ki.search(sq, (short) 10);
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(7, kr.getMatch(0).getEndPos());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) ArrayList(java.util.ArrayList) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Aggregations

SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)24 Test (org.junit.Test)21 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)19 KrillIndex (de.ids_mannheim.korap.KrillIndex)13 Term (org.apache.lucene.index.Term)13 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)12 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)11 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)9 SpanQuery (org.apache.lucene.search.spans.SpanQuery)8 SpanClassFilterQuery (de.ids_mannheim.korap.query.SpanClassFilterQuery)6 Krill (de.ids_mannheim.korap.Krill)4 SpanSubspanQuery (de.ids_mannheim.korap.query.SpanSubspanQuery)3 ArrayList (java.util.ArrayList)3 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)2 SpanMultipleDistanceQuery (de.ids_mannheim.korap.query.SpanMultipleDistanceQuery)2 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)2 SpanReferenceQuery (de.ids_mannheim.korap.query.SpanReferenceQuery)2 SpanRelationMatchQuery (de.ids_mannheim.korap.query.SpanRelationMatchQuery)2 SpanRelationQuery (de.ids_mannheim.korap.query.SpanRelationQuery)2 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)2