Search in sources :

Example 21 with SpanClassQuery

use of de.ids_mannheim.korap.query.SpanClassQuery 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 22 with SpanClassQuery

use of de.ids_mannheim.korap.query.SpanClassQuery 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 23 with SpanClassQuery

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

the class TestReferenceIndex method testCase1.

@Test
public void testCase1() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(TestRelationIndex.createFieldDoc2());
    ki.commit();
    SpanTermQuery stq = new SpanTermQuery(new Term("base", "pos:V"));
    SpanElementQuery seq = new SpanElementQuery("base", "np");
    SpanClassQuery scq1 = new SpanClassQuery(stq, (byte) 1);
    SpanClassQuery scq2 = new SpanClassQuery(seq, (byte) 2);
    SpanNextQuery snq1 = new SpanNextQuery(scq1, scq2);
    SpanFocusQuery sfq1 = new SpanFocusQuery(snq1, (byte) 2);
    SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", "<:child-of")), true, RelationDirection.LEFT);
    SpanElementQuery seq2 = new SpanElementQuery("base", "pp");
    SpanClassQuery scq3 = new SpanClassQuery(seq2, (byte) 3);
    SpanRelationMatchQuery rq = new SpanRelationMatchQuery(srq, sfq1, scq3, true);
    // focus on np
    SpanFocusQuery sfq2 = new SpanFocusQuery(rq, (byte) 1);
    DistanceConstraint constraint = new DistanceConstraint(3, 3, true, false);
    SpanDistanceQuery sdq = new SpanDistanceQuery(sfq2, scq3, constraint, true);
    SpanReferenceQuery ref = new SpanReferenceQuery(sdq, (byte) 3, true);
    kr = ki.search(ref, (short) 10);
    /*
         * for (Match km : kr.getMatches()) {
         * 
         * System.out.println(km.getStartPos() + "," + km.getEndPos()
         * + " " + km.getSnippetBrackets()); }
         * System.out.println(kr.getTotalResults());
         */
    // cat=V & cat=np & cat=pp & #1 . #2 & #3 ->child-of #2 & #1 .{3,3} #3
    assertEquals("spanReference(spanDistance(focus(1: focus(#[1,2]spanSegment(" + "focus(#1: spanSegment(spanRelation(base:<:child-of), focus(2: spanNext(" + "{1: base:pos:V}, {2: <base:np />})))), {3: <base:pp />}))), " + "{3: <base:pp />}, [(w[3:3], ordered, notExcluded)]), 3)", ref.toString());
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(7, kr.getMatch(0).getEndPos());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) SpanRelationMatchQuery(de.ids_mannheim.korap.query.SpanRelationMatchQuery) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) Term(org.apache.lucene.index.Term) SpanReferenceQuery(de.ids_mannheim.korap.query.SpanReferenceQuery) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 24 with SpanClassQuery

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

the class TestReferenceIndex method testCase2.

@Test
public void testCase2() throws IOException, QueryException {
    String filepath = getClass().getResource("/queries/reference/distance-reference.jsonld").getFile();
    SpanQueryWrapper sqwi = getJSONQuery(filepath);
    SpanQuery sq = sqwi.toQuery();
    // cat="vb" & cat="prp" & cat="nn" & #1 .{0,1} #2 & #1
    // .{0,2} #3 & #3 -> #2
    assertEquals("spanReference(focus(#[1,2]spanSegment({2: <tokens:prp />}, focus(#2: " + "spanSegment(spanRelation(tokens:>:stanford/d:tag), " + "focus(3: spanDistance(focus(1: spanDistance({1: <tokens:vb />}, " + "{2: <tokens:prp />}, [(w[1:2], notOrdered, notExcluded)])), " + "{3: <tokens:nn />}, [(w[1:3], notOrdered, notExcluded)]))))" + ")), 2)", sq.toString());
    SpanElementQuery seq1 = new SpanElementQuery("tokens", "vb");
    // new SpanTermQuery(new Term("tokens", "c:vb"));
    SpanElementQuery seq2 = new SpanElementQuery("tokens", "prp");
    // new SpanTermQuery(new Term("tokens", "c:prp"));
    SpanElementQuery seq3 = new SpanElementQuery("tokens", "nn");
    // new SpanTermQuery(new Term("tokens", "c:nn"));
    SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
    SpanClassQuery scq2 = new SpanClassQuery(seq2, (byte) 2);
    SpanClassQuery scq3 = new SpanClassQuery(seq3, (byte) 3);
    SpanDistanceQuery sdq1 = new SpanDistanceQuery(scq1, scq2, new DistanceConstraint(1, 2, false, false), true);
    SpanFocusQuery sfq1 = new SpanFocusQuery(sdq1, (byte) 1);
    SpanDistanceQuery sdq2 = new SpanDistanceQuery(sfq1, scq3, new DistanceConstraint(1, 3, false, false), true);
    SpanFocusQuery sfq2 = new SpanFocusQuery(sdq2, (byte) 3);
    // nn -> prp
    SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("tokens", ">:stanford/d:tag")), true, RelationDirection.RIGHT);
    SpanRelationMatchQuery rq = new SpanRelationMatchQuery(srq, sfq2, scq2, true);
    SpanReferenceQuery ref = new SpanReferenceQuery(rq, (byte) 2, true);
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.commit();
    kr = ki.search(ref, (short) 10);
    // for (Match km : kr.getMatches()) {
    // System.out.println(km.getStartPos() + "," + km.getEndPos()
    // + " "
    // + km.getSnippetBrackets());
    // }
    assertEquals(sq.toString(), ref.toString());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(4, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(9, kr.getMatch(1).getEndPos());
    assertEquals(11, kr.getMatch(2).getStartPos());
    assertEquals(13, kr.getMatch(2).getEndPos());
    // multiple references
    SpanFocusQuery sfq3 = new SpanFocusQuery(ref, (byte) 1);
    // vp -> nn
    SpanRelationMatchQuery rq2 = new SpanRelationMatchQuery(srq, sfq3, scq3, true);
    SpanReferenceQuery ref2 = new SpanReferenceQuery(rq2, (byte) 3, true);
    kr = ki.search(ref2, (short) 10);
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(4, kr.getMatch(0).getEndPos());
    assertEquals(10, kr.getMatch(1).getStartPos());
    assertEquals(13, kr.getMatch(1).getEndPos());
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + " "
// + km.getSnippetBrackets());
// }
}
Also used : SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) Term(org.apache.lucene.index.Term) SpanReferenceQuery(de.ids_mannheim.korap.query.SpanReferenceQuery) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) SpanRelationMatchQuery(de.ids_mannheim.korap.query.SpanRelationMatchQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) Test(org.junit.Test)

Example 25 with SpanClassQuery

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

the class TestRegexIndex method testWildcardPlusRewritten.

@Test
public void testWildcardPlusRewritten() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.commit();
    // C2 meine+ /+w1:2,s0 &Erfahrung
    // meine+ rewritten into meine.?
    SpanMultiTermQueryWrapper<RegexpQuery> mtq = new SpanMultiTermQueryWrapper<RegexpQuery>(new RegexpQuery(new Term("tokens", "s:meine.?")));
    SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
    kr = ki.search(mdsq, (short) 10);
    assertEquals(4, kr.getMatches().size());
}
Also used : SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanMultipleDistanceQuery(de.ids_mannheim.korap.query.SpanMultipleDistanceQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) 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