Search in sources :

Example 1 with SpanClassQuery

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

the class TestClassFilterIndex method testEqual.

// Problem with SpanDistanceQuery - unordered distance spans,
// -> unsorted
@Test
public void testEqual() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(TestReferenceIndex.createFieldDoc0());
    ki.commit();
    SpanElementQuery seq1 = new SpanElementQuery("tokens", "np");
    SpanElementQuery seq2 = new SpanElementQuery("tokens", "prp");
    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);
    assertEquals(6, kr.getTotalResults());
    kr = ki.search(scq2, (short) 10);
    // for (Match km : kr.getMatches()) {
    // System.out.println(km.getStartPos() + "," + km.getEndPos()
    // + " "
    // + km.getSnippetBrackets());
    // }
    SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq, ClassOperation.EQUAL, 2, 1, true);
    kr = ki.search(sq, (short) 10);
    assertEquals(5, kr.getMatch(0).getStartPos());
    assertEquals(6, kr.getMatch(0).getEndPos());
    assertEquals(14, kr.getMatch(1).getStartPos());
    assertEquals(15, kr.getMatch(1).getEndPos());
}
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 2 with SpanClassQuery

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

the class TestClassFilterIndex method testIntersect.

@Test
public void testIntersect() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(TestReferenceIndex.createFieldDoc0());
    ki.commit();
    SpanElementQuery seq1 = new SpanElementQuery("tokens", "np");
    SpanElementQuery seq2 = new SpanElementQuery("tokens", "vb");
    SpanClassQuery scq = new SpanClassQuery(seq2, (byte) 3);
    SpanDistanceQuery sdq = new SpanDistanceQuery(seq1, scq, new DistanceConstraint(0, 1, false, false), true);
    SpanClassQuery scq1 = new SpanClassQuery(sdq, (byte) 1);
    SpanElementQuery seq3 = new SpanElementQuery("tokens", "prp");
    SpanDistanceQuery sdq2 = new SpanDistanceQuery(seq3, seq2, new DistanceConstraint(0, 1, false, false), true);
    SpanClassQuery scq2 = new SpanClassQuery(sdq2, (byte) 2);
    SpanDistanceQuery sdq3 = new SpanDistanceQuery(scq1, scq2, new DistanceConstraint(0, 1, false, false), true);
    SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq3, ClassOperation.INTERSECT, 1, 2, true);
    assertEquals("spanClassFilter(spanDistance({1: spanDistance(<tokens:np />, " + "{3: <tokens:vb />}, [(w[0:1], notOrdered, notExcluded)])}, " + "{2: spanDistance(<tokens:prp />, <tokens:vb />, [(w[0:1], " + "notOrdered, notExcluded)])}, [(w[0:1], notOrdered, notExcluded)]),INTERSECT,1,2)", sq.toString());
    kr = ki.search(sq, (short) 20);
    // for (Match km : kr.getMatches()) {
    // System.out.println(km.getStartPos() + "," + km.getEndPos()
    // + " "
    // + km.getSnippetBrackets());
    // }
    assertEquals(13, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(3, kr.getMatch(0).getEndPos());
    assertEquals("[[{1:Frankenstein, {2:{3:treat}}}{2: my}]] daughter well. She is the one ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals(1, kr.getMatch(1).getStartPos());
    assertEquals(4, kr.getMatch(1).getEndPos());
    assertEquals("Frankenstein, [[{1:{2:{3:treat} my} daughter}]] well. She is the one that ...", kr.getMatch(1).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 3 with SpanClassQuery

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

the class TestClassFilterIndex method testInclude.

@Test
public void testInclude() 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);
    SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq, ClassOperation.INCLUDE, 2, 1, true);
    assertEquals(sq.toString(), "spanClassFilter(spanDistance({1: <tokens:np />}, {2: <tokens:vp />}, " + "[(w[0:1], notOrdered, notExcluded)]),INCLUDE,2,1)");
    kr = ki.search(sq, (short) 10);
    // for (Match km : kr.getMatches()) {
    // System.out.println(km.getStartPos() + "," + km.getEndPos()
    // + " "
    // + km.getSnippetBrackets());
    // }
    assertEquals(7, kr.getTotalResults());
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(5, kr.getMatch(0).getEndPos());
    assertEquals("Frankenstein, [[{2:treat {1:my daughter} well}]]. She is the one that saved ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals(6, kr.getMatch(1).getStartPos());
    assertEquals(18, kr.getMatch(1).getEndPos());
    assertEquals("Frankenstein, treat my daughter well. She [[{2:is {1:the one} that saved " + "your master who you hold so dear}]].", kr.getMatch(1).getSnippetBrackets());
    assertEquals("Frankenstein, treat my daughter well. She [[{2:is {1:the one that " + "saved your master who you hold so dear}}]].", kr.getMatch(2).getSnippetBrackets());
    assertEquals("Frankenstein, treat my daughter well. She [[{2:is the one that " + "saved {1:your master} who you hold so dear}]].", kr.getMatch(3).getSnippetBrackets());
    assertEquals("Frankenstein, treat my daughter well. She [[{2:is the one that saved your master who {1:you} hold so dear}]].", kr.getMatch(4).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 4 with SpanClassQuery

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

the class TestClassFilterIndex method testDiffer.

@Test
public void testDiffer() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(TestReferenceIndex.createFieldDoc0());
    ki.commit();
    SpanElementQuery seq1 = new SpanElementQuery("tokens", "np");
    SpanElementQuery seq2 = new SpanElementQuery("tokens", "prp");
    SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
    SpanClassQuery scq2 = new SpanClassQuery(seq2, (byte) 2);
    SpanDistanceQuery sdq = new SpanDistanceQuery(scq1, scq2, new DistanceConstraint(0, 2, false, false), true);
    SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq, ClassOperation.DIFFER, 1, 2, true);
    kr = ki.search(sq, (short) 20);
    // for (Match km : kr.getMatches()) {
    // System.out.println(km.getStartPos() + "," + km.getEndPos()
    // + " "
    // + km.getSnippetBrackets());
    // }
    assertEquals(9, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(3, kr.getMatch(0).getEndPos());
    assertEquals("[[{1:Frankenstein}, treat {2:my}]] daughter well. She is the one ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals(5, kr.getMatch(3).getStartPos());
    assertEquals(9, kr.getMatch(3).getEndPos());
    assertEquals("Frankenstein, treat my daughter well. [[{2:She} is {1:the one}]] that saved your master who you ...", kr.getMatch(3).getSnippetBrackets());
// she is both prp and np
}
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 5 with SpanClassQuery

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

the class TestMatchIndex method indexExampleFocusWithSpan.

@Test
public void indexExampleFocusWithSpan() throws IOException {
    KrillIndex ki = new KrillIndex();
    // abcabcabac
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2|<>:s$<b>64<i>1<i>5<i>5]" + "[(2-3)s:c|i:c|_2$<i>2<i>3|<>:s$<b>64<i>2<i>7<i>7]" + "[(3-4)s:a|i:a|_3$<i>3<i>4]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]" + "[(6-7)s:a|i:a|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:a|i:a|_8$<i>8<i>9]" + "[(9-10)s:c|i:c|_9$<i>9<i>10]");
    ki.addDoc(fd);
    ki.commit();
    SpanQuery sq;
    Result kr;
    // sq = new SpanWithinQuery(new SpanClassQuery(new SpanElementQuery(
    // "base", "s"), (byte) 2), new SpanClassQuery(new SpanTermQuery(
    // new Term("base", "s:b")), (byte) 3));
    // 
    // kr = ki.search(sq, (short) 10);
    // assertEquals(kr.getSerialQuery(),
    // "spanContain({2: <base:s />}, {3: base:s:b})");
    // assertEquals(kr.getMatch(0).getSnippetBrackets(),
    // "a[{2:{3:b}cab}]cabac");
    sq = new SpanFocusQuery(new SpanWithinQuery(new SpanClassQuery(new SpanElementQuery("base", "s"), (byte) 2), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 3)), (byte) 3);
    kr = ki.search(sq, (short) 10);
    assertEquals(kr.getSerialQuery(), "focus(3: spanContain({2: <base:s />}, {3: base:s:b}))");
    assertEquals(kr.getMatch(0).getSnippetBrackets(), "a[[{3:b}]]cabcab ...");
}
Also used : SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanWithinQuery(de.ids_mannheim.korap.query.SpanWithinQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Aggregations

SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)32 Test (org.junit.Test)30 Term (org.apache.lucene.index.Term)25 KrillIndex (de.ids_mannheim.korap.KrillIndex)24 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)16 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)15 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)14 SpanQuery (org.apache.lucene.search.spans.SpanQuery)14 SpanMultipleDistanceQuery (de.ids_mannheim.korap.query.SpanMultipleDistanceQuery)10 SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)10 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)9 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)8 Result (de.ids_mannheim.korap.response.Result)8 SpanRelationQuery (de.ids_mannheim.korap.query.SpanRelationQuery)7 SpanClassFilterQuery (de.ids_mannheim.korap.query.SpanClassFilterQuery)6 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)6 SpanRelationMatchQuery (de.ids_mannheim.korap.query.SpanRelationMatchQuery)6 WildcardQuery (org.apache.lucene.search.WildcardQuery)6 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)4 RegexpQuery (org.apache.lucene.search.RegexpQuery)4