use of de.ids_mannheim.korap.query.SpanRelationQuery in project Krill by KorAP.
the class TestRelationIndex method testCase8.
/**
* Relations whose source/target do not embed
* its counterparts.
*/
@Test
public void testCase8() throws IOException {
ki.addDoc(createFieldDoc2());
ki.commit();
// return source of dep relations to pos:NN
SpanTermWithIdQuery tq = new SpanTermWithIdQuery(new Term("base", "pos:NN"), true);
SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", "<:dep")), true, RelationDirection.LEFT);
srq.setSourceClass((byte) 1);
SpanRelationMatchQuery rm = new SpanRelationMatchQuery(srq, tq, true);
SpanQuery rv = new SpanFocusQuery(rm, (byte) 1);
kr = ki.search(rv, (short) 10);
assertEquals((long) 3, kr.getTotalResults());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(1, kr.getMatch(0).getEndPos());
assertEquals(1, kr.getMatch(1).getStartPos());
assertEquals(2, kr.getMatch(1).getEndPos());
assertEquals(4, kr.getMatch(2).getStartPos());
assertEquals(5, kr.getMatch(2).getEndPos());
// return target of dep relations from pos:NN
srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", ">:dep")), true, RelationDirection.RIGHT);
srq.setTargetClass((byte) 1);
rm = new SpanRelationMatchQuery(srq, tq, true);
rv = new SpanFocusQuery(rm, (byte) 1);
kr = ki.search(rv, (short) 10);
assertEquals((long) 3, kr.getTotalResults());
assertEquals(2, kr.getMatch(0).getStartPos());
assertEquals(3, kr.getMatch(0).getEndPos());
assertEquals(4, kr.getMatch(1).getStartPos());
assertEquals(5, kr.getMatch(1).getEndPos());
assertEquals(5, kr.getMatch(2).getStartPos());
assertEquals(6, kr.getMatch(2).getEndPos());
}
use of de.ids_mannheim.korap.query.SpanRelationQuery in project Krill by KorAP.
the class TestRelationIndex method testCase9.
/**
* Relation with specific sources and return any targets <br/>
* Relation with specific sources and targets, return the targets
* <br/>
* Relation with specific sources and targets, return the sources
*
* @throws IOException
*/
@Test
public void testCase9() throws IOException {
ki.addDoc(createFieldDoc2());
ki.commit();
// return all children of 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.LEFT);
srq.setSourceClass((byte) 2);
SpanRelationMatchQuery rm = new SpanRelationMatchQuery(srq, scq1, true);
SpanFocusQuery rv = new SpanFocusQuery(rm, (byte) 2);
rv.setSorted(false);
assertEquals("focus(2: focus(#[1,2]spanSegment({2: source:spanRelation(base:<:child-of)}, {1: <base:np />})))", rv.toString());
kr = ki.search(rv, (short) 10);
assertEquals((long) 7, kr.getTotalResults());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(1, kr.getMatch(0).getEndPos());
assertEquals(2, kr.getMatch(1).getStartPos());
assertEquals(3, kr.getMatch(1).getEndPos());
assertEquals(2, kr.getMatch(2).getStartPos());
assertEquals(4, kr.getMatch(2).getEndPos());
assertEquals(3, kr.getMatch(3).getStartPos());
assertEquals(4, kr.getMatch(3).getEndPos());
assertEquals(4, kr.getMatch(4).getStartPos());
assertEquals(7, kr.getMatch(4).getEndPos());
assertEquals(5, kr.getMatch(5).getStartPos());
assertEquals(6, kr.getMatch(5).getEndPos());
assertEquals(6, kr.getMatch(6).getStartPos());
assertEquals(7, kr.getMatch(6).getEndPos());
}
use of de.ids_mannheim.korap.query.SpanRelationQuery in project Krill by KorAP.
the class TestRelationIndex method testCase10b.
/**
* Relation whose nodes have a specific attribute. Alternative
* query (actually used in serialization)
*/
@Test
public void testCase10b() 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
SpanWithAttributeQuery swaq = new SpanWithAttributeQuery(aq, true);
SpanSegmentQuery ssq = new SpanSegmentQuery(srq, swaq);
assertEquals("spanSegment({1: source:{2: target:spanRelation(base:>:child-of)}}, " + "spanWithAttribute(spanAttribute(base:@:case=accusative)))", ssq.toString());
kr = ki.search(ssq, (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());
// Matching relation target nodes with an attribute
// NOTE: swaq must be the first parameter
SpanFocusQuery sfq2 = new SpanFocusQuery(srq, (byte) 2);
sfq2.setSorted(false);
SpanSegmentQuery ssq2 = new SpanSegmentQuery(swaq, sfq2);
kr = ki.search(ssq2, (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());
// Matching specific relation source node with an attribute
SpanElementQuery seq = new SpanElementQuery("base", "np");
swaq = new SpanWithAttributeQuery(seq, aq, true);
ssq = new SpanSegmentQuery(srq, swaq);
assertEquals("spanSegment({1: source:{2: target:spanRelation(base:>:child-of)}}, " + "spanElementWithAttribute(<base:np />, " + "spanAttribute(base:@:case=accusative)))", ssq.toString());
kr = ki.search(ssq, (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());
}
use of de.ids_mannheim.korap.query.SpanRelationQuery in project Krill by KorAP.
the class TestRelationIndex method testCase3.
/**
* Relations only
*/
@Test
public void testCase3() throws IOException {
ki.addDoc(createFieldDoc2());
ki.commit();
// child-of relations
SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", ">:child-of")), true, RelationDirection.RIGHT);
kr = ki.search(srq, (short) 20);
assertEquals((long) 13, kr.getTotalResults());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(1, kr.getMatch(0).getEndPos());
assertEquals(0, kr.getMatch(1).getStartPos());
assertEquals(1, kr.getMatch(1).getEndPos());
assertEquals(1, kr.getMatch(2).getStartPos());
assertEquals(2, kr.getMatch(2).getEndPos());
assertEquals(1, kr.getMatch(3).getStartPos());
assertEquals(7, kr.getMatch(3).getEndPos());
assertEquals(2, kr.getMatch(4).getStartPos());
assertEquals(3, kr.getMatch(4).getEndPos());
assertEquals(2, kr.getMatch(5).getStartPos());
assertEquals(4, kr.getMatch(5).getEndPos());
}
use of de.ids_mannheim.korap.query.SpanRelationQuery in project Krill by KorAP.
the class TestRelationIndex method testCase11.
/**
* Matching both relation nodes whose a specific attribute
*/
@Test
public void testCase11() 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());
SpanAttributeQuery aq2 = new SpanAttributeQuery(new SpanTermQuery(new Term("base", "@:case=accusative")), true);
kr = ki.search(aq2, (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());
SpanWithAttributeQuery swaq1 = new SpanWithAttributeQuery(aq, true);
SpanWithAttributeQuery swaq2 = new SpanWithAttributeQuery(aq2, true);
kr = ki.search(swaq1, (short) 10);
assertEquals((long) 3, kr.getTotalResults());
SpanRelationMatchQuery srmq = new SpanRelationMatchQuery(srq, swaq1, swaq2, true);
assertEquals("focus(#[1,2]spanSegment(spanWithAttribute(spanAttribute(base:@:case=accusative)), " + "focus(#2: spanSegment({1: source:{2: target:spanRelation(base:>:child-of)}}, " + "spanWithAttribute(spanAttribute(base:@:case=accusative))))))", srmq.toString());
kr = ki.search(srmq, (short) 10);
assertEquals((long) 1, kr.getTotalResults());
assertEquals(2, kr.getMatch(0).getStartPos());
assertEquals(7, kr.getMatch(0).getEndPos());
}
Aggregations