use of de.ids_mannheim.korap.query.SpanRelationQuery in project Krill by KorAP.
the class TestRelationIndex method testRelationMissingPayloads.
@Test
public void testRelationMissingPayloads() throws IOException {
ki.addDoc(createFieldDoc4());
ki.commit();
SpanRelationQuery sq = new SpanRelationQuery(new SpanTermQuery(new Term("base", ">:dep")), true, RelationDirection.RIGHT);
kr = ki.search(sq, (short) 10);
assertEquals((long) 1, kr.getTotalResults());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(0, kr.getMatch(0).getEndPos());
SpanFocusQuery fq = new SpanFocusQuery(sq, sq.getTempClassNumbers());
fq.setMatchTemporaryClass(true);
fq.setRemoveTemporaryClasses(true);
fq.setSorted(false);
kr = ki.search(fq, (short) 20);
assertEquals((long) 1, kr.getTotalResults());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
}
use of de.ids_mannheim.korap.query.SpanRelationQuery in project Krill by KorAP.
the class TestRelationIndex method testCase5.
/**
* Dependency relations with attribute
*/
@Test
public void testCase5() throws IOException {
ki.addDoc(createFieldDoc2());
ki.commit();
// target of a dependency relation
SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", "<:dep")), true, RelationDirection.LEFT);
kr = ki.search(srq, (short) 10);
assertEquals((long) 6, kr.getTotalResults());
SpanFocusQuery fq = new SpanFocusQuery(srq, srq.getTempClassNumbers());
fq.setMatchTemporaryClass(true);
fq.setRemoveTemporaryClasses(true);
// fq.setSorted(false);
kr = ki.search(fq, (short) 10);
assertEquals((long) 6, kr.getTotalResults());
SpanAttributeQuery aq = new SpanAttributeQuery(new SpanTermQuery(new Term("base", "@:func=head")), true);
kr = ki.search(aq, (short) 10);
// dependency relation, which is also a head
SpanWithAttributeQuery wq = new SpanWithAttributeQuery(fq, aq, true);
kr = ki.search(wq, (short) 20);
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 TestFocusIndex method testCase12.
/**
* Check Skipto focus spans
*/
@Test
public void testCase12() throws IOException {
ki.addDoc(TestRelationIndex.createFieldDoc0());
ki.addDoc(TestRelationIndex.createFieldDoc1());
ki.commit();
SpanRelationQuery sq = new SpanRelationQuery(new SpanTermQuery(new Term("base", ">:xip/syntax-dep_rel")), true, RelationDirection.RIGHT);
sq.setSourceClass((byte) 1);
SpanFocusQuery sfq = new SpanFocusQuery(sq, (byte) 1);
sfq.setSorted(false);
SpanTermQuery stq = new SpanTermQuery(new Term("base", "s:c"));
SpanNextQuery snq = new SpanNextQuery(stq, sfq);
kr = ki.search(snq, (short) 20);
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
assertEquals(5, kr.getMatch(1).getStartPos());
assertEquals(9, kr.getMatch(1).getEndPos());
// for (Match m : kr.getMatches()) {
// System.out.println(m.getStartPos() + " " + m.getEndPos());
// }
}
use of de.ids_mannheim.korap.query.SpanRelationQuery in project Krill by KorAP.
the class SpanRelationWrapper method toFragmentQuery.
@Override
public SpanQuery toFragmentQuery() throws QueryException {
if (this.isNull() || this.isEmpty()) {
return null;
}
SpanQuery relationTermQuery = relationQuery.retrieveNode(this.retrieveNode).toFragmentQuery();
// .retrieveNode(this.retrieveNode).toFragmentQuery();
if (relationTermQuery == null)
return null;
SpanRelationQuery rq = new SpanRelationQuery(relationTermQuery, true, direction);
SpanQuery subq1, subq2;
if (subQuery1.isEmpty) {
if (!subQuery2.isEmpty) {
// match target
subq2 = subQuery2.retrieveNode(this.retrieveNode).toFragmentQuery();
if (subQuery1.hasClass) {
rq.setSourceClass(subQuery1.getClassNumber());
}
return new SpanRelationMatchQuery(rq, subq2, true);
}
} else if (subQuery2.isEmpty) {
if (!subQuery1.isEmpty) {
// match source
subq1 = subQuery1.retrieveNode(this.retrieveNode).toFragmentQuery();
if (subQuery2.hasClass) {
rq.setTargetClass(subQuery2.getClassNumber());
}
return new SpanRelationMatchQuery(rq, subq1, true);
}
} else {
// match both
subq1 = subQuery1.retrieveNode(this.retrieveNode).toFragmentQuery();
subq2 = subQuery2.retrieveNode(this.retrieveNode).toFragmentQuery();
return new SpanRelationMatchQuery(rq, subq1, subq2, true);
}
// both empty
if (subQuery1.hasClass) {
rq.setSourceClass(subQuery1.getClassNumber());
}
if (subQuery2.hasClass) {
rq.setTargetClass(subQuery2.getClassNumber());
}
SpanFocusQuery fq = new SpanFocusQuery(rq, rq.getTempClassNumbers());
fq.setMatchTemporaryClass(true);
fq.setRemoveTemporaryClasses(true);
fq.setSorted(false);
return fq;
}
use of de.ids_mannheim.korap.query.SpanRelationQuery 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());
}
Aggregations