use of de.ids_mannheim.korap.query.SpanReferenceQuery 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());
}
use of de.ids_mannheim.korap.query.SpanReferenceQuery in project Krill by KorAP.
the class TestReferenceIndex method testCase2.
@Test
public void testCase2() throws IOException, QueryException {
String filepath = getClass().getResource("/queries/reference/distance-reference.jsonld").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
// cat="vb" & cat="prp" & cat="nn" & #1 .{0,1} #2 & #1
// .{0,2} #3 & #3 -> #2
assertEquals("spanReference(focus(#[1,2]spanSegment({2: <tokens:prp />}, focus(#2: " + "spanSegment(spanRelation(tokens:>:stanford/d:tag), " + "focus(3: spanDistance(focus(1: spanDistance({1: <tokens:vb />}, " + "{2: <tokens:prp />}, [(w[1:2], notOrdered, notExcluded)])), " + "{3: <tokens:nn />}, [(w[1:3], notOrdered, notExcluded)]))))" + ")), 2)", sq.toString());
SpanElementQuery seq1 = new SpanElementQuery("tokens", "vb");
// new SpanTermQuery(new Term("tokens", "c:vb"));
SpanElementQuery seq2 = new SpanElementQuery("tokens", "prp");
// new SpanTermQuery(new Term("tokens", "c:prp"));
SpanElementQuery seq3 = new SpanElementQuery("tokens", "nn");
// new SpanTermQuery(new Term("tokens", "c:nn"));
SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
SpanClassQuery scq2 = new SpanClassQuery(seq2, (byte) 2);
SpanClassQuery scq3 = new SpanClassQuery(seq3, (byte) 3);
SpanDistanceQuery sdq1 = new SpanDistanceQuery(scq1, scq2, new DistanceConstraint(1, 2, false, false), true);
SpanFocusQuery sfq1 = new SpanFocusQuery(sdq1, (byte) 1);
SpanDistanceQuery sdq2 = new SpanDistanceQuery(sfq1, scq3, new DistanceConstraint(1, 3, false, false), true);
SpanFocusQuery sfq2 = new SpanFocusQuery(sdq2, (byte) 3);
// nn -> prp
SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("tokens", ">:stanford/d:tag")), true, RelationDirection.RIGHT);
SpanRelationMatchQuery rq = new SpanRelationMatchQuery(srq, sfq2, scq2, true);
SpanReferenceQuery ref = new SpanReferenceQuery(rq, (byte) 2, true);
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.commit();
kr = ki.search(ref, (short) 10);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + " "
// + km.getSnippetBrackets());
// }
assertEquals(sq.toString(), ref.toString());
assertEquals(2, kr.getMatch(0).getStartPos());
assertEquals(4, kr.getMatch(0).getEndPos());
assertEquals(5, kr.getMatch(1).getStartPos());
assertEquals(9, kr.getMatch(1).getEndPos());
assertEquals(11, kr.getMatch(2).getStartPos());
assertEquals(13, kr.getMatch(2).getEndPos());
// multiple references
SpanFocusQuery sfq3 = new SpanFocusQuery(ref, (byte) 1);
// vp -> nn
SpanRelationMatchQuery rq2 = new SpanRelationMatchQuery(srq, sfq3, scq3, true);
SpanReferenceQuery ref2 = new SpanReferenceQuery(rq2, (byte) 3, true);
kr = ki.search(ref2, (short) 10);
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(4, kr.getMatch(0).getEndPos());
assertEquals(10, kr.getMatch(1).getStartPos());
assertEquals(13, kr.getMatch(1).getEndPos());
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + " "
// + km.getSnippetBrackets());
// }
}
Aggregations