Search in sources :

Example 46 with SpanQueryWrapper

use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.

the class TestSpanRelationQueryJSON method testTypedRelationWithWrapTokenNodes.

@Test
public void testTypedRelationWithWrapTokenNodes() throws QueryException {
    // query = "corenlp/c=\"VP\" & corenlp/c=\"NP\" & #1 ->malt/d[func=\"PP\"] #2";
    String filepath = getClass().getResource("/queries/relation/typed-relation-with-wrap-token-nodes.json").getFile();
    SpanQueryWrapper sqwi = getJSONQuery(filepath);
    SpanQuery sq = sqwi.toQuery();
    assertEquals("focus(#[1,2]spanSegment(tokens:tt/p:VVINF, " + "focus(#2: spanSegment(" + "spanRelation(tokens:>:malt/d:KONJ), tokens:tt/p:KOUI))))", sq.toString());
}
Also used : SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 47 with SpanQueryWrapper

use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.

the class TestSampleIndex method testMultipleDistanceWithWildcards.

@Test
public void testMultipleDistanceWithWildcards() throws IOException, QueryException {
    WildcardQuery wcquery = new WildcardQuery(new Term("tokens", "s:meine*"));
    SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(wcquery);
    // meine* /+w1:2 &Erfahrung
    SpanQuery tdq = new SpanDistanceQuery(mtq, sq, TestMultipleDistanceIndex.createConstraint("w", 1, 2, true, false), true);
    kr = sample.search(tdq, (short) 10);
    assertEquals(4, kr.getMatches().size());
    assertEquals(107, kr.getMatch(0).getStartPos());
    assertEquals(109, kr.getMatch(0).getEndPos());
    assertEquals(132566, kr.getMatch(1).getStartPos());
    assertEquals(132569, kr.getMatch(1).getEndPos());
    assertEquals(161393, kr.getMatch(2).getStartPos());
    assertEquals(161396, kr.getMatch(2).getEndPos());
    assertEquals(10298, kr.getMatch(3).getStartPos());
    assertEquals(10301, kr.getMatch(3).getEndPos());
    // meine* /+s0 &Erfahrung
    SpanQuery edq = new SpanDistanceQuery(mtq, sq, TestMultipleDistanceIndex.createConstraint("tokens", "base/s:s", 0, 0, true, false), true);
    kr = sample.search(edq, (short) 20);
    assertEquals(18, kr.getMatches().size());
    // meine* /+w1:2,s0 &Erfahrung
    SpanQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
    kr = sample.search(mdsq, (short) 10);
    assertEquals(4, kr.getMatches().size());
    // check SpanQueryWrapper generated query
    SpanQueryWrapper sqwi = getJSONQuery(getClass().getResource("/queries/bugs/cosmas_wildcards.jsonld").getFile());
    SpanQuery jsq = sqwi.toQuery();
    assertEquals(mdsq.toString(), jsq.toString());
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) Term(org.apache.lucene.index.Term) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) SpanMultipleDistanceQuery(de.ids_mannheim.korap.query.SpanMultipleDistanceQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 48 with SpanQueryWrapper

use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.

the class TestSampleIndex method testWildcardsWithJson.

@Test
public void testWildcardsWithJson() throws IOException, QueryException {
    SpanQueryWrapper sqwi = getJSONQuery(getClass().getResource("/queries/bugs/cosmas_wildcards_all.jsonld").getFile());
    SpanQuery sq = sqwi.toQuery();
    kr = sample.search(sq, (short) 10);
    assertEquals(4, kr.getMatches().size());
    // test krill apply
    Krill krill = new Krill();
    krill.setSpanQuery(sq);
    krill.setIndex(sample);
    kr = krill.apply();
    assertEquals(4, kr.getMatches().size());
    // test krill deserialization
    String jsonString = getJsonString(getClass().getResource("/queries/bugs/cosmas_wildcards_all.jsonld").getFile());
    krill = new Krill();
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(jsonString);
    final KrillQuery kq = new KrillQuery("tokens");
    krill.setQuery(kq);
    SpanQueryWrapper qw = kq.fromKoral(jsonNode.get("query"));
    assertEquals(sqwi.toQuery(), qw.toQuery());
    krill.setSpanQuery(qw.toQuery());
    kr = krill.apply(sample);
    assertEquals(4, kr.getMatches().size());
}
Also used : Krill(de.ids_mannheim.korap.Krill) KrillQuery(de.ids_mannheim.korap.KrillQuery) JsonNode(com.fasterxml.jackson.databind.JsonNode) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) TestSimple.getJsonString(de.ids_mannheim.korap.TestSimple.getJsonString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 49 with SpanQueryWrapper

use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.

the class TestSpanSubspanQueryJSON method testNegativeEmbeddedSequenceWithClass.

@Test
public void testNegativeEmbeddedSequenceWithClass() throws QueryException {
    // submatch(0,1:{1:[base != Baum] dass})
    String filepath = getClass().getResource("/queries/submatch/embedded-negative-class-seq.jsonld").getFile();
    SpanQueryWrapper sqwi = getJSONQuery(filepath);
    SpanQuery sq = sqwi.toQuery();
    assertEquals("subspan({1: spanExpansion(tokens:s:dass, !tokens:l:Baum{1, 1}, left)}, 0, 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 50 with SpanQueryWrapper

use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.

the class TestSpanSubspanQueryJSON method testNegativeSequenceWithClass.

@Test
public void testNegativeSequenceWithClass() throws QueryException {
    // das {1:submatch(0,1:[base != Baum])}
    String filepath = getClass().getResource("/queries/submatch/negative-sequence-class.jsonld").getFile();
    SpanQueryWrapper sqwi = getJSONQuery(filepath);
    SpanQuery sq = sqwi.toQuery();
    assertEquals("focus(254: spanContain(<tokens:base/s:t />, {254: spanExpansion(tokens:s:das, !tokens:l:Baum{1, 1}, right, class:1)}))", 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