Collection bug fix, new server endpoint established
diff --git a/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollection.java b/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollection.java
index ba62e86..3fa1ea9 100644
--- a/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollection.java
+++ b/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollection.java
@@ -17,7 +17,6 @@
import static org.junit.Assert.*;
import org.junit.Test;
-import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -42,10 +41,11 @@
// Create Virtual collections:
KorapCollection kc = new KorapCollection(ki);
- // The virtual collection consists of all documents that have the textClass "reisen" and "freizeit"
-
assertEquals("Documents", 7, kc.numberOf("documents"));
+ // The virtual collection consists of all documents that have
+ // the textClass "reisen" and "freizeit"
+
kc.filter( kf.and("textClass", "reisen").and("textClass", "freizeit-unterhaltung") );
assertEquals("Documents", 5, kc.numberOf("documents"));
@@ -73,7 +73,6 @@
SpanQuery query = kq.seg("opennlp/p:NN").with("tt/p:NN").toQuery();
KorapResult kr = kc.search(query);
-
assertEquals(70, kr.totalResults());
kc.extend( kf.and("textClass", "uninteresting") );
@@ -96,7 +95,13 @@
// Construct index
KorapIndex ki = new KorapIndex();
// Indexing test files
- for (String i : new String[] {"00001", "00002", "00003", "00004", "00005", "00006", "02439"}) {
+ for (String i : new String[] {"00001",
+ "00002",
+ "00003",
+ "00004",
+ "00005",
+ "00006",
+ "02439"}) {
ki.addDocFile(
getClass().getResource("/wiki/" + i + ".json.gz").getFile(), true
);
@@ -110,17 +115,16 @@
assertEquals("Documents", 7, kc.numberOf("documents"));
- /*
- If this is set - everything is fine automatically ...
+ // If this is set - everything is fine automatically ...
kc.filter(kf.and("corpusID", "WPD"));
assertEquals("Documents", 7, kc.numberOf("documents"));
- */
+
// The virtual collection consists of all documents that have the textClass "reisen" and "freizeit"
+
kc.filter( kf.and("textClass", "reisen").and("textClass", "freizeit-unterhaltung") );
assertEquals("Documents", 5, kc.numberOf("documents"));
-
assertEquals("Tokens", 1678, kc.numberOf("tokens"));
assertEquals("Sentences", 194, kc.numberOf("sentences"));
assertEquals("Paragraphs", 139, kc.numberOf("paragraphs"));
@@ -133,6 +137,7 @@
assertEquals("Sentences", 75, kc.numberOf("sentences"));
assertEquals("Paragraphs", 48, kc.numberOf("paragraphs"));
+ // This is already filtered though ...
kc.filter(kf.and("corpusID", "WPD"));
assertEquals("Documents", 1, kc.numberOf("documents"));
@@ -153,12 +158,9 @@
kc.extend( kf.and("textClass", "wissenschaft") );
assertEquals("Documents", 3, kc.numberOf("documents"));
- /*
assertEquals("Tokens", 1669, kc.numberOf("tokens"));
assertEquals("Sentences", 188, kc.numberOf("sentences"));
assertEquals("Paragraphs", 130, kc.numberOf("paragraphs"));
- // System.err.println(kr.toJSON());
- */
};
@@ -169,7 +171,13 @@
// Construct index
KorapIndex ki = new KorapIndex();
// Indexing test files
- for (String i : new String[] {"00001", "00002", "00003", "00004", "00005", "00006", "02439"}) {
+ for (String i : new String[] {"00001",
+ "00002",
+ "00003",
+ "00004",
+ "00005",
+ "00006",
+ "02439"}) {
ki.addDocFile(
getClass().getResource("/wiki/" + i + ".json.gz").getFile(), true
);
@@ -197,8 +205,6 @@
assertEquals("Sentences", 40, kc.numberOf("sentences"));
assertEquals("Paragraphs", 2, kc.numberOf("paragraphs"));
- // assertEquals("Documents", 1, kc.numberOf("documents"));
-
// Create a query
KorapQuery kq = new KorapQuery("tokens");
SpanQuery query = kq.seg("opennlp/p:NN").with("tt/p:NN").toQuery();
@@ -232,23 +238,26 @@
};
ki.commit();
- assertEquals("Documents", 7, ki.numberOf("documents"));
- assertEquals("Sentences", 281, ki.numberOf("sentences"));
+ 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"));
KorapResult kr = ki.search(sq, (short) 10);
assertEquals(86,kr.getTotalResults());
// Create Virtual collections:
- KorapCollection kc = new KorapCollection(new String[]{"2", "3", "4"});
+ KorapCollection kc = new KorapCollection();
+ 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"));
+
kr = kc.search(sq);
assertEquals(39,kr.getTotalResults());
};
};
-
-
-
-// kc.filter( kf.and("textClass", "kultur").or("textClass", "wissenschaft") );
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
index c06592d..e4dccc4 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
@@ -363,6 +363,49 @@
assertEquals((short) 1, kr.getItemsPerResource());
};
+ @Test
+ public void searchJSONitemsPerResourceServer () throws IOException {
+
+ /*
+ * This test is a server-only implementation of
+ * TestResource#testCollection
+ */
+
+
+ // Construct index
+ KorapIndex ki = new KorapIndex();
+ // Indexing test files
+ int uid = 1;
+ for (String i : new String[] {"00001",
+ "00002",
+ "00003",
+ "00004",
+ "00005",
+ "00006",
+ "02439"}) {
+ ki.addDocFile(
+ uid++,
+ getClass().getResource("/wiki/" + i + ".json.gz").getFile(),
+ true
+ );
+ };
+ ki.commit();
+
+ String json = getString(getClass().getResource("/queries/bsp-uid-example.jsonld").getFile());
+
+ KorapSearch ks = new KorapSearch(json);
+ ks.setItemsPerResource(1);
+ KorapCollection kc = new KorapCollection();
+ kc.filterUIDs(new String[]{"1", "4"});
+ kc.setIndex(ki);
+ ks.setCollection(kc);
+
+ KorapResult kr = ks.run(ki);
+
+ assertEquals(2, kr.getTotalResults());
+ assertEquals(0, kr.getStartIndex());
+ assertEquals(25, kr.getItemsPerPage());
+ };
@Test
diff --git a/src/test/java/de/ids_mannheim/korap/server/DBTest.java b/src/test/java/de/ids_mannheim/korap/server/TestDatabase.java
similarity index 93%
rename from src/test/java/de/ids_mannheim/korap/server/DBTest.java
rename to src/test/java/de/ids_mannheim/korap/server/TestDatabase.java
index 11f3a23..04e7603 100644
--- a/src/test/java/de/ids_mannheim/korap/server/DBTest.java
+++ b/src/test/java/de/ids_mannheim/korap/server/TestDatabase.java
@@ -19,7 +19,7 @@
import org.junit.Test;
import static org.junit.Assert.assertEquals;
-public class DBTest {
+public class TestDatabase {
private Connection conn;
private Statement stat;
@@ -73,8 +73,8 @@
mc.add(9,10);
mc.add(16,90);
mc.commit();
- assertEquals(mc.getMatchCount(), 109);
- assertEquals(mc.getDocumentCount(), 4);
+ assertEquals(mc.getTotalResults(), 109);
+ assertEquals(mc.getTotalResultDocs(), 4);
};
@After
diff --git a/src/test/java/de/ids_mannheim/korap/server/ResourceTest.java b/src/test/java/de/ids_mannheim/korap/server/TestResource.java
similarity index 70%
rename from src/test/java/de/ids_mannheim/korap/server/ResourceTest.java
rename to src/test/java/de/ids_mannheim/korap/server/TestResource.java
index ee84419..08ae610 100644
--- a/src/test/java/de/ids_mannheim/korap/server/ResourceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/server/TestResource.java
@@ -4,6 +4,9 @@
http://harryjoy.com/2012/09/08/simple-rest-client-in-java/
*/
import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
@@ -12,18 +15,19 @@
import org.glassfish.grizzly.http.server.HttpServer;
+import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
import java.io.FileInputStream;
import de.ids_mannheim.korap.KorapNode;
+import de.ids_mannheim.korap.KorapResult;
import de.ids_mannheim.korap.server.KorapResponse;
import static de.ids_mannheim.korap.util.KorapString.*;
-public class ResourceTest {
+public class TestResource {
private HttpServer server;
private WebTarget target;
@@ -76,12 +80,8 @@
put(Entity.json(json), KorapResponse.class);
assertEquals(kresp.getNode(), "milena");
- /*
- assertNull(kresp.getErr());
- assertNull(kresp.getErrstr());
- */
+ assertEquals(kresp.getErr(), 0);
assertEquals(kresp.getUnstaged(), unstaged++);
- assertEquals(kresp.getVersion(), "0.42");
};
KorapResponse kresp = target.path("/index").
@@ -90,4 +90,38 @@
assertEquals(kresp.getNode(), "milena");
assertEquals(kresp.getMsg(), "Unstaged data was committed");
};
+
+ @Test
+ public void testCollection() throws IOException {
+
+ String json = getString(
+ getClass().getResource("/queries/bsp-uid-example.jsonld").getFile()
+ );
+
+ KorapResponse kresp
+ = target.path("/").
+ queryParam("uid", "1").
+ queryParam("uid", "4").
+ request("application/json").
+ post(Entity.json(json), KorapResponse.class);
+
+ assertEquals(2, kresp.getTotalResults());
+ assertEquals(0, kresp.getErr());
+ };
+
+ public static String getString (String path) {
+ StringBuilder contentBuilder = new StringBuilder();
+ try {
+ BufferedReader in = new BufferedReader(new FileReader(path));
+ String str;
+ while ((str = in.readLine()) != null) {
+ contentBuilder.append(str);
+ };
+ in.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ return contentBuilder.toString();
+ };
+
};
diff --git a/src/test/resources/queries/bsp-uid-example.jsonld b/src/test/resources/queries/bsp-uid-example.jsonld
new file mode 100644
index 0000000..72f1c53
--- /dev/null
+++ b/src/test/resources/queries/bsp-uid-example.jsonld
@@ -0,0 +1,13 @@
+{
+ "@context": "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+ "query": {
+ "@type": "korap:token",
+ "wrap": {
+ "@type": "korap:term",
+ "foundry": "mate",
+ "layer" : "lemma",
+ "key":"sein",
+ "match": "match:eq"
+ }
+ }
+}