use of de.ids_mannheim.korap.query.SpanDistanceQuery in project Krill by KorAP.
the class TestMultipleDistanceIndex method testCase6.
/**
* Exclusion
* Gaps
*/
@Test
public void testCase6() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc3());
ki.commit();
// First constraint - token exclusion
SpanQuery sx = new SpanTermQuery(new Term("base", "s:b"));
SpanQuery sy = new SpanTermQuery(new Term("base", "s:c"));
DistanceConstraint dc1 = createConstraint("w", 0, 1, false, true);
SpanDistanceQuery sq = new SpanDistanceQuery(sx, sy, dc1, true);
kr = ki.search(sq, (short) 10);
assertEquals((long) 1, kr.getTotalResults());
// 4-5
// Second constraint - element distance
DistanceConstraint dc2 = createConstraint("s", 1, 1, false, false);
sq = new SpanDistanceQuery(sx, sy, dc2, true);
kr = ki.search(sq, (short) 10);
// 0-3, 1-3, 1-4, 1-5, 3-7, 4-7
assertEquals((long) 6, kr.getTotalResults());
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
constraints.add(dc1);
constraints.add(dc2);
SpanQuery mdq;
mdq = createQuery("s:b", "s:c", constraints, false);
kr = ki.search(mdq, (short) 10);
assertEquals((long) 2, kr.getTotalResults());
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(5, kr.getMatch(0).getEndPos());
assertEquals(4, kr.getMatch(1).getStartPos());
assertEquals(7, kr.getMatch(1).getEndPos());
}
use of de.ids_mannheim.korap.query.SpanDistanceQuery 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.SpanDistanceQuery 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());
// }
}
use of de.ids_mannheim.korap.query.SpanDistanceQuery in project Krill by KorAP.
the class TestSubSpanIndex method testCase2.
@Test
public void testCase2() {
SpanDistanceQuery sdq = new SpanDistanceQuery(new SpanTermQuery(new Term("tokens", "tt/p:NN")), new SpanTermQuery(new Term("tokens", "tt/p:VAFIN")), new DistanceConstraint(5, 5, true, false), true);
// the subspan length is longer than the span length
SpanSubspanQuery ssq = new SpanSubspanQuery(sdq, 0, 7, true);
kr = ki.search(ssq, (short) 10);
assertEquals(35, kr.getMatch(0).getStartPos());
assertEquals(41, kr.getMatch(0).getEndPos());
assertEquals(179, kr.getMatch(1).getStartPos());
assertEquals(185, kr.getMatch(1).getEndPos());
// the subspan start is before the span start
ssq = new SpanSubspanQuery(sdq, -7, 4, true);
kr = ki.search(ssq, (short) 10);
assertEquals((long) 8, kr.getTotalResults());
assertEquals(35, kr.getMatch(0).getStartPos());
assertEquals(39, kr.getMatch(0).getEndPos());
assertEquals(179, kr.getMatch(1).getStartPos());
assertEquals(183, kr.getMatch(1).getEndPos());
}
use of de.ids_mannheim.korap.query.SpanDistanceQuery in project Krill by KorAP.
the class TestSubSpanIndex method testCase3.
// Length 0
@Test
public void testCase3() {
SpanDistanceQuery sdq = new SpanDistanceQuery(new SpanTermQuery(new Term("tokens", "tt/p:NN")), new SpanTermQuery(new Term("tokens", "tt/p:VAFIN")), new DistanceConstraint(5, 5, true, false), true);
SpanSubspanQuery ssq = new SpanSubspanQuery(sdq, 3, 0, true);
kr = ki.search(ssq, (short) 10);
assertEquals(38, kr.getMatch(0).getStartPos());
assertEquals(41, kr.getMatch(0).getEndPos());
assertEquals(182, kr.getMatch(1).getStartPos());
assertEquals(185, kr.getMatch(1).getEndPos());
ssq = new SpanSubspanQuery(sdq, -2, 0, true);
kr = ki.search(ssq, (short) 10);
assertEquals(39, kr.getMatch(0).getStartPos());
assertEquals(41, kr.getMatch(0).getEndPos());
assertEquals(183, kr.getMatch(1).getStartPos());
assertEquals(185, kr.getMatch(1).getEndPos());
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + km.getSnippetBrackets());
// }
}
Aggregations