Renamed to Krill
- Unfortunately I introduced 2 new failing Jersey tests
diff --git a/Changes b/Changes
index d8c8592..c54c996 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,10 @@
-0.49.4 2015-02-13
+0.50.1 2015-02-23
+ - Deserialization of arbitrary elements with attributes (margaretha)
+
+0.50 2015-02-23
+ - Project name is now "Krill"
+
+0.49.4 2015-02-20
- [documentation] Improved documentation for API classes,
improved test coverage for utility classes (diewald)
- [performance] Updated Lucene dependency from 4.5.1 to 4.10.3,
diff --git a/pom.xml b/pom.xml
index cdbbbd6..2659c86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
# install the indexer
$ mvn clean compile assembly:single
# Then run e.g.
- $ java -jar target/KorAP-lucene-index-X.XX.jar
+ $ java -jar target/Krill-X.XX.jar
src/main/resources/korap.conf
/data/hdd/lucene-new/WPD/
@@ -22,11 +22,11 @@
-->
<groupId>KorAP-modules</groupId>
- <artifactId>KorAP-lucene-index</artifactId>
- <version>0.49.4</version>
+ <artifactId>Krill</artifactId>
+ <version>0.50.1</version>
<packaging>jar</packaging>
- <name>KorAP-lucene-index</name>
+ <name>Krill</name>
<url>http://www.ids-mannheim.de/</url>
<organization>
@@ -148,9 +148,28 @@
</dependency>
<!-- JSON support in Jersey -->
+ <!--
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-moxy</artifactId>
+ </dependency>
<dependency>
- <groupId>org.glassfish.jersey.media</groupId>
- <artifactId>jersey-media-moxy</artifactId>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-json</artifactId>
+ <version>1.9</version>
+ </dependency>
+ -->
+ <!--
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ <version>2.16</version>
+ </dependency>
+ -->
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ <version>2.4.4</version>
</dependency>
<!-- JSON support using Jackson -->
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index 6f9130b..a800f54 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -835,7 +835,7 @@
log.trace("We've found a matching document");
HashSet<String> fields = (HashSet<String>)
- new KorapSearch().getFields().clone();
+ new Krill().getFields().clone();
fields.add(field);
// Get terms from the document
@@ -1076,13 +1076,13 @@
* Search in the index.
*/
public KorapResult search (SpanQuery query) {
- return this.search(new KorapSearch(query));
+ return this.search(new Krill(query));
};
public KorapResult search (SpanQuery query, short count) {
return this.search(
- new KorapSearch(query).setCount(count)
+ new Krill(query).setCount(count)
);
};
@@ -1096,7 +1096,7 @@
boolean rightTokenContext,
short rightContext) {
- KorapSearch ks = new KorapSearch(query);
+ Krill ks = new Krill(query);
ks.setStartIndex(startIndex).setCount(count);
ks.setContext(
new SearchContext(
@@ -1119,7 +1119,7 @@
short leftContext,
boolean rightTokenContext,
short rightContext) {
- KorapSearch ks = new KorapSearch(query);
+ Krill ks = new Krill(query);
ks.setContext(
new SearchContext(
leftTokenContext,
@@ -1136,7 +1136,7 @@
/**
* Search the endpoint.
*/
- public KorapResult search (KorapSearch ks) {
+ public KorapResult search (Krill ks) {
if (DEBUG)
log.trace("Start search");
@@ -1145,7 +1145,7 @@
KorapCollection collection = ks.getCollection();
collection.setIndex(this);
- // Get the spanquery from the KorapSearch object
+ // Get the spanquery from the Krill object
SpanQuery query = ks.getSpanQuery();
// Get the field of textual data and annotations ("tokens")
@@ -1376,7 +1376,7 @@
// Collect matches
- public MatchCollector collect (KorapSearch ks, MatchCollector mc) {
+ public MatchCollector collect (Krill ks, MatchCollector mc) {
if (DEBUG)
log.trace("Start collecting");
diff --git a/src/main/java/de/ids_mannheim/korap/KorapNode.java b/src/main/java/de/ids_mannheim/korap/KorapNode.java
index 8c34dd0..ddaab00 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapNode.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapNode.java
@@ -34,13 +34,13 @@
// Index
private static KorapIndex index;
private static ComboPooledDataSource cpds;
- private static String path;
- private static String name = "unknown";
+ private static String path,
+ name = "unknown";
private static String dbUser, dbPwd;
- private static String dbClass = "org.sqlite.JDBC";
- private static String dbURL = "jdbc:sqlite:";
+ private static String dbClass = "org.sqlite.JDBC",
+ dbURL = "jdbc:sqlite:";
/*
* Todo: Add shutdown hook,
@@ -50,7 +50,9 @@
*/
/**
- * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
+ * Starts Grizzly HTTP server exposing JAX-RS
+ * resources defined in this application.
+ *
* @return Grizzly HTTP server.
*/
public static HttpServer startServer() {
@@ -112,7 +114,7 @@
* @param args
* @throws IOException
*/
- public static void main(String[] args) throws IOException {
+ public static void main (String[] args) throws IOException {
// WADL available at BASE_URI + application.wadl
final HttpServer server = startServer();
diff --git a/src/main/java/de/ids_mannheim/korap/KorapQuery.java b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
index d2a1660..f3b499e 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
@@ -71,7 +71,8 @@
*/
public class KorapQuery extends Notifications {
private String field;
- private ObjectMapper json;
+ private ObjectMapper mapper;
+ private JsonNode json;
// Logger
private final static Logger log = LoggerFactory.getLogger(KorapQuery.class);
@@ -98,7 +99,7 @@
*/
public KorapQuery (String field) {
this.field = field;
- this.json = new ObjectMapper();
+ this.mapper = new ObjectMapper();
};
@@ -159,7 +160,7 @@
JsonNode jsonN;
try {
// Read Json string
- jsonN = this.json.readValue(json, JsonNode.class);
+ jsonN = this.mapper.readValue(json, JsonNode.class);
}
// Something went wrong
@@ -194,6 +195,9 @@
if (!json.has("@type"))
throw new QueryException(701, "JSON-LD group has no @type attribute");
+ // Set this for serialization
+ this.json = json;
+
// Get @type for branching
String type = json.get("@type").asText();
@@ -1078,8 +1082,17 @@
}
}
return null;
- }
+ };
+ public JsonNode toJsonNode () {
+ return this.json;
+ };
+
+ public String toJsonString () {
+ if (this.json == null)
+ return "{}";
+ return this.json.toString();
+ };
/*
diff --git a/src/main/java/de/ids_mannheim/korap/KorapResult.java b/src/main/java/de/ids_mannheim/korap/KorapResult.java
index 8f4c1dc..18c6cdd 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapResult.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapResult.java
@@ -19,7 +19,7 @@
import java.util.List;
/*
- TODO: Reuse the KorapSearch code for data serialization!
+ TODO: Reuse the Krill code for data serialization!
*/
/**
* Response class for search results.
@@ -31,7 +31,7 @@
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
-public class KorapResult extends KorapResponse {
+public class KorapResult extends Krill {
ObjectMapper mapper = new ObjectMapper();
@JsonIgnore
diff --git a/src/main/java/de/ids_mannheim/korap/KorapSearch.java b/src/main/java/de/ids_mannheim/korap/Krill.java
similarity index 71%
rename from src/main/java/de/ids_mannheim/korap/KorapSearch.java
rename to src/main/java/de/ids_mannheim/korap/Krill.java
index 1021bb0..c168f3b 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapSearch.java
+++ b/src/main/java/de/ids_mannheim/korap/Krill.java
@@ -10,11 +10,14 @@
import de.ids_mannheim.korap.KorapResult;
import de.ids_mannheim.korap.util.QueryException;
import de.ids_mannheim.korap.index.SearchContext;
-import de.ids_mannheim.korap.response.Notifications;
+import de.ids_mannheim.korap.response.KorapResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Krill is a corpus data retrieval index using Lucene for Look-Ups.
* It is the reference implementation for KoralQuery consumption.
@@ -33,17 +36,14 @@
/*
* Todo: Use a configuration file
* Todo: Let this class extend KorapResult!
- * KorapResult = new KorapSearch(String json).run(KorapIndex ki);
+ * KorapResult = new Krill(String json).run(KorapIndex ki);
* Todo: Set timeout default value per config file
*/
-
-public class KorapSearch extends Notifications {
+public class Krill extends KorapResponse {
private int startIndex = 0, limit = 0;
private short count = 25, countMax = 50, itemsPerResource = 0;
private boolean cutOff = false;
- private SpanQuery spanQuery;
-
private KorapCollection collection;
private KorapIndex index;
@@ -51,8 +51,9 @@
private long timeout = (long) 120_000;
private HashSet<String> fields;
- private HashSet<Integer> highlights;
+ HashSet<Integer> highlights;
+ private SpanQuery spanQuery;
private JsonNode request;
public SearchContext context;
@@ -60,12 +61,15 @@
private long timeoutStart = Long.MIN_VALUE;
+ // Logger
+ private final static Logger log = LoggerFactory.getLogger(Krill.class);
+
{
context = new SearchContext();
fields = new HashSet<String>(16);
- // Lift legacy fields per default
+ // LEGACY: Lift following fields per default
for (String field : new String[]{
"ID",
"UID",
@@ -87,11 +91,11 @@
highlights = new HashSet<Integer>(3);
};
-
+
/**
* Construct a new Krill object.
*/
- public KorapSearch () {};
+ public Krill () {};
/**
@@ -100,7 +104,7 @@
*
* @param query The {@link SpanQueryWrapper} object.
*/
- public KorapSearch (SpanQueryWrapper query) {
+ public Krill (SpanQueryWrapper query) {
try {
this.spanQuery = query.toQuery();
}
@@ -116,37 +120,72 @@
*
* @param query The {@link SpanQuery} object.
*/
- public KorapSearch (SpanQuery query) {
+ public Krill (SpanQuery query) {
this.spanQuery = query;
};
- public KorapSearch (String jsonString) {
- try {
- // Parse json string
- this.fromJson(jsonString);
- }
- catch (QueryException qe) {
- this.addError(qe.getErrorCode(), qe.getMessage());
- };
- };
-
- public KorapSearch (JsonNode json) {
- try {
- this.fromJson(json);
- }
- catch (QueryException qe) {
- this.addError(qe.getErrorCode(), qe.getMessage());
- };
+ /**
+ * Construct a new Krill object,
+ * consuming a KoralQuery json string.
+ *
+ * @param query The KoralQuery json string.
+ */
+ public Krill (String query) {
+ // Parse json string
+ this.fromJson(query);
};
- public KorapSearch fromJson (JsonNode json) throws QueryException {
+ /**
+ * Construct a new Krill object,
+ * consuming a KoralQuery {@link JsonNode} object.
+ *
+ * @param query The KoralQuery {@link JsonNode} object.
+ */
+ public Krill (JsonNode query) {
+ this.fromJson(query);
+ };
+
+
+ /**
+ * Parse KoralQuery as a json string.
+ *
+ * @param query The KoralQuery json string.
+ * @return The {@link Krill} object for chaining.
+ * @throws QueryException
+ */
+ public Krill fromJson (String query) {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ this.request = mapper.readTree(query);
+ this.fromJson(this.request);
+ }
+
+ // Unable to parse JSON
+ catch (IOException e) {
+ this.addError(621, "Unable to parse JSON");
+ };
+
+ return this;
+ };
+
+
+ /**
+ * Parse KoralQuery as a {@link JsonNode} object.
+ *
+ * @param query The KoralQuery {@link JsonNode} object.
+ * @return The {@link Krill} object for chaining.
+ * @throws QueryException
+ */
+ public Krill fromJson (JsonNode json) {
+
// Parse "query" attribute
if (json.has("query")) {
try {
KorapQuery kq = new KorapQuery("tokens");
SpanQueryWrapper qw = kq.fromJson(json.get("query"));
+ this.setQuery(kq);
// Unable to process result
if (qw.isEmpty())
@@ -166,8 +205,9 @@
this.addError(q.getErrorCode(), q.getMessage());
};
}
- else
+ else {
this.addError(700, "No query given");
+ };
// <legacycode>
if (json.has("warning") &&
@@ -189,22 +229,27 @@
this.copyNotificationsFrom(json);
// virtual collections
- if (json.has("collection")) {
- this.setCollection(
- new KorapCollection().fromJson(json.get("collection"))
- );
- }
+ try {
+ if (json.has("collection")) {
+ this.setCollection(
+ new KorapCollection().fromJson(json.get("collection"))
+ );
+ }
- // <legacycode>
- else if (json.has("collections")) {
- KorapCollection kc = new KorapCollection();
- for (JsonNode collection : json.get("collections")) {
- kc.fromJsonLegacy(collection);
+ // <legacycode>
+ else if (json.has("collections")) {
+ KorapCollection kc = new KorapCollection();
+ for (JsonNode collection : json.get("collections")) {
+ kc.fromJsonLegacy(collection);
+ };
+
+ this.setCollection(kc);
};
-
- this.setCollection(kc);
+ // </legacycode>
+ }
+ catch (QueryException q) {
+ this.addError(q.getErrorCode(), q.getMessage());
};
- // </legacycode>
// No errors
@@ -277,23 +322,6 @@
return this;
};
-
- public KorapSearch fromJson (String jsonString) throws QueryException {
- ObjectMapper mapper = new ObjectMapper();
- try {
- this.request = mapper.readTree(jsonString);
- this.fromJson(this.request);
- }
-
- // Unable to parse JSON
- catch (IOException e) {
- this.addError(621, "Unable to parse JSON");
- };
-
- return this;
- };
-
-
public long getTimeOut () {
return this.timeout;
};
@@ -302,35 +330,17 @@
this.timeout = timeout;
};
- public SpanQuery getSpanQuery () {
- return this.spanQuery;
- };
public JsonNode getRequest () {
return this.request;
};
- public KorapSearch setSpanQuery (SpanQueryWrapper sqwi) {
- // this.copyNotifications(sqwi);
- try {
- this.spanQuery = sqwi.toQuery();
- }
- catch (QueryException q) {
- this.addError(q.getErrorCode(), q.getMessage());
- };
- return this;
- };
-
- public KorapSearch setSpanQuery (SpanQuery sq) {
- this.spanQuery = sq;
- return this;
- };
public SearchContext getContext () {
return this.context;
};
- public KorapSearch setContext (SearchContext context) {
+ public Krill setContext (SearchContext context) {
this.context = context;
return this;
};
@@ -339,12 +349,12 @@
return this.startIndex;
};
- public KorapSearch setStartIndex (int value) {
+ public Krill setStartIndex (int value) {
this.startIndex = (value >= 0) ? value : 0;
return this;
};
- public KorapSearch setStartPage (int value) {
+ public Krill setStartPage (int value) {
if (value >= 0)
this.setStartIndex((value * this.getCount()) - this.getCount());
else
@@ -364,7 +374,7 @@
return this.limit;
};
- public KorapSearch setLimit (int limit) {
+ public Krill setLimit (int limit) {
if (limit > 0)
this.limit = limit;
return this;
@@ -374,30 +384,30 @@
return this.cutOff;
};
- public KorapSearch setCutOff (boolean cutOff) {
+ public Krill setCutOff (boolean cutOff) {
this.cutOff = cutOff;
return this;
};
- public KorapSearch setCount (int value) {
+ public Krill setCount (int value) {
// Todo: Maybe update startIndex with known startPage!
this.setCount((short) value);
return this;
};
- public KorapSearch setCount (short value) {
+ public Krill setCount (short value) {
if (value > 0)
this.count = (value <= this.countMax) ? value : this.countMax;
return this;
};
- public KorapSearch setItemsPerResource (short value) {
+ public Krill setItemsPerResource (short value) {
if (value >= 0)
this.itemsPerResource = value;
return this;
};
- public KorapSearch setItemsPerResource (int value) {
+ public Krill setItemsPerResource (int value) {
return this.setItemsPerResource((short) value);
};
@@ -419,9 +429,9 @@
* Add a field to the set of fields to retrieve.
*
* @param field The field to retrieve.
- * @return The {@link KorapSearch} object for chaining.
+ * @return The {@link Krill} object for chaining.
*/
- public KorapSearch addField (String field) {
+ public Krill addField (String field) {
this.fields.add(field);
return this;
};
@@ -431,15 +441,15 @@
* Add class numbers to highlight in KWIC view.
*
* @param classNumber The number of a class to highlight.
- * @return The {@link KorapSearch} object for chaining.
+ * @return The {@link Krill} object for chaining.
*/
- public KorapSearch addHighlight (int classNumber) {
+ public Krill addHighlight (int classNumber) {
this.highlights.add(classNumber);
return this;
};
- public KorapSearch setCollection (KorapCollection kc) {
+ public Krill setCollection (KorapCollection kc) {
this.collection = kc;
// Move messages from the collection
@@ -455,35 +465,84 @@
};
+ public KorapIndex getIndex () {
+ return this.index;
+ };
+
+ public Krill setIndex (KorapIndex ki) {
+ this.index = ki;
+ return this;
+ };
+
+
/**
* Apply the KoralQuery to an index.
+ *
+ * @param index The {@link KorapIndex}
+ * the search should be applyied to.
+ * @return The result as a {@link KorapResult} object.
*/
- public KorapResult apply (KorapIndex ki) {
- if (this.spanQuery == null) {
- KorapResult kr = new KorapResult();
- kr.setRequest(this.request);
+ public KorapResult apply (KorapIndex index) {
+ return this.setIndex(index).apply();
+ };
- if (this.hasErrors())
- kr.copyNotificationsFrom(this);
- else
- kr.addError(700, "No query given");
- return kr;
- };
+ /**
+ * Apply the KoralQuery to an index.
+ *
+ * @return The result as a {@link KorapResult} object.
+ */
+ public KorapResult apply () {
+
+ // Create new KorapResult object to return
+ KorapResult kr = new KorapResult();
+
+ // There were errors
if (this.hasErrors()) {
- KorapResult kr = new KorapResult();
-
- // TODO: dev mode
- kr.setRequest(this.request);
kr.copyNotificationsFrom(this);
- return kr;
+ }
+
+ // There was no index
+ else if (this.index == null) {
+ kr.addError(601, "Unable to find index");
+ }
+
+ // Apply search
+ else {
+ kr = this.index.search(this);
+ this.getCollection().setIndex(this.index);
+ kr.copyNotificationsFrom(this);
};
- this.getCollection().setIndex(ki);
- KorapResult kr = ki.search(this);
+ // TODO: Only for development mode
kr.setRequest(this.request);
- kr.copyNotificationsFrom(this);
- this.clearNotifications();
+ kr.setQuery(this.getQuery());
+
return kr;
};
+
+ @Deprecated
+ public SpanQuery getSpanQuery () {
+ return this.spanQuery;
+ };
+
+
+ @Deprecated
+ public Krill setSpanQuery (SpanQueryWrapper sqwi) {
+ // this.copyNotifications(sqwi);
+ try {
+ this.spanQuery = sqwi.toQuery();
+ }
+ catch (QueryException q) {
+ this.addError(q.getErrorCode(), q.getMessage());
+ };
+ return this;
+ };
+
+
+ @Deprecated
+ public Krill setSpanQuery (SpanQuery sq) {
+ this.spanQuery = sq;
+ return this;
+ };
};
diff --git a/src/main/java/de/ids_mannheim/korap/node/Resource.java b/src/main/java/de/ids_mannheim/korap/node/Resource.java
index bc70cd1..0bdcc23 100644
--- a/src/main/java/de/ids_mannheim/korap/node/Resource.java
+++ b/src/main/java/de/ids_mannheim/korap/node/Resource.java
@@ -22,7 +22,7 @@
import de.ids_mannheim.korap.KorapNode;
import de.ids_mannheim.korap.KorapIndex;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KorapCollection;
import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.KorapResult;
@@ -62,6 +62,9 @@
// Initiate Logger
private final static Logger log = LoggerFactory.getLogger(KorapNode.class);
+ // This advices the java compiler to ignore all loggings
+ public static final boolean DEBUG = false;
+
// Slightly based on String::BooleanSimple
static Pattern p = Pattern.compile(
"\\s*(?i:false|no|inactive|disabled|off|n|neg(?:ative)?|not|null|undef)\\s*"
@@ -69,14 +72,14 @@
// Check if a string is meant to represent null
private static boolean isNull (String value) {
- if (value == null)
- return true;
+ if (value == null)
+ return true;
- Matcher m = p.matcher(value);
- if (m.matches())
- return true;
+ Matcher m = p.matcher(value);
+ if (m.matches())
+ return true;
- return false;
+ return false;
};
@@ -86,22 +89,22 @@
@GET
@Produces(MediaType.APPLICATION_JSON)
public String info () {
- KorapIndex index = KorapNode.getIndex();
- KorapResponse kresp = new KorapResponse();
- kresp.setNode(KorapNode.getName());
- kresp.setName(index.getName());
- kresp.setVersion(index.getVersion());
+ KorapIndex index = KorapNode.getIndex();
+ KorapResponse kresp = new KorapResponse();
+ kresp.setNode(KorapNode.getName());
+ kresp.setName(index.getName());
+ kresp.setVersion(index.getVersion());
- kresp.setListener(KorapNode.getListener());
- long texts = -1;
- /*
- kresp.addMessage(
- "Number of documents in the index",
- String.parseLong(index.numberOf("documents"))
- );
- */
- kresp.addMessage(680, "Server is up and running!");
- return kresp.toJsonString();
+ kresp.setListener(KorapNode.getListener());
+ long texts = -1;
+ /*
+ kresp.addMessage(
+ "Number of documents in the index",
+ String.parseLong(index.numberOf("documents"))
+ );
+ */
+ kresp.addMessage(680, "Server is up and running!");
+ return kresp.toJsonString();
};
@@ -120,44 +123,50 @@
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String add (@PathParam("textID") Integer uid,
- @Context UriInfo uri,
- String json) {
- /*
- * See
- * http://www.mkyong.com/webservices/jax-rs/file-upload-example-in-jersey/
- */
+ @Context UriInfo uri,
+ String json) {
+ /*
+ * See
+ * http://www.mkyong.com/webservices/jax-rs/file-upload-example-in-jersey/
+ */
- // Todo: Parameter for server node
+ // Todo: Parameter for server node
- // Get index
- KorapIndex index = KorapNode.getIndex();
+ if (DEBUG)
+ log.trace("Added new document with unique identifier {}", uid);
- KorapResponse kresp = new KorapResponse();
- kresp.setNode(KorapNode.getName());
+ // Get index
+ KorapIndex index = KorapNode.getIndex();
- if (index == null) {
- kresp.addError(601, "Unable to find index");
- return kresp.toJsonString();
- };
+ KorapResponse kresp = new KorapResponse();
+ kresp.setNode(KorapNode.getName());
- kresp.setVersion(index.getVersion());
- kresp.setName(index.getName());
+ if (index == null) {
+ kresp.addError(601, "Unable to find index");
+ return kresp.toJsonString();
+ };
- String ID = "Unknown";
- try {
- FieldDocument fd = index.addDoc(uid, json);
- ID = fd.getID();
- }
- // Set HTTP to ???
- // TODO: This may be a field error!
- catch (IOException e) {
- kresp.addError(602, "Unable to add document to index");
- return kresp.toJsonString();
- };
+ kresp.setVersion(index.getVersion());
+ kresp.setName(index.getName());
- // Set HTTP to 200
- kresp.addMessage(681, "Document was added successfully", ID);
- return kresp.toJsonString();
+ String ID = "Unknown";
+ try {
+ FieldDocument fd = index.addDoc(uid, json);
+ ID = fd.getID();
+ }
+ // Set HTTP to ???
+ // TODO: This may be a field error!
+ catch (IOException e) {
+ kresp.addError(602, "Unable to add document to index");
+ return kresp.toJsonString();
+ };
+
+ // Set HTTP to 200
+ kresp.addMessage(681, "Document was added successfully", ID);
+
+
+ System.err.println(kresp.toJsonString());
+ return kresp.toJsonString();
};
@@ -170,31 +179,31 @@
@Produces(MediaType.APPLICATION_JSON)
public String commit () {
- // Get index
- KorapIndex index = KorapNode.getIndex();
- KorapResponse kresp = new KorapResponse();
- kresp.setNode(KorapNode.getName());
+ // Get index
+ KorapIndex index = KorapNode.getIndex();
+ KorapResponse kresp = new KorapResponse();
+ kresp.setNode(KorapNode.getName());
- if (index == null) {
- kresp.addError(601, "Unable to find index");
- return kresp.toJsonString();
- };
+ if (index == null) {
+ kresp.addError(601, "Unable to find index");
+ return kresp.toJsonString();
+ };
- kresp.setVersion(index.getVersion());
- kresp.setName(index.getName());
+ kresp.setVersion(index.getVersion());
+ kresp.setName(index.getName());
+
+ // There are documents to commit
+ try {
+ index.commit();
+ }
+ catch (IOException e) {
+ // Set HTTP to ???
+ kresp.addError(603, "Unable to commit staged data to index");
+ return kresp.toJsonString();
+ };
- // There are documents to commit
- try {
- index.commit();
- }
- catch (IOException e) {
- // Set HTTP to ???
- kresp.addError(603, "Unable to commit staged data to index");
- return kresp.toJsonString();
- };
-
- // Set HTTP to ???
- return kresp.toJsonString();
+ // Set HTTP to ???
+ return kresp.toJsonString();
};
@@ -209,47 +218,47 @@
@Consumes(MediaType.APPLICATION_JSON)
public String find (String json, @Context UriInfo uri) {
- // Get index
- KorapIndex index = KorapNode.getIndex();
+ // Get index
+ KorapIndex index = KorapNode.getIndex();
- // Search index
+ // Search index
if (index != null) {
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
- // Get query parameters
- MultivaluedMap<String,String> qp = uri.getQueryParameters();
+ // Get query parameters
+ MultivaluedMap<String,String> qp = uri.getQueryParameters();
- if (qp.get("uid") != null) {
+ if (qp.get("uid") != null) {
- // Build Collection based on a list of uids
- List<String> uids = qp.get("uid");
- KorapCollection kc = new KorapCollection();
- kc.filterUIDs(uids.toArray(new String[uids.size()]));
+ // Build Collection based on a list of uids
+ List<String> uids = qp.get("uid");
+ KorapCollection kc = new KorapCollection();
+ kc.filterUIDs(uids.toArray(new String[uids.size()]));
+
+ // TODO: RESTRICT COLLECTION TO ONLY RESPECT SELF DOCS (REPLICATION)
+
+ // Override old collection
+ ks.setCollection(kc);
- // TODO: RESTRICT COLLECTION TO ONLY RESPECT SELF DOCS (REPLICATION)
+ // Only return the first match per text
+ ks.setItemsPerResource(1);
- // Override old collection
- ks.setCollection(kc);
+ return ks.apply(index).toJsonString();
+ };
+ KorapResult kr = new KorapResult();
+ kr.setNode(KorapNode.getName());
+ kr.addError(610, "Missing request parameters", "No unique IDs were given");
+ return kr.toJsonString();
+ };
- // Only return the first match per text
- ks.setItemsPerResource(1);
-
- return ks.apply(index).toJsonString();
- };
- KorapResult kr = new KorapResult();
- kr.setNode(KorapNode.getName());
- kr.addError(610, "Missing request parameters", "No unique IDs were given");
- return kr.toJsonString();
- };
-
- KorapResponse kresp = new KorapResponse();
- kresp.setNode(KorapNode.getName());
- kresp.setName(index.getName());
- kresp.setVersion(index.getVersion());
-
- kresp.addError(601, "Unable to find index");
-
- return kresp.toJsonString();
+ KorapResponse kresp = new KorapResponse();
+ kresp.setNode(KorapNode.getName());
+ kresp.setName(index.getName());
+ kresp.setVersion(index.getVersion());
+
+ kresp.addError(601, "Unable to find index");
+
+ return kresp.toJsonString();
};
@@ -263,45 +272,45 @@
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String collect (String json,
- @PathParam("resultID") String resultID,
- @Context UriInfo uri) {
+ @PathParam("resultID") String resultID,
+ @Context UriInfo uri) {
- // Get index
- KorapIndex index = KorapNode.getIndex();
+ // Get index
+ KorapIndex index = KorapNode.getIndex();
- // No index found
- if (index == null) {
- KorapResponse kresp = new KorapResponse();
- kresp.setNode(KorapNode.getName());
- kresp.addError(601, "Unable to find index");
- return kresp.toJsonString();
- };
+ // No index found
+ if (index == null) {
+ KorapResponse kresp = new KorapResponse();
+ kresp.setNode(KorapNode.getName());
+ kresp.addError(601, "Unable to find index");
+ return kresp.toJsonString();
+ };
- // Get the database
- try {
- MatchCollectorDB mc = new MatchCollectorDB(1000, "Res_" + resultID);
- Connection conn = KorapNode.getDBPool().getConnection();
- mc.setDBPool("mysql", KorapNode.getDBPool(), conn);
+ // Get the database
+ try {
+ MatchCollectorDB mc = new MatchCollectorDB(1000, "Res_" + resultID);
+ Connection conn = KorapNode.getDBPool().getConnection();
+ mc.setDBPool("mysql", KorapNode.getDBPool(), conn);
+
+ // TODO: Only search in self documents (REPLICATION FTW!)
+
+ Krill ks = new Krill(json);
+ MatchCollector result = index.collect(ks, mc);
- // TODO: Only search in self documents (REPLICATION FTW!)
+ result.setNode(KorapNode.getName());
+ return result.toJsonString();
+ }
+ catch (SQLException e) {
+ log.error(e.getLocalizedMessage());
+ };
- KorapSearch ks = new KorapSearch(json);
- MatchCollector result = index.collect(ks, mc);
+ KorapResponse kresp = new KorapResponse();
+ kresp.setNode(KorapNode.getName());
+ kresp.setName(index.getName());
+ kresp.setVersion(index.getVersion());
- result.setNode(KorapNode.getName());
- return result.toJsonString();
- }
- catch (SQLException e) {
- log.error(e.getLocalizedMessage());
- };
-
- KorapResponse kresp = new KorapResponse();
- kresp.setNode(KorapNode.getName());
- kresp.setName(index.getName());
- kresp.setVersion(index.getVersion());
-
- kresp.addError(604, "Unable to connect to database");
- return kresp.toJsonString();
+ kresp.addError(604, "Unable to connect to database");
+ return kresp.toJsonString();
};
@@ -329,7 +338,7 @@
// Search index
if (index != null) {
- KorapResult kr = new KorapSearch(json).apply(index);
+ KorapResult kr = new Krill(json).apply(index);
kr.setNode(KorapNode.getName());
return kr.toJsonString();
};
diff --git a/src/main/java/de/ids_mannheim/korap/response/KorapResponse.java b/src/main/java/de/ids_mannheim/korap/response/KorapResponse.java
index 3f7e54e..b082f29 100644
--- a/src/main/java/de/ids_mannheim/korap/response/KorapResponse.java
+++ b/src/main/java/de/ids_mannheim/korap/response/KorapResponse.java
@@ -9,6 +9,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.response.Notifications;
/**
@@ -31,6 +32,8 @@
ObjectMapper mapper = new ObjectMapper();
private String version, name, node, listener;
+ private KorapQuery query;
+
private long
totalResources = -2, // Not set
totalResults = -2; // Not set
@@ -313,6 +316,31 @@
/**
+ * Get the KoralQuery query object.
+ *
+ * @return The {@link KorapQuery} object,
+ * representing the KoralQuery query object.
+ */
+ @JsonIgnore
+ public KorapQuery getQuery () {
+ return this.query;
+ };
+
+
+ /**
+ * Set the KoralQuery query object.
+ *
+ * @param query The {@link KorapQuery} object,
+ * representing the KoralQuery query object.
+ */
+ @JsonIgnore
+ public KorapResponse setQuery (KorapQuery query) {
+ this.query = query;
+ return this;
+ };
+
+
+ /**
* Serialize response as a {@link JsonNode}.
*
* @return {@link JsonNode} representation of the response
@@ -358,6 +386,14 @@
if (this.totalResults != -2)
json.put("totalResults", this.totalResults);
+ // KoralQuery query object
+ if (this.getQuery() != null) {
+ JsonNode queryNode =
+ this.getQuery().toJsonNode();
+ if (queryNode != null)
+ json.put("query", queryNode);
+ };
+
return (JsonNode) json;
};
diff --git a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
index ce3e202..2501b31 100644
--- a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
+++ b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
@@ -6,7 +6,7 @@
import de.ids_mannheim.korap.KorapIndex;
import de.ids_mannheim.korap.index.FieldDocument;
import de.ids_mannheim.korap.KorapCollection;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KorapResult;
import de.ids_mannheim.korap.KorapQuery;
import org.apache.lucene.store.MMapDirectory;
@@ -46,7 +46,7 @@
t1 = System.nanoTime();
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
};
t2 = System.nanoTime();
@@ -99,7 +99,7 @@
t1 = System.nanoTime();
double length = 0;
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
length += kr.toJsonString().length();
};
t2 = System.nanoTime();
@@ -141,7 +141,7 @@
t1 = System.nanoTime();
double length = 0;
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
};
t2 = System.nanoTime();
@@ -182,7 +182,7 @@
t1 = System.nanoTime();
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
};
t2 = System.nanoTime();
@@ -197,7 +197,7 @@
t1 = System.nanoTime();
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
};
t2 = System.nanoTime();
@@ -212,7 +212,7 @@
t1 = System.nanoTime();
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
};
t2 = System.nanoTime();
@@ -329,7 +329,7 @@
t1 = System.nanoTime();
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
};
t2 = System.nanoTime();
diff --git a/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java b/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java
index b3b5736..07650dd 100644
--- a/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java
+++ b/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java
@@ -14,7 +14,7 @@
import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.KorapResult;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.query.SpanNextQuery;
import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
import de.ids_mannheim.korap.util.QueryException;
@@ -23,7 +23,7 @@
public class TestClass {
KorapIndex ki;
KorapResult kr;
- KorapSearch ks;
+ Krill ks;
@Test
public void queryJSONpoly1() throws QueryException, IOException {
diff --git a/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java b/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
index 0118e1b..1fd999f 100644
--- a/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
+++ b/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
@@ -8,7 +8,7 @@
import de.ids_mannheim.korap.KorapIndex;
import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.KorapResult;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.index.FieldDocument;
@@ -211,7 +211,7 @@
kq = new KorapQuery("base");
q = (SpanQuery) kq.or(kq._(1, kq.seg("i:a"))).or(kq._(2, kq.seg("i:c"))).toQuery();
- KorapSearch qs = new KorapSearch(q);
+ Krill qs = new Krill(q);
qs.getContext().left.setToken(true).setLength((short) 1);
qs.getContext().right.setToken(true).setLength((short) 1);
kr = ki.search(qs);
@@ -247,7 +247,7 @@
q = (SpanQuery) kq._(
3, kq.or(kq._(1, kq.seg("i:a"))).or(kq._(2, kq.seg("i:c")))
).toQuery();
- qs = new KorapSearch(q);
+ qs = new Krill(q);
qs.getContext().left.setToken(true).setLength((short) 0);
qs.getContext().right.setToken(true).setLength((short) 0);
kr = ki.search(qs);
@@ -281,7 +281,7 @@
// 15
String json = getString(getClass().getResource("/queries/bugs/greater_highlights_15.jsonld").getFile());
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapResult kr = ks.apply(ki);
assertEquals(kr.getSerialQuery(),"{15: tokens:s:Alphabet}");
assertEquals(kr.getTotalResults(),7);
@@ -292,7 +292,7 @@
json = getString(getClass().getResource("/queries/bugs/greater_highlights_16.jsonld").getFile());
// 16
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(kr.getSerialQuery(),"{16: tokens:s:Alphabet}");
assertEquals(kr.getTotalResults(),7);
@@ -303,7 +303,7 @@
// 127
json = getString(getClass().getResource("/queries/bugs/greater_highlights_127.jsonld").getFile());
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(kr.getSerialQuery(),"{127: tokens:s:Alphabet}");
assertEquals(kr.getTotalResults(),7);
@@ -314,7 +314,7 @@
// 255
json = getString(getClass().getResource("/queries/bugs/greater_highlights_255.jsonld").getFile());
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(kr.getSerialQuery(),"{255: tokens:s:Alphabet}");
assertEquals(kr.getTotalResults(),7);
@@ -325,7 +325,7 @@
// 300
json = getString(getClass().getResource("/queries/bugs/greater_highlights_300.jsonld").getFile());
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(709, kr.getError(0).getCode());
assertEquals("Valid class numbers exceeded", kr.getError(0).getMessage());
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java b/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
index 04ea612..7eebc61 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
@@ -19,7 +19,7 @@
import de.ids_mannheim.korap.KorapIndex;
import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.KorapResult;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.KorapDocument;
import de.ids_mannheim.korap.query.SpanNextQuery;
@@ -175,13 +175,13 @@
KorapQuery kq = new KorapQuery("tokens");
- KorapSearch ks;
+ Krill ks;
KorapResult kr;
// Start creating query
// within(<s>, {1: {2: [mate/p=ADJA & mate/m=number:sg]}[opennlp/p=NN & tt/p=NN]})
- ks = new KorapSearch(kq.within(
+ ks = new Krill(kq.within(
kq.tag("s"),
kq._(1,
kq.seq(
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchCollector.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchCollector.java
index 854f6f6..62781d2 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchCollector.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchCollector.java
@@ -18,7 +18,7 @@
import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.index.MatchCollector;
import de.ids_mannheim.korap.KorapCollection;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.query.SpanNextQuery;
import de.ids_mannheim.korap.query.SpanClassQuery;
import de.ids_mannheim.korap.index.FieldDocument;
@@ -77,7 +77,7 @@
sq = new SpanTermQuery(new Term("base", "s:b"));
MatchCollector mc = ki.collect(
- new KorapSearch(sq).setCount((short) 10),
+ new Krill(sq).setCount((short) 10),
new MatchCollector()
);
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
index 5d320e4..a98ed05 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
@@ -14,7 +14,7 @@
import de.ids_mannheim.korap.KorapIndex;
import de.ids_mannheim.korap.KorapQuery;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KorapResult;
import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.util.QueryException;
@@ -92,7 +92,7 @@
ki.commit();
KorapQuery kq = new KorapQuery("tokens");
- KorapSearch ks = new KorapSearch(
+ Krill ks = new Krill(
kq._(2,kq.seq(kq.seg("s:b")).append(kq._(kq.seg("s:a"))))
);
KorapResult kr = ki.search(ks);
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
index 7d0fc46..8b86c7f 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
@@ -19,7 +19,7 @@
public class TestRealIndex {
KorapIndex ki;
KorapResult kr;
- KorapSearch ks;
+ Krill ks;
KorapQuery kq;
public TestRealIndex() throws IOException {
@@ -36,7 +36,7 @@
@Test
public void testCase1() throws IOException, QueryException {
KorapQuery kq = new KorapQuery("tokens");
- ks = new KorapSearch(kq.within(kq.tag("base/s:s"), kq.seq(kq.re("s:.*")).append(kq._(kq.re("s:.*")))).toQuery());
+ ks = new Krill(kq.within(kq.tag("base/s:s"), kq.seq(kq.re("s:.*")).append(kq._(kq.re("s:.*")))).toQuery());
ks.setTimeOut(10000);
kr = ks.apply(ki);
System.err.println(kr.toJsonString());
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
index 20273bc..6815a49 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
@@ -16,7 +16,7 @@
import de.ids_mannheim.korap.KorapIndex;
import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.KorapResult;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.index.FieldDocument;
import de.ids_mannheim.korap.model.MultiTermTokenStream;
import org.apache.lucene.search.Query;
@@ -52,7 +52,7 @@
SpanQuery sq = kq.re("s:af*e").toQuery();
assertEquals("SpanMultiTermQueryWrapper(base:/s:af*e/)", sq.toString());
- KorapSearch ks = new KorapSearch(sq);
+ Krill ks = new Krill(sq);
ks.context.left.setToken(true).setLength(1);
ks.context.right.setToken(true).setLength(1);
@@ -109,7 +109,7 @@
SpanQuery sq = kq.wc("s:af*e").toQuery();
assertEquals("SpanMultiTermQueryWrapper(base:s:af*e)", sq.toString());
- KorapSearch ks = new KorapSearch(sq);
+ Krill ks = new Krill(sq);
ks.context.left.setToken(true).setLength(1);
ks.context.right.setToken(true).setLength(1);
@@ -168,7 +168,7 @@
SpanQuery sq = kq.re("s:Af*e", true).toQuery();
assertEquals("SpanMultiTermQueryWrapper(base:/i:af*e/)", sq.toString());
- KorapSearch ks = new KorapSearch(sq);
+ Krill ks = new Krill(sq);
ks.context.left.setToken(true).setLength(1);
ks.context.right.setToken(true).setLength(1);
@@ -233,7 +233,7 @@
SpanQuery sq = kq.seq(kq.seg("s:affe")).append(kq.re("s:af*e")).toQuery();
assertEquals("spanNext(base:s:affe, SpanMultiTermQueryWrapper(base:/s:af*e/))", sq.toString());
- KorapSearch ks = new KorapSearch(sq);
+ Krill ks = new Krill(sq);
ks.context.left.setToken(true).setLength(1);
ks.context.right.setToken(true).setLength(1);
@@ -274,7 +274,7 @@
),
kq.seg("s:affe")).toQuery();
assertEquals("spanContain(spanNext(SpanMultiTermQueryWrapper(base:/s:a.*e/), SpanMultiTermQueryWrapper(base:/s:af*e/)), base:s:affe)", sq.toString());
- KorapSearch ks = new KorapSearch(sq);
+ Krill ks = new Krill(sq);
ks.context.left.setToken(true).setLength(1);
ks.context.right.setToken(true).setLength(1);
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
index 6711653..25516e6 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
@@ -17,7 +17,7 @@
import de.ids_mannheim.korap.KorapIndex;
import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.KorapResult;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.collection.BooleanFilter;
import de.ids_mannheim.korap.query.DistanceConstraint;
import de.ids_mannheim.korap.query.SpanDistanceQuery;
@@ -29,7 +29,7 @@
long start, end;
KorapIndex ki;
KorapResult kr;
- KorapSearch ks;
+ Krill ks;
private SpanDistanceQuery createElementDistanceQuery(String e, String x, String y,
int min, int max, boolean isOrdered, boolean exclusion){
@@ -70,18 +70,18 @@
SpanDistanceQuery sq;
// ordered
sq = createDistanceQuery("s:Wir", "s:kommen", 1, 1, true,false);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 8);
// unordered
sq = createDistanceQuery("s:Wir", "s:kommen", 1, 1, false,false);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 11);
sq = createDistanceQuery("s:kommen", "s:Wir", 1, 1, false,false);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 11);
//System.out.println(kr.getTotalResults());
@@ -97,20 +97,20 @@
public void testCase2() throws IOException{
SpanQuery q = new SpanTermQuery(new Term("tokens","s:Wir"));
- ks = new KorapSearch(q);
+ ks = new Krill(q);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1907);
SpanDistanceQuery sq;
// ordered
sq = createDistanceQuery("s:Wir", "s:kommen", 1, 1, true, true);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1899);
// unordered
sq = createDistanceQuery("s:Wir", "s:kommen", 1, 1, false, true);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1896);
}
@@ -121,13 +121,13 @@
// ordered
SpanDistanceQuery sq = createElementDistanceQuery("s","s:weg", "s:fahren",
0, 1, true, false);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 3);
// unordered
sq = createElementDistanceQuery("s","s:weg", "s:fahren", 0, 1, false,false);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 5);
@@ -144,7 +144,7 @@
// only 1
sq = createElementDistanceQuery("s","s:weg", "s:fahren", 1, 1, false,false);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 3);
}
@@ -153,7 +153,7 @@
@Test
public void testCase4() throws IOException{
SpanDistanceQuery sq = createElementDistanceQuery("s","s:weg", "s:fahren", 1, 1, false, true);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 979);
//0.8s
@@ -174,18 +174,18 @@
public void testCase5() throws IOException{
SpanQuery sq;
sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens","mate/p:ADJA")),1,2, true);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 4116416);
//0.9s
sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens","mate/p:ADJA")),1,1, true);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 3879671);
sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens","mate/p:ADJA")),2,2, true);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 236745);
//0.65s
@@ -198,14 +198,14 @@
new SpanTermQuery(new Term("tokens", "tt/p:NN")),
new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens","mate/p:ADJA")),2,2, true)
);
- ks = new KorapSearch(sq);
+ ks = new Krill(sq);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 30223);
// 1.1s
SpanQuery sq2 = new SpanNextQuery(sq,
new SpanTermQuery(new Term("tokens", "tt/p:NN")));
- ks = new KorapSearch(sq2);
+ ks = new Krill(sq2);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 26607);
// 1.1s
diff --git a/src/test/java/de/ids_mannheim/korap/node/TestResource.java b/src/test/java/de/ids_mannheim/korap/node/TestResource.java
index 643ec6a..5c80b59 100644
--- a/src/test/java/de/ids_mannheim/korap/node/TestResource.java
+++ b/src/test/java/de/ids_mannheim/korap/node/TestResource.java
@@ -10,6 +10,7 @@
import javax.ws.rs.client.Entity;
import org.glassfish.grizzly.http.server.HttpServer;
+import com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures;
import static org.junit.Assert.*;
import org.junit.After;
@@ -29,7 +30,6 @@
*/
// http://harryjoy.com/2012/09/08/simple-rest-client-in-java/
public class TestResource {
-
private HttpServer server;
private WebTarget target;
@@ -44,8 +44,17 @@
// support for JSON in the client (you also have to uncomment
// dependency on jersey-media-json module in pom.xml and Main.startServer())
// --
- // c.configuration().enable(new org.glassfish.jersey.media.json.JsonJaxbFeature());
+ // c.configuration().enable(com.sun.jersey.api.json.POJOMappingFeature());
+ // c.configuration().enable(new org.glassfish.jersey.media.json.JsonJaxbFeature());
+ // c.register(JacksonFeature.class);
+ // c.register(com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures.class);
+
+ /*
+ ClientConfig clientConfig = new DefaultClientConfig();
+ clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
+ Client c = Client.create(clientConfig);
+*/
target = c.target(KorapNode.BASE_URI);
};
@@ -80,9 +89,11 @@
getClass().getResource("/wiki/" + i + ".json").getFile()
);
+ Entity jsonE = Entity.json(json);
+
kresp = target.path("/index/" + i).
request("application/json").
- put(Entity.json(json), KorapResponse.class);
+ put(jsonE, KorapResponse.class);
assertEquals(kresp.getNode(), "milena");
assertFalse(kresp.hasErrors());
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java b/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
index 73ada81..de572cc 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
@@ -8,7 +8,7 @@
import de.ids_mannheim.korap.KorapIndex;
import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.KorapResult;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.index.FieldDocument;
@@ -52,7 +52,7 @@
json = getString(getClass().getResource("/queries/bugs/cosmas_classrefcheck.jsonld").getFile());
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapResult kr = ks.apply(ki);
assertEquals(kr.getSerialQuery(),"focus(130: {131: spanContain({129: <tokens:s />}, {130: tokens:s:wegen})})");
assertEquals(kr.getTotalResults(),0);
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java b/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java
index 80776b5..cfbedff 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java
@@ -8,7 +8,7 @@
import de.ids_mannheim.korap.KorapIndex;
import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.KorapResult;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.index.FieldDocument;
@@ -30,239 +30,240 @@
@Test
public void checkJSONResult () throws Exception {
- KorapIndex ki = new KorapIndex();
- FieldDocument fd = new FieldDocument();
- fd.addString("ID", "doc-1");
- fd.addString("UID", "1");
- fd.addTV("base",
- "abab",
- "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
- "[(1-2)s:b|i:b|_1#1-2]" +
- "[(2-3)s:a|i:c|_2#2-3]" +
- "[(3-4)s:b|i:a|_3#3-4]");
- ki.addDoc(fd);
- fd = new FieldDocument();
- fd.addString("ID", "doc-2");
- fd.addString("UID", "2");
- fd.addTV("base",
- "aba",
- "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
- "[(1-2)s:b|i:b|_1#1-2]" +
- "[(2-3)s:a|i:c|_2#2-3]");
- ki.addDoc(fd);
+ KorapIndex ki = new KorapIndex();
+ FieldDocument fd = new FieldDocument();
+ fd.addString("ID", "doc-1");
+ fd.addString("UID", "1");
+ fd.addTV("base",
+ "abab",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]" +
+ "[(3-4)s:b|i:a|_3#3-4]");
+ ki.addDoc(fd);
+ fd = new FieldDocument();
+ fd.addString("ID", "doc-2");
+ fd.addString("UID", "2");
+ fd.addTV("base",
+ "aba",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]");
+ ki.addDoc(fd);
- // Commit!
- ki.commit();
+ // Commit!
+ ki.commit();
- KorapQuery kq = new KorapQuery("base");
- SpanQuery q = (SpanQuery) kq.or(kq._(1, kq.seg("s:a"))).or(kq._(2, kq.seg("s:b"))).toQuery();
- KorapResult kr = ki.search(q);
- assertEquals((long) 7, kr.getTotalResults());
+ KorapQuery kq = new KorapQuery("base");
+ SpanQuery q = (SpanQuery) kq.or(
+ kq._(1, kq.seg("s:a"))).or(kq._(2, kq.seg("s:b"))
+ ).toQuery();
+ KorapResult kr = ki.search(q);
+ assertEquals((long) 7, kr.getTotalResults());
- ObjectMapper mapper = new ObjectMapper();
- JsonNode res = mapper.readTree(kr.toJsonString());
- assertEquals(7, res.at("/totalResults").asInt());
- assertEquals("spanOr([{1: base:s:a}, {2: base:s:b}])", res.at("/serialQuery").asText());
- assertEquals(0, res.at("/startIndex").asInt());
- assertEquals(25, res.at("/itemsPerPage").asInt());
- assertEquals("token", res.at("/context/left/0").asText());
- assertEquals(6, res.at("/context/left/1").asInt());
- assertEquals("token", res.at("/context/right/0").asText());
- assertEquals(6, res.at("/context/right/1").asInt());
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res = mapper.readTree(kr.toJsonString());
+ assertEquals(7, res.at("/totalResults").asInt());
+ assertEquals("spanOr([{1: base:s:a}, {2: base:s:b}])",
+ res.at("/serialQuery").asText());
+ assertEquals(0, res.at("/startIndex").asInt());
+ assertEquals(25, res.at("/itemsPerPage").asInt());
+ assertEquals("token", res.at("/context/left/0").asText());
+ assertEquals(6, res.at("/context/left/1").asInt());
+ assertEquals("token", res.at("/context/right/0").asText());
+ assertEquals(6, res.at("/context/right/1").asInt());
- assertEquals("base", res.at("/matches/0/field").asText());
- /*
- Probably a Jackson bug
- assertTrue(res.at("/matches/0/startMore").asBoolean());
- assertTrue(res.at("/matches/0/endMore").asBoolean());
- */
- assertEquals(1, res.at("/matches/0/UID").asInt());
- assertEquals("doc-1", res.at("/matches/0/docID").asText());
- assertEquals("match-doc-1-p0-1(1)0-0", res.at("/matches/0/ID").asText());
- assertEquals("<span class=\"context-left\"></span><mark><mark class=\"class-1 level-0\">a</mark></mark><span class=\"context-right\">bab</span>", res.at("/matches/0/snippet").asText());
+ assertEquals("base", res.at("/matches/0/field").asText());
+ /*
+ Probably a Jackson bug
+ assertTrue(res.at("/matches/0/startMore").asBoolean());
+ assertTrue(res.at("/matches/0/endMore").asBoolean());
+ */
+ assertEquals(1, res.at("/matches/0/UID").asInt());
+ assertEquals("doc-1", res.at("/matches/0/docID").asText());
+ assertEquals("match-doc-1-p0-1(1)0-0", res.at("/matches/0/ID").asText());
+ assertEquals("<span class=\"context-left\"></span><mark><mark class=\"class-1 level-0\">a</mark></mark><span class=\"context-right\">bab</span>", res.at("/matches/0/snippet").asText());
- assertEquals("base", res.at("/matches/6/field").asText());
- /*
- Probably a Jackson bug
- assertEquals(true, res.at("/matches/6/startMore").asBoolean());
- assertEquals(true, res.at("/matches/6/endMore").asBoolean());
- */
- assertEquals(2, res.at("/matches/6/UID").asInt());
- assertEquals("doc-2", res.at("/matches/6/docID").asText());
- assertEquals("match-doc-2-p2-3(1)2-2", res.at("/matches/6/ID").asText());
- assertEquals("<span class=\"context-left\">ab</span><mark><mark class=\"class-1 level-0\">a</mark></mark><span class=\"context-right\"></span>", res.at("/matches/6/snippet").asText());
-
+ assertEquals("base", res.at("/matches/6/field").asText());
+ /*
+ Probably a Jackson bug
+ assertEquals(true, res.at("/matches/6/startMore").asBoolean());
+ assertEquals(true, res.at("/matches/6/endMore").asBoolean());
+ */
+ assertEquals(2, res.at("/matches/6/UID").asInt());
+ assertEquals("doc-2", res.at("/matches/6/docID").asText());
+ assertEquals("match-doc-2-p2-3(1)2-2", res.at("/matches/6/ID").asText());
+ assertEquals("<span class=\"context-left\">ab</span><mark><mark class=\"class-1 level-0\">a</mark></mark><span class=\"context-right\"></span>", res.at("/matches/6/snippet").asText());
};
@Test
public void checkJSONResultWarningBug () throws Exception {
- KorapIndex ki = new KorapIndex();
- FieldDocument fd = new FieldDocument();
- fd.addString("ID", "doc-1");
- fd.addString("UID", "1");
- fd.addTV("tokens",
- "abab",
- "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
- "[(1-2)s:b|i:b|_1#1-2]" +
- "[(2-3)s:a|i:c|_2#2-3]" +
- "[(3-4)s:b|i:a|_3#3-4]");
- ki.addDoc(fd);
- ki.commit();
+ KorapIndex ki = new KorapIndex();
+ FieldDocument fd = new FieldDocument();
+ fd.addString("ID", "doc-1");
+ fd.addString("UID", "1");
+ fd.addTV("tokens",
+ "abab",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]" +
+ "[(3-4)s:b|i:a|_3#3-4]");
+ ki.addDoc(fd);
+ ki.commit();
- String json = getString(getClass().getResource("/queries/bugs/optionality_warning.jsonld").getFile());
- KorapSearch ks = new KorapSearch(json);
+ String json = getString(getClass().getResource("/queries/bugs/optionality_warning.jsonld").getFile());
+ Krill ks = new Krill(json);
- KorapResult kr = ks.apply(ki);
- assertEquals((long) 2, kr.getTotalResults());
+ KorapResult kr = ks.apply(ki);
+ assertEquals((long) 2, kr.getTotalResults());
- ObjectMapper mapper = new ObjectMapper();
- JsonNode res = mapper.readTree(kr.toJsonString());
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res = mapper.readTree(kr.toJsonString());
- // Old:
- // assertEquals("Optionality of query is ignored", res.at("/warning").asText());
- assertEquals("Optionality of query is ignored",
- res.at("/warnings/0/1").asText());
-
+ // Old:
+ // assertEquals("Optionality of query is ignored", res.at("/warning").asText());
+ assertEquals("Optionality of query is ignored",
+ res.at("/warnings/0/1").asText());
};
@Test
public void checkJSONResultForJSONInput () throws Exception {
- KorapIndex ki = new KorapIndex();
- FieldDocument fd = new FieldDocument();
- fd.addString("ID", "doc-1");
- fd.addString("UID", "1");
- fd.addTV("tokens",
- "abab",
- "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
- "[(1-2)s:b|i:b|_1#1-2]" +
- "[(2-3)s:a|i:c|_2#2-3]" +
- "[(3-4)s:b|i:a|_3#3-4]");
- ki.addDoc(fd);
- fd = new FieldDocument();
- fd.addString("ID", "doc-2");
- fd.addString("UID", "2");
- fd.addTV("tokens",
- "aba",
- "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
- "[(1-2)s:b|i:b|_1#1-2]" +
- "[(2-3)s:a|i:c|_2#2-3]");
- ki.addDoc(fd);
+ KorapIndex ki = new KorapIndex();
+ FieldDocument fd = new FieldDocument();
+ fd.addString("ID", "doc-1");
+ fd.addString("UID", "1");
+ fd.addTV("tokens",
+ "abab",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]" +
+ "[(3-4)s:b|i:a|_3#3-4]");
+ ki.addDoc(fd);
+ fd = new FieldDocument();
+ fd.addString("ID", "doc-2");
+ fd.addString("UID", "2");
+ fd.addTV("tokens",
+ "aba",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]");
+ ki.addDoc(fd);
+
+ // Commit!
+ ki.commit();
- // Commit!
- ki.commit();
+ String json = getString(
+ getClass().getResource("/queries/bsp-result-check.jsonld").getFile()
+ );
+ Krill ks = new Krill(json);
+ KorapResult kr = ks.apply(ki);
+ assertEquals((long) 7, kr.getTotalResults());
- String json = getString(getClass().getResource("/queries/bsp-result-check.jsonld").getFile());
- KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.apply(ki);
- assertEquals((long) 7, kr.getTotalResults());
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res = mapper.readTree(kr.toJsonString());
- ObjectMapper mapper = new ObjectMapper();
- JsonNode res = mapper.readTree(kr.toJsonString());
+ assertEquals(7, res.at("/totalResults").asInt());
+ assertEquals("spanOr([tokens:s:a, tokens:s:b])", res.at("/serialQuery").asText());
+ assertEquals(5, res.at("/itemsPerPage").asInt());
+ assertEquals(0, res.at("/startIndex").asInt());
+ assertEquals(1, res.at("/request/meta/startPage").asInt());
+ assertEquals(5, res.at("/request/meta/count").asInt());
+ assertEquals("token", res.at("/request/meta/context/left/0").asText());
+ assertEquals(3, res.at("/request/meta/context/left/1").asInt());
+ assertEquals("char", res.at("/request/meta/context/right/0").asText());
+ assertEquals(6, res.at("/request/meta/context/right/1").asInt());
- assertEquals(7, res.at("/totalResults").asInt());
- assertEquals("spanOr([tokens:s:a, tokens:s:b])", res.at("/serialQuery").asText());
- assertEquals(5, res.at("/itemsPerPage").asInt());
- assertEquals(0, res.at("/startIndex").asInt());
- assertEquals(1, res.at("/request/meta/startPage").asInt());
- assertEquals(5, res.at("/request/meta/count").asInt());
- assertEquals("token", res.at("/request/meta/context/left/0").asText());
- assertEquals(3, res.at("/request/meta/context/left/1").asInt());
- assertEquals("char", res.at("/request/meta/context/right/0").asText());
- assertEquals(6, res.at("/request/meta/context/right/1").asInt());
+ assertEquals("koral:group", res.at("/request/query/@type").asText());
+ assertEquals("operation:or", res.at("/request/query/operation").asText());
- assertEquals("koral:group", res.at("/request/query/@type").asText());
- assertEquals("operation:or", res.at("/request/query/operation").asText());
+ assertEquals("koral:token", res.at("/request/query/operands/0/@type").asText());
+ assertEquals("koral:term", res.at("/request/query/operands/0/wrap/@type").asText());
+ assertEquals("orth", res.at("/request/query/operands/0/wrap/layer").asText());
+ assertEquals("a", res.at("/request/query/operands/0/wrap/key").asText());
+ assertEquals("match:eq", res.at("/request/query/operands/0/wrap/match").asText());
- assertEquals("koral:token", res.at("/request/query/operands/0/@type").asText());
- assertEquals("koral:term", res.at("/request/query/operands/0/wrap/@type").asText());
- assertEquals("orth", res.at("/request/query/operands/0/wrap/layer").asText());
- assertEquals("a", res.at("/request/query/operands/0/wrap/key").asText());
- assertEquals("match:eq", res.at("/request/query/operands/0/wrap/match").asText());
+ assertEquals("koral:token", res.at("/request/query/operands/1/@type").asText());
+ assertEquals("koral:term", res.at("/request/query/operands/1/wrap/@type").asText());
+ assertEquals("orth", res.at("/request/query/operands/1/wrap/layer").asText());
+ assertEquals("b", res.at("/request/query/operands/1/wrap/key").asText());
+ assertEquals("match:eq", res.at("/request/query/operands/1/wrap/match").asText());
- assertEquals("koral:token", res.at("/request/query/operands/1/@type").asText());
- assertEquals("koral:term", res.at("/request/query/operands/1/wrap/@type").asText());
- assertEquals("orth", res.at("/request/query/operands/1/wrap/layer").asText());
- assertEquals("b", res.at("/request/query/operands/1/wrap/key").asText());
- assertEquals("match:eq", res.at("/request/query/operands/1/wrap/match").asText());
-
- assertEquals(1, res.at("/matches/0/UID").asInt());
- assertEquals("doc-1", res.at("/matches/0/docID").asText());
- assertEquals("match-doc-1-p0-1", res.at("/matches/0/ID").asText());
- assertEquals("<span class=\"context-left\"></span><mark>a</mark><span class=\"context-right\">bab</span>", res.at("/matches/0/snippet").asText());
-
+ assertEquals(1, res.at("/matches/0/UID").asInt());
+ assertEquals("doc-1", res.at("/matches/0/docID").asText());
+ assertEquals("match-doc-1-p0-1", res.at("/matches/0/ID").asText());
+ assertEquals("<span class=\"context-left\"></span><mark>a</mark><span class=\"context-right\">bab</span>", res.at("/matches/0/snippet").asText());
};
-
@Test
public void checkJSONTokenResult () throws Exception {
- KorapIndex ki = new KorapIndex();
- FieldDocument fd = new FieldDocument();
- fd.addString("ID", "doc-1");
- fd.addString("UID", "1");
- fd.addTV("base",
- "abab",
- "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
- "[(1-2)s:b|i:b|_1#1-2]" +
- "[(2-3)s:a|i:c|_2#2-3]" +
- "[(3-4)s:b|i:a|_3#3-4]");
- ki.addDoc(fd);
- fd = new FieldDocument();
- fd.addString("ID", "doc-2");
- fd.addString("UID", "2");
- fd.addTV("base",
- "aba",
- "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
- "[(1-2)s:b|i:b|_1#1-2]" +
- "[(2-3)s:a|i:c|_2#2-3]");
- ki.addDoc(fd);
+ KorapIndex ki = new KorapIndex();
+ FieldDocument fd = new FieldDocument();
+ fd.addString("ID", "doc-1");
+ fd.addString("UID", "1");
+ fd.addTV("base",
+ "abab",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]" +
+ "[(3-4)s:b|i:a|_3#3-4]");
+ ki.addDoc(fd);
+ fd = new FieldDocument();
+ fd.addString("ID", "doc-2");
+ fd.addString("UID", "2");
+ fd.addTV("base",
+ "aba",
+ "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" +
+ "[(1-2)s:b|i:b|_1#1-2]" +
+ "[(2-3)s:a|i:c|_2#2-3]");
+ ki.addDoc(fd);
+
+ // Commit!
+ ki.commit();
- // Commit!
- ki.commit();
+ KorapQuery kq = new KorapQuery("base");
+ SpanQuery q = (SpanQuery) kq.seq(kq.seg("s:a")).append(kq.seg("s:b")).toQuery();
+ KorapResult kr = ki.search(q);
- KorapQuery kq = new KorapQuery("base");
- SpanQuery q = (SpanQuery) kq.seq(kq.seg("s:a")).append(kq.seg("s:b")).toQuery();
- KorapResult kr = ki.search(q);
+ assertEquals((long) 3, kr.getTotalResults());
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res = mapper.readTree(kr.toTokenListJsonString());
+ assertEquals(3, res.at("/totalResults").asInt());
+ assertEquals("spanNext(base:s:a, base:s:b)", res.at("/serialQuery").asText());
+ assertEquals(0, res.at("/startIndex").asInt());
+ assertEquals(25, res.at("/itemsPerPage").asInt());
- assertEquals((long) 3, kr.getTotalResults());
- ObjectMapper mapper = new ObjectMapper();
- JsonNode res = mapper.readTree(kr.toTokenListJsonString());
- assertEquals(3, res.at("/totalResults").asInt());
- assertEquals("spanNext(base:s:a, base:s:b)", res.at("/serialQuery").asText());
- assertEquals(0, res.at("/startIndex").asInt());
- assertEquals(25, res.at("/itemsPerPage").asInt());
+ assertEquals("doc-1", res.at("/matches/0/textSigle").asText());
+ assertEquals(0, res.at("/matches/0/tokens/0/0").asInt());
+ assertEquals(1, res.at("/matches/0/tokens/0/1").asInt());
+ assertEquals(1, res.at("/matches/0/tokens/1/0").asInt());
+ assertEquals(2, res.at("/matches/0/tokens/1/1").asInt());
- assertEquals("doc-1", res.at("/matches/0/textSigle").asText());
- assertEquals(0, res.at("/matches/0/tokens/0/0").asInt());
- assertEquals(1, res.at("/matches/0/tokens/0/1").asInt());
- assertEquals(1, res.at("/matches/0/tokens/1/0").asInt());
- assertEquals(2, res.at("/matches/0/tokens/1/1").asInt());
+ assertEquals("doc-1", res.at("/matches/1/textSigle").asText());
+ assertEquals(2, res.at("/matches/1/tokens/0/0").asInt());
+ assertEquals(3, res.at("/matches/1/tokens/0/1").asInt());
+ assertEquals(3, res.at("/matches/1/tokens/1/0").asInt());
+ assertEquals(4, res.at("/matches/1/tokens/1/1").asInt());
- assertEquals("doc-1", res.at("/matches/1/textSigle").asText());
- assertEquals(2, res.at("/matches/1/tokens/0/0").asInt());
- assertEquals(3, res.at("/matches/1/tokens/0/1").asInt());
- assertEquals(3, res.at("/matches/1/tokens/1/0").asInt());
- assertEquals(4, res.at("/matches/1/tokens/1/1").asInt());
-
- assertEquals("doc-2", res.at("/matches/2/textSigle").asText());
- assertEquals(0, res.at("/matches/2/tokens/0/0").asInt());
- assertEquals(1, res.at("/matches/2/tokens/0/1").asInt());
- assertEquals(1, res.at("/matches/2/tokens/1/0").asInt());
- assertEquals(2, res.at("/matches/2/tokens/1/1").asInt());
+ assertEquals("doc-2", res.at("/matches/2/textSigle").asText());
+ assertEquals(0, res.at("/matches/2/tokens/0/0").asInt());
+ assertEquals(1, res.at("/matches/2/tokens/0/1").asInt());
+ assertEquals(1, res.at("/matches/2/tokens/1/0").asInt());
+ assertEquals(2, res.at("/matches/2/tokens/1/1").asInt());
};
-
+
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();
+ 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/java/de/ids_mannheim/korap/search/TestKorapSearch.java b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
similarity index 95%
rename from src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
rename to src/test/java/de/ids_mannheim/korap/search/TestKrill.java
index a13f0bc..3079718 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
@@ -5,7 +5,7 @@
import static de.ids_mannheim.korap.TestSimple.*;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KorapCollection;
import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.KorapIndex;
@@ -29,10 +29,10 @@
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
-public class TestKorapSearch {
+public class TestKrill {
@Test
public void searchCount () {
- KorapSearch ks = new KorapSearch(
+ Krill ks = new Krill(
new KorapQuery("field1").seg("a").with("b")
);
// Count:
@@ -48,7 +48,7 @@
@Test
public void searchStartIndex () {
- KorapSearch ks = new KorapSearch(
+ Krill ks = new Krill(
new KorapQuery("field1").seg("a").with("b")
);
// startIndex
@@ -66,7 +66,7 @@
@Test
public void searchQuery () {
- KorapSearch ks = new KorapSearch(
+ Krill ks = new Krill(
new KorapQuery("field1").seg("a").with("b")
);
// query
@@ -93,7 +93,7 @@
};
ki.commit();
- KorapSearch ks = new KorapSearch(
+ Krill ks = new Krill(
new KorapQuery("tokens").seg("s:Buchstaben")
);
ks.getCollection().filter(
@@ -135,7 +135,7 @@
getClass().getResource("/queries/metaquery3.jsonld").getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 66);
assertEquals(5, kr.getItemsPerPage());
@@ -177,12 +177,12 @@
getClass().getResource("/queries/metaquery4.jsonld").getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1);
- ks = new KorapSearch(json);
+ ks = new Krill(json);
// Ignore the collection part of the query!
ks.setCollection(new KorapCollection());
kr = ks.apply(ki);
@@ -193,14 +193,14 @@
getClass().getResource("/queries/metaquery5.jsonld").getFile()
);
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1);
json = getString(
getClass().getResource("/queries/metaquery6.jsonld").getFile()
);
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1);
};
@@ -225,7 +225,7 @@
);
};
ki.commit();
- KorapResult kr = new KorapSearch("{ query").apply(ki);
+ KorapResult kr = new Krill("{ query").apply(ki);
assertEquals(kr.getTotalResults(), 0);
assertEquals(kr.getError(0).getMessage(), "Unable to parse JSON");
};
@@ -254,7 +254,7 @@
getClass().getResource("/queries/bsp-fail1.jsonld").getFile()
);
- KorapResult kr = new KorapSearch(json).apply(ki);
+ KorapResult kr = new Krill(json).apply(ki);
assertEquals(0, kr.getStartIndex());
assertEquals(kr.getTotalResults(), 0);
assertEquals(25, kr.getItemsPerPage());
@@ -284,7 +284,7 @@
getClass().getResource("/queries/bsp-fail2.jsonld").getFile()
);
- KorapResult kr = new KorapSearch(json).apply(ki);
+ KorapResult kr = new Krill(json).apply(ki);
assertEquals(50, kr.getItemsPerPage());
assertEquals(49950, kr.getStartIndex());
assertEquals(kr.getTotalResults(), 0);
@@ -314,7 +314,7 @@
getClass().getResource("/queries/bsp-context.jsonld").getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 10);
assertEquals("A bzw. a ist der erste Buchstabe des" +
@@ -334,7 +334,8 @@
getClass().getResource("/queries/bsp-context-2.jsonld").getFile()
);
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
+
assertEquals(kr.getTotalResults(), -1);
assertEquals("... lls seit den Griechen beibehalten worden." +
" 3. Bedeutungen in der Biologie steht A für"+
@@ -373,7 +374,7 @@
getClass().getResource("/queries/bsp-paging.jsonld").getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 10);
assertEquals(5, kr.getStartIndex());
@@ -382,7 +383,7 @@
json = getString(
getClass().getResource("/queries/bsp-cutoff.jsonld").getFile()
);
- ks = ks = new KorapSearch(json);
+ ks = ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), -1);
assertEquals(2, kr.getStartIndex());
@@ -421,7 +422,7 @@
getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 10);
assertEquals(0, kr.getStartIndex());
@@ -434,7 +435,7 @@
assertEquals("WPD_AAA.00002", kr.getMatch(8).getDocID());
assertEquals("WPD_AAA.00004", kr.getMatch(9).getDocID());
- ks = new KorapSearch(json);
+ ks = new Krill(json);
ks.setItemsPerResource(1);
kr = ks.apply(ki);
@@ -447,7 +448,7 @@
assertEquals(0, kr.getStartIndex());
assertEquals(20, kr.getItemsPerPage());
- ks = new KorapSearch(json);
+ ks = new Krill(json);
ks.setItemsPerResource(2);
kr = ks.apply(ki);
@@ -462,7 +463,7 @@
assertEquals(0, kr.getStartIndex());
assertEquals(20, kr.getItemsPerPage());
- ks = new KorapSearch(json);
+ ks = new Krill(json);
ks.setItemsPerResource(1);
ks.setStartIndex(1);
ks.setCount(1);
@@ -510,7 +511,7 @@
getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
ks.setItemsPerResource(1);
KorapCollection kc = new KorapCollection();
kc.filterUIDs(new String[]{"1", "4"});
@@ -599,7 +600,7 @@
assertNull(fd.getDocEditor());
assertNull(fd.getDocAuthor());
- KorapSearch ks = new KorapSearch(
+ Krill ks = new Krill(
new KorapQuery("tokens").
seg("mate/m:case:nom").
with("mate/m:number:pl")
@@ -690,7 +691,7 @@
assertNull(fd.getDocEditor());
assertNull(fd.getDocAuthor());
- KorapSearch ks = new KorapSearch(
+ Krill ks = new Krill(
new KorapQuery("tokens").
seg("mate/m:case:nom").
with("mate/m:number:sg")
@@ -724,7 +725,7 @@
);
KorapQuery kq = new KorapQuery("tokens");
- KorapSearch ks = new KorapSearch(
+ Krill ks = new Krill(
kq.focus(
1,
kq.contains(kq.tag("base/s:s"), kq._(1, kq.seg("s:Leben")))
@@ -743,7 +744,7 @@
);
// Try with high class - don't highlight
- ks = new KorapSearch(
+ ks = new Krill(
kq.focus(
129,
kq.contains(kq.tag("base/s:s"), kq._(129, kq.seg("s:Leben")))
@@ -761,7 +762,7 @@
"[Leben] gerufen hatten. Pressemeldungen zufolge haben sich ..."
);
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(
kr.getSerialQuery(),
@@ -806,7 +807,7 @@
getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapResult kr = ks.apply(ki);
assertEquals(
kr.getSerialQuery(),
@@ -851,7 +852,7 @@
getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapResult kr = ks.apply(ki);
ObjectMapper mapper = new ObjectMapper();
@@ -902,7 +903,7 @@
getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapCollection kc = ks.getCollection();
// No index was set
@@ -985,7 +986,7 @@
getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 276);
assertEquals(0, kr.getStartIndex());
@@ -997,7 +998,7 @@
getFile()
);
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 147);
@@ -1011,7 +1012,7 @@
getFile()
);
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 28);
@@ -1025,7 +1026,7 @@
getFile()
);
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 0);
@@ -1038,7 +1039,7 @@
getFile()
);
- ks = new KorapSearch(json);
+ ks = new Krill(json);
kr = ks.apply(ki);
assertEquals("filter with QueryWrapperFilter("+
@@ -1079,7 +1080,7 @@
getFile()
);
- KorapSearch ks = new KorapSearch(json);
+ Krill ks = new Krill(json);
ks.setCutOff(false);
SearchContext sc = ks.getContext();
sc.left.setLength((short) 10);
@@ -1101,7 +1102,7 @@
getFile()
);
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
assertEquals(
kr.getMatch(0).getSnippetBrackets(),
"steht a für den dezimalen [Wert] 97 sowohl im ASCII-"+
@@ -1150,7 +1151,7 @@
getFile()
);
- KorapResult kr = new KorapSearch(json).apply(ki);
+ KorapResult kr = new Krill(json).apply(ki);
assertEquals(
kr.getError(0).getMessage(),
@@ -1183,7 +1184,7 @@
getFile()
);
- KorapResult kr = new KorapSearch(json).apply(ki);
+ KorapResult kr = new Krill(json).apply(ki);
assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " +
"[der alte Digraph Aa durch Å] ersetzt worden, " +
"in Eigennamen und Ortsnamen ...",
@@ -1199,7 +1200,7 @@
getFile()
);
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " +
"[der alte Digraph Aa durch Å] ersetzt worden, " +
@@ -1229,7 +1230,7 @@
getFile()
);
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " +
"[der alte Digraph Aa durch Å] ersetzt worden, " +
@@ -1245,7 +1246,7 @@
getFile()
);
- kr = new KorapSearch(json).apply(ki);
+ kr = new Krill(json).apply(ki);
assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " +
"[der alte Digraph Aa durch Å] ersetzt worden, " +
"in Eigennamen und Ortsnamen ...",
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java b/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
index 4074176..f8994b0 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
@@ -5,7 +5,7 @@
import static de.ids_mannheim.korap.TestSimple.*;
-import de.ids_mannheim.korap.KorapSearch;
+import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KorapCollection;
import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.KorapIndex;
@@ -48,7 +48,7 @@
getClass().getResource("/queries/metas/fields.jsonld").getFile()
);
- KorapSearch ks = new KorapSearch(jsonString);
+ Krill ks = new Krill(jsonString);
KorapResult kr = ks.apply(ki);
assertEquals((long) 17, kr.getTotalResults());
@@ -75,7 +75,7 @@
jsonString = getString(
getClass().getResource("/queries/metas/fields_2.jsonld").getFile()
);
- ks = new KorapSearch(jsonString);
+ ks = new Krill(jsonString);
kr = ks.apply(ki);
assertEquals((long) 17, kr.getTotalResults());
assertEquals(0, kr.getStartIndex());