Search in sources :

Example 26 with SpanClassQuery

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

the class TestRegexIndex method testWildcardStarRewritten.

@Test
public void testWildcardStarRewritten() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.commit();
    // meine* /+w1:2,s0 &Erfahrung
    // rewritten into meine.*
    RegexpQuery wcquery = new RegexpQuery(new Term("tokens", "s:meine.*"));
    SpanMultiTermQueryWrapper<RegexpQuery> mtq = new SpanMultiTermQueryWrapper<RegexpQuery>(wcquery);
    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)

Example 27 with SpanClassQuery

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

the class TestRelationIndex method testCase6.

/**
 * Relation directions <br/>
 * Relation with specific sources, return the sources
 */
@Test
public void testCase6() throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();
    // return all children that are NP
    SpanElementQuery seq1 = new SpanElementQuery("base", "np");
    SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
    SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", ">:child-of")), true, RelationDirection.RIGHT);
    SpanRelationMatchQuery rm = new SpanRelationMatchQuery(srq, scq1, true);
    SpanFocusQuery rv = new SpanFocusQuery(rm, (byte) 1);
    rv.setSorted(false);
    assertEquals("focus(1: focus(#[1,2]spanSegment(spanRelation(base:>:child-of), {1: <base:np />})))", rv.toString());
    kr = ki.search(rv, (short) 10);
    assertEquals(4, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(1, kr.getMatch(0).getEndPos());
    assertEquals(2, kr.getMatch(1).getStartPos());
    assertEquals(4, kr.getMatch(1).getEndPos());
    assertEquals(2, kr.getMatch(2).getStartPos());
    assertEquals(7, kr.getMatch(2).getEndPos());
    assertEquals(5, kr.getMatch(3).getStartPos());
    assertEquals(7, kr.getMatch(3).getEndPos());
    // return all parents that are NP
    srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", "<:child-of")), true, RelationDirection.LEFT);
    rm = new SpanRelationMatchQuery(srq, scq1, true);
    rv = new SpanFocusQuery(rm, (byte) 1);
    kr = ki.search(rv, (short) 10);
    assertEquals(7, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(1, kr.getMatch(0).getEndPos());
    assertEquals(2, kr.getMatch(1).getStartPos());
    assertEquals(4, kr.getMatch(1).getEndPos());
    assertEquals(2, kr.getMatch(2).getStartPos());
    assertEquals(4, kr.getMatch(2).getEndPos());
    assertEquals(2, kr.getMatch(3).getStartPos());
    assertEquals(7, kr.getMatch(3).getEndPos());
    assertEquals(2, kr.getMatch(4).getStartPos());
    assertEquals(7, kr.getMatch(4).getEndPos());
    assertEquals(5, kr.getMatch(5).getStartPos());
    assertEquals(7, kr.getMatch(5).getEndPos());
    assertEquals(5, kr.getMatch(6).getStartPos());
    assertEquals(7, kr.getMatch(6).getEndPos());
}
Also used : SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) SpanRelationMatchQuery(de.ids_mannheim.korap.query.SpanRelationMatchQuery) Term(org.apache.lucene.index.Term) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) Test(org.junit.Test)

Example 28 with SpanClassQuery

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

the class TestRelationIndex method testCase9b.

@Test
public void testCase9b() throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();
    SpanTermWithIdQuery tiq = new SpanTermWithIdQuery(new Term("base", "pos:ART"), true);
    SpanClassQuery scq1 = new SpanClassQuery(tiq, (byte) 1);
    SpanElementQuery seq = new SpanElementQuery("base", "np");
    SpanClassQuery scq2 = new SpanClassQuery(seq, (byte) 2);
    SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", ">:child-of")), true, RelationDirection.RIGHT);
    srq.setSourceClass((byte) 1);
    srq.setTargetClass((byte) 2);
    SpanRelationMatchQuery rm = new SpanRelationMatchQuery(srq, scq1, scq2, true);
    // return all nps whose children are articles
    SpanFocusQuery rv = new SpanFocusQuery(rm, (byte) 2);
    rv.setSorted(false);
    kr = ki.search(rv, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(4, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(7, kr.getMatch(1).getEndPos());
// for (Match m : kr.getMatches()) {
// System.out.println(m.getStartPos() + " " + m.getEndPos());
// }
}
Also used : SpanTermWithIdQuery(de.ids_mannheim.korap.query.SpanTermWithIdQuery) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) SpanRelationMatchQuery(de.ids_mannheim.korap.query.SpanRelationMatchQuery) Term(org.apache.lucene.index.Term) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) Test(org.junit.Test)

Example 29 with SpanClassQuery

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

the class TestRelationIndex method testCase9c.

