Add tests for value vectors
Change-Id: Ie29c77b4bd36a590fe5b32b27967c2d816cf82c4
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java
index cb633ef..b2466dd 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java
@@ -993,6 +993,57 @@
}
+ @Test
+ public void testKrillCollectionWithValueVectorNe () throws IOException {
+ ki = new KrillIndex();
+ ki.addDoc(createDoc1()); // nachricht kultur reisen
+ ki.addDoc(createDoc2()); // kultur reisen
+ ki.addDoc(createDoc3()); // reisen finanzen
+ ki.commit();
+
+ KrillCollection kc = new KrillCollection();
+ kc.setIndex(ki);
+
+ CollectionBuilder cb = kc.build();
+ kc.fromBuilder(cb.orGroup().with(cb.term("textClass", "nachricht")).with(cb.term("textClass","finanzen")));
+ assertEquals("OrGroup(textClass:nachricht textClass:finanzen)", kc.toString());
+ assertEquals("Documents", 2, kc.numberOf("documents"));
+
+ kc.fromBuilder(cb.term("textClass", "nachricht").not());
+ assertEquals("-textClass:nachricht", kc.toString());
+ assertEquals("Documents", 2, kc.numberOf("documents"));
+
+ kc.fromBuilder(cb.orGroup().with(cb.term("textClass", "nachricht").not()).with(cb.term("textClass","finanzen").not()));
+ assertEquals("OrGroup(-textClass:nachricht -textClass:finanzen)", kc.toString());
+ assertEquals("Documents", 3, kc.numberOf("documents"));
+
+ kc.fromBuilder(cb.orGroup().with(cb.term("textClass", "nachricht")).with(cb.term("textClass","finanzen")).not());
+ assertEquals("-OrGroup(textClass:nachricht textClass:finanzen)", kc.toString());
+ assertEquals("Documents", 1, kc.numberOf("documents"));
+
+ Krill ks = new Krill(new QueryBuilder("tokens").seg("i:a"));
+ ks.setCollection(kc);
+
+ // Create a query
+ Result kr = ks.apply(ki);
+ assertEquals(1, kr.getTotalResults());
+ assertEquals("[[a]] c d", kr.getMatch(0).getSnippetBrackets());
+
+ String json = _getJSONString("collection_with_vector_ne.jsonld");
+ ks = new Krill(json);
+
+ kc = ks.getCollection();
+ kc.setIndex(ki);
+
+ assertEquals("-OrGroup(textClass:nachricht textClass:finanzen)", kc.toString());
+ assertEquals("Documents", 1, kc.numberOf("documents"));
+
+ kr = ks.apply(ki);
+ assertEquals("[[a]] c d", kr.getMatch(0).getSnippetBrackets());
+ assertEquals(1, kr.getTotalResults());
+ };
+
+
private FieldDocument createDoc1 () {
FieldDocument fd = new FieldDocument();
fd.addString("UID", "1");
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java
index ad69ffc..71f4038 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java
@@ -148,6 +148,21 @@
assertEquals("", kc.toString());
};
+ @Test
+ public void collectionWithValueVector () {
+ String metaQuery = _getJSONString("collection_with_vector.jsonld");
+ KrillCollection kc = new KrillCollection(metaQuery);
+ assertFalse(kc.hasErrors());
+ assertEquals("OrGroup(textSigle:aaa textSigle:bbb textSigle:ccc)", kc.toString());
+ };
+
+ @Test
+ public void collectionWithValueVectorNe () {
+ String metaQuery = _getJSONString("collection_with_vector_ne.jsonld");
+ KrillCollection kc = new KrillCollection(metaQuery);
+ assertFalse(kc.hasErrors());
+ assertEquals("-OrGroup(textClass:nachricht textClass:finanzen)", kc.toString());
+ };
@Test
public void collectionMirror () throws Exception {
diff --git a/src/test/resources/queries/collections/collection_with_vector.jsonld b/src/test/resources/queries/collections/collection_with_vector.jsonld
new file mode 100644
index 0000000..e34b852
--- /dev/null
+++ b/src/test/resources/queries/collections/collection_with_vector.jsonld
@@ -0,0 +1,20 @@
+{
+ "@context":"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld",
+ "query":{
+ "@type":"koral:token",
+ "wrap":{
+ "@type":"koral:term",
+ "layer":"orth",
+ "key":"der",
+ "match":"match:eq",
+ "foundry":"opennlp"
+ }
+ },
+ "collection":{
+ "key":"textSigle",
+ "match":"match:eq",
+ "type":"type:string",
+ "value":["aaa","bbb","ccc"],
+ "@type":"koral:doc"
+ }
+}
diff --git a/src/test/resources/queries/collections/collection_with_vector_ne.jsonld b/src/test/resources/queries/collections/collection_with_vector_ne.jsonld
new file mode 100644
index 0000000..94123a3
--- /dev/null
+++ b/src/test/resources/queries/collections/collection_with_vector_ne.jsonld
@@ -0,0 +1,23 @@
+{
+ "@context":"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld",
+ "query":{
+ "@type":"koral:token",
+ "wrap":{
+ "@type":"koral:term",
+ "layer":"orth",
+ "key":"a",
+ "match":"match:eq",
+ "foundry":"opennlp"
+ }
+ },
+ "collection":{
+ "key":"textClass",
+ "match":"match:ne",
+ "type":"type:string",
+ "value":["nachricht","finanzen"],
+ "@type":"koral:doc"
+ },
+ "meta":{
+ "cutOff":null
+ }
+}