Search in sources :

Example 11 with SpanQueryWrapper

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());
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) SpanWithinQuery(de.ids_mannheim.korap.query.SpanWithinQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 12 with SpanQueryWrapper

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());
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 13 with SpanQueryWrapper

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());
}
Also used : SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 14 with SpanQueryWrapper

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());
}
Also used : SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 15 with SpanQueryWrapper

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());
}
Also used : SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Aggregations

SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)165 Test (org.junit.Test)150 SpanQuery (org.apache.lucene.search.spans.SpanQuery)65 KrillIndex (de.ids_mannheim.korap.KrillIndex)17 QueryException (de.ids_mannheim.korap.util.QueryException)14 KrillQuery (de.ids_mannheim.korap.KrillQuery)13 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)11 Result (de.ids_mannheim.korap.response.Result)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 Krill (de.ids_mannheim.korap.Krill)5 SpanRepetitionQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRepetitionQueryWrapper)3 TestSimple.getJsonString (de.ids_mannheim.korap.TestSimple.getJsonString)2 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)2 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)2 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)2 SpanAlterQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper)2 SpanRegexQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper)2 SpanSegmentQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper)2 Term (org.apache.lucene.index.Term)2 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)2