Search in sources :

Example 11 with SpanWithAttributeQuery

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

the class TestAttributeIndex method testcase9.

/**
 * Element with only not attributes
 *
 * @throws IOException
 */
@Test
public void testcase9() throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();
    SpanAttributeQuery saq = new SpanAttributeQuery(new SpanTermQuery(new Term("base", "@:class=book")), true, true);
    SpanQuery sq = new SpanWithAttributeQuery(new SpanElementQuery("base", "div"), saq, true);
    kr = ki.search(sq, (short) 10);
    assertEquals(4, kr.getTotalResults());
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(2, kr.getMatch(0).getEndPos());
    assertEquals(3, kr.getMatch(1).getStartPos());
    assertEquals(5, kr.getMatch(1).getEndPos());
    assertEquals(5, kr.getMatch(2).getStartPos());
    assertEquals(6, kr.getMatch(2).getEndPos());
    assertEquals(6, kr.getMatch(3).getStartPos());
    assertEquals(7, kr.getMatch(3).getEndPos());
    List<SpanQuery> sql = new ArrayList<>();
    sql.add(saq);
    sql.add(new SpanAttributeQuery(new SpanTermQuery(new Term("base", "@:class=header")), true, true));
    sq = new SpanWithAttributeQuery(new SpanElementQuery("base", "div"), sql, true);
    kr = ki.search(sq, (short) 10);
    assertEquals(1, kr.getTotalResults());
    assertEquals(3, kr.getMatch(0).getStartPos());
    assertEquals(5, kr.getMatch(0).getEndPos());
}
Also used : SpanAttributeQuery(de.ids_mannheim.korap.query.SpanAttributeQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanWithAttributeQuery(de.ids_mannheim.korap.query.SpanWithAttributeQuery) ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 12 with SpanWithAttributeQuery

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

the class TestAttributeIndex method testCase3.

/**
 * same attribute types referring to different element types
 */
@Test
public void testCase3() throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();
    List<SpanQuery> sql = new ArrayList<>();
    sql.add(new SpanAttributeQuery(new SpanTermQuery(new Term("base", "@:class=header")), true));
    sql.add(new SpanAttributeQuery(new SpanTermQuery(new Term("base", "@:class=book")), true, true));
    SpanQuery sq = new SpanWithAttributeQuery(new SpanElementQuery("base", "div"), sql, true);
    kr = ki.search(sq, (short) 10);
    assertEquals((long) 3, kr.getTotalResults());
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(2, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(6, kr.getMatch(1).getEndPos());
    assertEquals(6, kr.getMatch(2).getStartPos());
    assertEquals(7, kr.getMatch(2).getEndPos());
}
Also used : SpanAttributeQuery(de.ids_mannheim.korap.query.SpanAttributeQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) ArrayList(java.util.ArrayList) SpanWithAttributeQuery(de.ids_mannheim.korap.query.SpanWithAttributeQuery) Term(org.apache.lucene.index.Term) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 13 with SpanWithAttributeQuery

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

the class SpanWithAttributeQueryWrapper method createSpanWithSingleAttributeQuery.

private SpanWithAttributeQuery createSpanWithSingleAttributeQuery(SimpleSpanQuery withIdQuery) throws QueryException {
    SpanAttributeQuery attrQuery = createSpanAttributeQuery(this.attrQueryWrapper);
    if (attrQuery != null) {
        if (withIdQuery != null) {
            return new SpanWithAttributeQuery(withIdQuery, attrQuery, true);
        } else {
            return new SpanWithAttributeQuery(attrQuery, true);
        }
    }
    isNull = true;
    return null;
}
Also used : SpanAttributeQuery(de.ids_mannheim.korap.query.SpanAttributeQuery) SpanWithAttributeQuery(de.ids_mannheim.korap.query.SpanWithAttributeQuery)

Example 14 with SpanWithAttributeQuery

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

the class SpanWithAttributeQueryWrapper method createSpanWithAttributeListQuery.

private SpanWithAttributeQuery createSpanWithAttributeListQuery(SimpleSpanQuery withIdQuery) throws QueryException {
    List<SpanQuery> attrQueries = new ArrayList<SpanQuery>();
    SpanQuery attrQuery = null;
    for (SpanQueryWrapper sqw : queryWrapperList) {
        attrQuery = createSpanAttributeQuery(sqw);
        if (attrQuery == null) {
            isNull = true;
            return null;
        }
        attrQueries.add(attrQuery);
    }
    if (withIdQuery != null) {
        return new SpanWithAttributeQuery(withIdQuery, attrQueries, true);
    } else {
        return new SpanWithAttributeQuery(attrQueries, true);
    }
}
Also used : ArrayList(java.util.ArrayList) SpanWithAttributeQuery(de.ids_mannheim.korap.query.SpanWithAttributeQuery) SimpleSpanQuery(de.ids_mannheim.korap.query.SimpleSpanQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery)

Example 15 with SpanWithAttributeQuery

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

the class TestRelationIndex method testCase10a.

/**
 * Relation whose nodes have a specific attribute.
 */
@Test
public void testCase10a() throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();
    SpanAttributeQuery aq = new SpanAttributeQuery(new SpanTermQuery(new Term("base", "@:case=accusative")), true);
    kr = ki.search(aq, (short) 10);
    assertEquals((long) 3, kr.getTotalResults());
    SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", ">:child-of")), true, RelationDirection.RIGHT);
    srq.setSourceClass((byte) 1);
    srq.setTargetClass((byte) 2);
    kr = ki.search(srq, (short) 20);
    assertEquals((long) 13, kr.getTotalResults());
    // Matching relation source node with an attribute
    SpanFocusQuery sfq1 = new SpanFocusQuery(srq, (byte) 1);
    SpanWithAttributeQuery swaq = new SpanWithAttributeQuery(sfq1, aq, true);
    kr = ki.search(swaq, (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());
    // Returning relations whose source has a specific attribute
    SpanFocusQuery fqr = new SpanFocusQuery(swaq, srq.getTempClassNumbers());
    fqr.setMatchTemporaryClass(true);
    fqr.setRemoveTemporaryClasses(true);
    assertEquals("focus(#[1,2]spanRelationWithAttribute(focus(1: " + "{1: source:{2: target:spanRelation(base:>:child-of)}}), " + "spanAttribute(base:@:case=accusative)))", fqr.toString());
    kr = ki.search(fqr, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(7, kr.getMatch(0).getEndPos());
    assertEquals(4, kr.getMatch(1).getStartPos());
    assertEquals(7, kr.getMatch(1).getEndPos());
    // Matching relation target nodes with an attribute
    SpanFocusQuery sfq2 = new SpanFocusQuery(srq, (byte) 2);
    sfq2.setSorted(false);
    SpanWithAttributeQuery swaq2 = new SpanWithAttributeQuery(sfq2, aq, true);
    kr = ki.search(aq, (short) 20);
    // for (Match m : kr.getMatches()) {
    // System.out.println(m.getStartPos() + " " + m.getEndPos());
    // }
    kr = ki.search(swaq2, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(7, kr.getMatch(1).getEndPos());
    // Returning relations whose target has a specific attribute
    SpanFocusQuery fqr2 = new SpanFocusQuery(swaq2, srq.getTempClassNumbers());
    fqr2.setMatchTemporaryClass(true);
    fqr2.setRemoveTemporaryClasses(true);
    kr = ki.search(fqr2, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(7, kr.getMatch(0).getEndPos());
    assertEquals(5, kr.getMatch(1).getStartPos());
    assertEquals(7, kr.getMatch(1).getEndPos());
}
Also used : SpanAttributeQuery(de.ids_mannheim.korap.query.SpanAttributeQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) SpanWithAttributeQuery(de.ids_mannheim.korap.query.SpanWithAttributeQuery) Term(org.apache.lucene.index.Term) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) Test(org.junit.Test)

Aggregations

SpanWithAttributeQuery (de.ids_mannheim.korap.query.SpanWithAttributeQuery)16 SpanAttributeQuery (de.ids_mannheim.korap.query.SpanAttributeQuery)15 Term (org.apache.lucene.index.Term)14 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)14 Test (org.junit.Test)14 SpanQuery (org.apache.lucene.search.spans.SpanQuery)9 ArrayList (java.util.ArrayList)8 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)6 SpanRelationQuery (de.ids_mannheim.korap.query.SpanRelationQuery)5 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)4 SimpleSpanQuery (de.ids_mannheim.korap.query.SimpleSpanQuery)1 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)1 SpanRelationMatchQuery (de.ids_mannheim.korap.query.SpanRelationMatchQuery)1 SpanSegmentQuery (de.ids_mannheim.korap.query.SpanSegmentQuery)1