@Test
public void testCase9c() throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();
    SpanTermWithIdQuery tiq = new SpanTermWithIdQuery(new Term("base", "pos:ART"), true);
    SpanClassQuery scq1 = new SpanClassQuery(tiq, (byte) 1);
    kr = ki.search(scq1, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(3, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(6, kr.getMatch(1).getEndPos());
    SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", ">:child-of")), true, RelationDirection.RIGHT);
    srq.setSourceClass((byte) 1);
    srq.setTargetClass((byte) 2);
    // match articles as relation sources (left side)
    SpanSegmentQuery ssq1 = new SpanSegmentQuery(srq, scq1);
    // NOTE: SegmentSpans can only always adopt the relation left
    // side id.
    kr = ki.search(ssq1, (short) 10);
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(3, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(6, kr.getMatch(1).getEndPos());
    // return all parents of articles
    SpanFocusQuery sfq = new SpanFocusQuery(ssq1, (byte) 2);
    sfq.setSorted(false);
    kr = ki.search(sfq, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(4, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(7, kr.getMatch(1).getEndPos());
    SpanElementQuery seq = new SpanElementQuery("base", "np");
    SpanClassQuery scq2 = new SpanClassQuery(seq, (byte) 2);
    kr = ki.search(scq2, (short) 10);
    assertEquals((long) 4, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(1, kr.getMatch(0).getEndPos());
    assertEquals(2, kr.getMatch(1).getStartPos());
    assertEquals(4, kr.getMatch(1).getEndPos());
    assertEquals(2, kr.getMatch(2).getStartPos());
    assertEquals(7, kr.getMatch(2).getEndPos());
    assertEquals(5, kr.getMatch(3).getStartPos());
    assertEquals(7, kr.getMatch(3).getEndPos());
    // match nps as relation targets (right side)
    // return all nps whose children are articles
    SpanSegmentQuery ssq2 = new SpanSegmentQuery(sfq, scq2);
    kr = ki.search(ssq2, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(4, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(7, kr.getMatch(1).getEndPos());
    // NOTE: cannot match the span id of the embedded relation
    // target and the np. So the segment match here is only by
    // positions. All nps in the same position will be matches.
    // return the articles whos parents are nps
    SpanFocusQuery sfq2 = new SpanFocusQuery(ssq2, (byte) 1);
    sfq2.setSorted(false);
    assertEquals("focus(1: spanSegment(focus(2: spanSegment({1: source:" + "{2: target:spanRelation(base:>:child-of)}}, " + "{1: spanTermWithId(base:pos:ART)})), " + "{2: <base:np />}))", sfq2.toString());
    kr = ki.search(sfq2, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(3, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(6, kr.getMatch(1).getEndPos());
// for (Match m : kr.getMatches()) {
// System.out.println(m.getStartPos() + " " + m.getEndPos());
// }
}
Also used : SpanTermWithIdQuery(de.ids_mannheim.korap.query.SpanTermWithIdQuery) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) SpanSegmentQuery(de.ids_mannheim.korap.query.SpanSegmentQuery) Term(org.apache.lucene.index.Term) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) Test(org.junit.Test)

Example 30 with SpanClassQuery

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

the class TestRelationIndex method testCase7.

/**
 * Relation with specific sources, return any targets
 */
@Test
public void testCase7() throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();
    // match all children that are NP
    SpanElementQuery seq1 = new SpanElementQuery("base", "np");
    SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
    SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", ">:child-of")), true, RelationDirection.RIGHT);
    srq.setTargetClass((byte) 2);
    SpanRelationMatchQuery rm = new SpanRelationMatchQuery(srq, scq1, true);
    // SpanQuery rv = new SpanFocusQuery(rm, (byte) 1);
    // return all parents of np
    SpanFocusQuery rv2 = new SpanFocusQuery(rm, (byte) 2);
    rv2.setSorted(false);
    assertEquals("focus(2: focus(#[1,2]spanSegment({2: target:spanRelation(base:>:child-of)}, {1: <base:np />})))", rv2.toString());
    kr = ki.search(rv2, (short) 10);
    assertEquals((long) 4, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(7, kr.getMatch(0).getEndPos());
    assertEquals(1, kr.getMatch(1).getStartPos());
    assertEquals(7, kr.getMatch(1).getEndPos());
    assertEquals(2, kr.getMatch(2).getStartPos());
    assertEquals(7, kr.getMatch(2).getEndPos());
    assertEquals(4, kr.getMatch(3).getStartPos());
    assertEquals(7, kr.getMatch(3).getEndPos());
// id problem (solved)
// return all parents of np that are PP
}
Also used : SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) SpanRelationMatchQuery(de.ids_mannheim.korap.query.SpanRelationMatchQuery) Term(org.apache.lucene.index.Term) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) 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