use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestKrillCollectionIndex method testIndexWithNegation3.
@Test
public void testIndexWithNegation3() throws IOException {
// This is identical to above but the operands are switched
ki = new KrillIndex();
ki.addDoc(createDoc1());
ki.commit();
ki.addDoc(createDoc2());
ki.commit();
ki.addDoc(createDoc3());
ki.commit();
CollectionBuilder cb = new CollectionBuilder();
KrillCollection kcn = new KrillCollection(ki);
// orGroup with simple Negation
kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Peter")).with(cb.term("textClass", "kultur").not()));
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Sebastian")).with(cb.term("textClass", "kultur").not()));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.andGroup().with(cb.term("author", "Sebastian").not()).with(cb.term("author", "Frank").not()));
assertEquals("AndGroup(-author:Sebastian -author:Frank)", kcn.toString());
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.andGroup().with(cb.andGroup().with(cb.term("author", "Sebastian").not()).with(cb.term("author", "Frank").not())).with(cb.term("author", "Peter")));
assertEquals("AndGroup(AndGroup(-author:Sebastian -author:Frank) author:Peter)", kcn.toString());
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.andGroup().with(cb.andGroup().with(cb.term("author", "Sebastian").not()).with(cb.term("author", "Frank").not())).with(cb.re("textClass", "reis..")));
assertEquals("AndGroup(AndGroup(-author:Sebastian -author:Frank) QueryWrapperFilter(textClass:/reis../))", kcn.toString());
assertEquals(1, kcn.docCount());
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestKrillCollectionIndex method uidCollectionLegacy.
@Test
public void uidCollectionLegacy() throws IOException {
// Construct index
KrillIndex ki = new KrillIndex();
// Indexing test files
int uid = 1;
for (String i : new String[] { "00001", "00002", "00003", "00004", "00005", "00006", "02439" }) {
FieldDocument fd = ki.addDoc(uid++, getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), true);
}
;
ki.commit();
assertEquals("Documents", 7, ki.numberOf("documents"));
assertEquals("Paragraphs", 174, ki.numberOf("paragraphs"));
assertEquals("Sentences", 281, ki.numberOf("sentences"));
assertEquals("Tokens", 2661, ki.numberOf("tokens"));
SpanQuery sq = new SpanTermQuery(new Term("tokens", "s:der"));
Result kr = ki.search(sq, (short) 10);
assertEquals(86, kr.getTotalResults());
// Create Virtual collections:
KrillCollection kc = new KrillCollection();
kc.filterUIDs(new String[] { "2", "3", "4" });
kc.setIndex(ki);
assertEquals("Documents", 3, kc.numberOf("documents"));
assertEquals("Paragraphs", 46, kc.numberOf("paragraphs"));
assertEquals("Sentences", 103, kc.numberOf("sentences"));
assertEquals("Tokens", 1229, kc.numberOf("tokens"));
Krill ks = new Krill(sq);
ks.setCollection(kc).getMeta().setStartIndex(0).setCount((short) 20).setContext(new SearchContext(true, (short) 5, true, (short) 5));
kr = ks.apply(ki);
// kr = ki.search(kc, sq, 0, (short) 20, true, (short) 5, true, (short) 5);
assertEquals((long) 39, kr.getTotalResults());
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestKrillCollectionIndex method testKrillCollectionWithWrongJson.
@Test
public void testKrillCollectionWithWrongJson() throws IOException {
ki = new KrillIndex();
ki.addDoc(createDoc1());
ki.addDoc(createDoc2());
ki.addDoc(createDoc3());
ki.commit();
KrillCollection kc = new KrillCollection("{lalala}");
assertEquals("Unable to parse JSON", kc.getError(0).getMessage());
kc.setIndex(ki);
long docs = 0, tokens = 0, sentences = 0, paragraphs = 0;
try {
docs = kc.numberOf("documents");
tokens = kc.numberOf("tokens");
sentences = kc.numberOf("sentences");
paragraphs = kc.numberOf("paragraphs");
} catch (IOException e) {
e.printStackTrace();
}
assertEquals(0, docs);
assertEquals(0, tokens);
assertEquals(0, sentences);
assertEquals(0, paragraphs);
assertEquals(1, kc.getErrors().size());
assertEquals(StatusCodes.UNABLE_TO_PARSE_JSON, kc.getErrors().get(0).getCode());
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class Resource method _initResponse.
private Response _initResponse() {
Response kresp = new Response();
kresp.setNode(Node.getName());
kresp.setListener(Node.getListener());
// Get index
KrillIndex index = Node.getIndex();
if (index == null) {
kresp.addError(601, "Unable to find index");
return kresp;
}
;
kresp.setVersion(index.getVersion());
kresp.setName(index.getName());
return kresp;
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class Resource method match.
@GET
@Path("/match/{matchID}")
@Produces(MediaType.APPLICATION_JSON)
public String match(@PathParam("matchID") String id, @Context UriInfo uri) {
Response kresp = _initResponse();
if (kresp.hasErrors())
return kresp.toJsonString();
// Get index
KrillIndex index = Node.getIndex();
// Get query parameters
MultivaluedMap<String, String> qp = uri.getQueryParameters();
boolean includeSpans = false, includeHighlights = true, extendToSentence = false, info = false;
// Optional query parameter "info" for more information on the match
if (!_isNull(qp.getFirst("info")))
info = true;
// Optional query parameter "spans" for span information inclusion
if (!_isNull(qp.getFirst("spans"))) {
includeSpans = true;
info = true;
}
;
// Optional query parameter "highlights" for highlight information inclusion
String highlights = qp.getFirst("highlights");
if (highlights != null && _isNull(highlights))
includeHighlights = false;
// Optional query parameter "extended" for sentence expansion
if (!_isNull(qp.getFirst("extended")))
extendToSentence = true;
List<String> foundries = qp.get("foundry");
List<String> layers = qp.get("layer");
try {
// Get match info
return index.getMatchInfo(id, "tokens", info, foundries, layers, includeSpans, includeHighlights, extendToSentence).toJsonString();
}// Nothing found
catch (QueryException qe) {
// Todo: Make Match rely on Response!
kresp.addError(qe.getErrorCode(), qe.getMessage());
}
;
return kresp.toJsonString();
}
Aggregations