use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class TestWithinIndex method queryJSONcomplexSpanOrTerm.
@Test
public void queryJSONcomplexSpanOrTerm() throws QueryException, IOException {
/*
at org.apache.lucene.search.spans.SpanOrQuery$1.doc(SpanOrQuery.java:234)
at de.ids_mannheim.korap.query.spans.WithinSpans.toSameDoc(WithinSpans.java:423)
at de.ids_mannheim.korap.query.spans.WithinSpans.next(WithinSpans.java:375)
at de.ids_mannheim.korap.KrillIndex.search(KrillIndex.java:1293)
at de.ids_mannheim.korap.Krill.apply(Krill.java:304)
*/
String jsonPath = URLDecoder.decode(getClass().getResource("/queries/bugs/span_or_bug.jsonld").getFile(), "UTF-8");
String jsonPQuery = readFile(jsonPath);
SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonPQuery);
SpanWithinQuery sq = (SpanWithinQuery) sqwi.toQuery();
assertEquals("spanStartsWith(<tokens:base/s:s />, " + "spanOr([tokens:s:Er, tokens:s:Sie]))", sq.toString());
KrillIndex ki = new KrillIndex();
ki.addDoc(getClass().getResourceAsStream("/wiki/DDD-08370.json.gz"), true);
ki.addDoc(getClass().getResourceAsStream("/wiki/SSS-09803.json.gz"), true);
ki.commit();
Result kr = ki.search(sq, (short) 1);
assertEquals(1, kr.getTotalResults());
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class TestWithinIndex method indexExample8.
/**
* SpanElementQueries
*/
@Test
public void indexExample8() throws QueryException, IOException {
KrillIndex ki = new KrillIndex();
FieldDocument fd = new FieldDocument();
// <a>xx <e>hi j <e>hi j</e></e></a>
fd.addTV("base", "xx hi j hi j", "[(0-1)s:x|i:x|_0$<i>0<i>1|<>:a$<b>64<i>0<i>12<i>8<b>0]" + "[(1-2)s:x|i:x|_1$<i>1<i>2]" + "[(3-4)s:h|i:h|_2$<i>3<i>4|<>:e$<b>64<i>3<i>12<i>8<b>0]" + "[(4-5)s:i|i:i|_3$<i>4<i>5]" + "[(6-7)s:j|i:j|_4$<i>6<i>7]" + "[(8-9)s:h|i:h|_5$<i>8<i>9|<>:e$<b>64<i>8<i>9<i>8<b>0]" + "[(9-10)s:i|i:i|_6$<i>9<i>10]" + "[(11-12)s:j|i:j|_7$<i>11<i>12]");
ki.addDoc(fd);
ki.commit();
assertEquals(1, ki.numberOf("documents"));
QueryBuilder qb = new KrillQuery("base").builder();
SpanQueryWrapper sqw;
Result kr;
/*
sqw = qb.seg("i:x");
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(2, kr.getTotalResults());
sqw = qb.tag("a");
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(1, kr.getTotalResults());
sqw = qb.startswith(qb.tag("a"), qb.seg("i:x"));
assertEquals("spanStartsWith(<base:a />, base:i:x)",
sqw.toQuery().toString());
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(1, kr.getTotalResults());
*/
sqw = qb.startswith(qb.tag("e"), qb.seg("i:h"));
assertEquals("spanStartsWith(<base:e />, base:i:h)", sqw.toQuery().toString());
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(2, kr.getTotalResults());
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class TestSpanReferenceQueryJSON method testDistanceReferences.
@Test
public void testDistanceReferences() throws QueryException {
// ND: I don't understand what this query should be about ...
// EM: There was just a bug with multiple distance
String filepath = getClass().getResource("/queries/reference/bug-multiple-distance-simple.jsonld").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
assertEquals("spanDistance(<tokens:c:vb />, <tokens:c:prp />, [(w[1:1], notOrdered, notExcluded)])", sq.toString());
// "/queries/reference/distance-reference.jsonld").getFile();
filepath = getClass().getResource("/queries/reference/bug-multiple-distance.jsonld").getFile();
sqwi = getJSONQuery(filepath);
sq = sqwi.toQuery();
// 'cat="VP" & cat="NP" & cat="PP" & #1 . #2 & #2 . #3 & #1 .
// #3 & #2 ->dep #1'
assertEquals("spanReference(focus(#[1,2]spanSegment({1: <tokens:c:prp />}, " + "focus(#2: spanSegment(spanRelation(tokens:>:stanford/d:tag), " + "focus(2: spanDistance(focus(1: spanDistance(<tokens:c:vb />, " + "{1: <tokens:c:prp />}, [(w[1:1], notOrdered, notExcluded)])), " + "{2: <tokens:c:nn />}, [(w[1:3], ordered, notExcluded)])))))), 1)", sq.toString());
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class TestSpanReferenceQueryJSON method testFirstOperandRef.
@Test
public void testFirstOperandRef() throws IOException, QueryException {
String filepath = getClass().getResource("/queries/reference/first-operand-reference.jsonld").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
// 'cat="V" & cat="NP" & cat="PP" & #2 . #1 & #1 ->dep #3 &
// #3 . #2
assertEquals("spanReference(spanNext({3: tokens:p:P}, " + "focus(2: focus(#[1,2]spanSegment({3: tokens:p:P}, " + "focus(#2: spanSegment(spanRelation(tokens:>:mate/d:HEAD), " + "focus(1: spanNext({2: tokens:p:V}, {1: <tokens:c:NP />})))))))), 3)", sq.toString());
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class TestSpanReferenceQueryJSON method testSecondOperandRef.
@Test
public void testSecondOperandRef() throws QueryException {
String filepath = getClass().getResource("/queries/reference/second-operand-reference.jsonld").getFile();
SpanQueryWrapper sqwi = getJSONQuery(filepath);
SpanQuery sq = sqwi.toQuery();
// 'cat="V" & cat="NP" & cat="PP" & #2 . #1 & #1 ->dep #3 &
// #2 . #3
assertEquals("spanReference(spanNext(focus(2: focus(#[1,2]spanSegment({3: tokens:p:P}, " + "focus(#2: spanSegment(spanRelation(tokens:>:mate/d:HEAD), " + "focus(1: spanNext({2: tokens:p:V}, {1: <tokens:c:NP />}))))))), " + "{3: tokens:p:P}), 3)", sq.toString());
}
Aggregations