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());
}
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());
}
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;
}
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);
}
}
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());
}
Aggregations