Streamlined json import a bit
diff --git a/Changes b/Changes
index 22f4a94..d8c8592 100644
--- a/Changes
+++ b/Changes
@@ -20,7 +20,9 @@
fixed a lot of wrong tests for WithinSpans,
renamed KorapFilter to /collection/CollectionBuilder,
renamed SpanMatchModify to SpanFocus,
- changed KoralQuery root prefix to "koral" (diewald)
+ changed KoralQuery root prefix to "koral",
+ renamed different kinds of "queries" throughout classes,
+ renamed KorapSearch#run to KorapSearch#apply (diewald)
- [feature] Improved deserialization of SpanSubSpanQueries
(margaretha)
- [feature] Introducing the potential need for resorting queries
diff --git a/src/main/java/de/ids_mannheim/korap/KorapCollection.java b/src/main/java/de/ids_mannheim/korap/KorapCollection.java
index 120580a..257e245 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapCollection.java
@@ -91,7 +91,7 @@
// Deserialize from recent collections
if (json.has("collection")) {
- this.fromJSON(json.get("collection"));
+ this.fromJson(json.get("collection"));
}
// Legacy collection serialization
@@ -102,7 +102,7 @@
"Collections are deprecated in favour of a single collection"
);
for (JsonNode collection : json.get("collections")) {
- this.fromJSONLegacy(collection);
+ this.fromJsonLegacy(collection);
};
};
}
@@ -135,14 +135,16 @@
* @param jsonString The "collection" part of a KoralQuery.
* @throws QueryException
*/
- public void fromJSON (String jsonString) throws QueryException {
+ public KorapCollection fromJson (String jsonString) throws QueryException {
ObjectMapper mapper = new ObjectMapper();
try {
- this.fromJSON((JsonNode) mapper.readTree(jsonString));
+ this.fromJson((JsonNode) mapper.readTree(jsonString));
}
catch (Exception e) {
this.addError(621, "Unable to parse JSON", "KorapCollection");
};
+
+ return this;
};
@@ -153,19 +155,20 @@
* as a {@link JsonNode} object.
* @throws QueryException
*/
- public void fromJSON (JsonNode json) throws QueryException {
- this.filter(this._fromJSON(json));
+ public KorapCollection fromJson (JsonNode json) throws QueryException {
+ this.filter(this._fromJson(json));
+ return this;
};
// Create a boolean filter from JSON
- private BooleanFilter _fromJSON (JsonNode json) throws QueryException {
- return this._fromJSON(json, "tokens");
+ private BooleanFilter _fromJson (JsonNode json) throws QueryException {
+ return this._fromJson(json, "tokens");
};
// Create a booleanfilter from JSON
- private BooleanFilter _fromJSON (JsonNode json, String field) throws QueryException {
+ private BooleanFilter _fromJson (JsonNode json, String field) throws QueryException {
BooleanFilter bfilter = new BooleanFilter();
// TODO: THIS UNFORTUNATELY BREAKS TESTS
@@ -237,10 +240,10 @@
for (JsonNode operand : json.get("operands")) {
if (operation.equals("operation:and"))
- group.and(this._fromJSON(operand, field));
+ group.and(this._fromJson(operand, field));
else if (operation.equals("operation:or"))
- group.or(this._fromJSON(operand, field));
+ group.or(this._fromJson(operand, field));
else
throw new QueryException(613, "Unknown document group operation");
@@ -264,14 +267,15 @@
* @throws QueryException
*/
@Deprecated
- public void fromJSONLegacy (String jsonString) throws QueryException {
+ public KorapCollection fromJsonLegacy (String jsonString) throws QueryException {
ObjectMapper mapper = new ObjectMapper();
try {
- this.fromJSONLegacy((JsonNode) mapper.readValue(jsonString, JsonNode.class));
+ this.fromJsonLegacy((JsonNode) mapper.readValue(jsonString, JsonNode.class));
}
catch (Exception e) {
this.addError(621, "Unable to parse JSON", "KorapCollection");
};
+ return this;
};
@@ -284,14 +288,14 @@
* @throws QueryException
*/
@Deprecated
- public void fromJSONLegacy (JsonNode json) throws QueryException {
+ public KorapCollection fromJsonLegacy (JsonNode json) throws QueryException {
if (!json.has("@type"))
throw new QueryException(701, "JSON-LD group has no @type attribute");
if (!json.has("@value"))
throw new QueryException(851, "Legacy filter need @value fields");
- BooleanFilter bf = this._fromJSONLegacy(json.get("@value"), "tokens");
+ BooleanFilter bf = this._fromJsonLegacy(json.get("@value"), "tokens");
String type = json.get("@type").asText();
// Filter the collection
@@ -307,12 +311,14 @@
log.trace("Add Extend LEGACY");
this.extend(bf);
};
+
+ return this;
};
// Create a boolean filter from a Json string
@Deprecated
- private BooleanFilter _fromJSONLegacy (JsonNode json, String field)
+ private BooleanFilter _fromJsonLegacy (JsonNode json, String field)
throws QueryException {
BooleanFilter bfilter = new BooleanFilter();
@@ -380,7 +386,7 @@
throw new QueryException(612, "Operation needs at least two operands");
for (JsonNode operand : operands) {
- group.and(this._fromJSONLegacy(operand, field));
+ group.and(this._fromJsonLegacy(operand, field));
};
bfilter.and(group);
break;
@@ -390,7 +396,7 @@
throw new QueryException(612, "Operation needs at least two operands");
for (JsonNode operand : operands) {
- group.or(this._fromJSONLegacy(operand, field));
+ group.or(this._fromJsonLegacy(operand, field));
};
bfilter.and(group);
break;
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index d64fd7f..6f9130b 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -1146,7 +1146,7 @@
collection.setIndex(this);
// Get the spanquery from the KorapSearch object
- SpanQuery query = ks.getQuery();
+ SpanQuery query = ks.getSpanQuery();
// Get the field of textual data and annotations ("tokens")
String field = query.getField();
@@ -1387,7 +1387,7 @@
this.termContexts = new HashMap<Term, TermContext>();
// Get span query
- SpanQuery query = ks.getQuery();
+ SpanQuery query = ks.getSpanQuery();
// Get the field of textual data and annotations
String field = query.getField();
diff --git a/src/main/java/de/ids_mannheim/korap/KorapResult.java b/src/main/java/de/ids_mannheim/korap/KorapResult.java
index 1cba877..8f4c1dc 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapResult.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapResult.java
@@ -39,7 +39,7 @@
public static final short ITEMS_PER_PAGE_MAX = 100;
private int startIndex = 0;
- private String query;
+ private String serialQuery;
private List<KorapMatch> matches;
@@ -67,7 +67,7 @@
/**
* Construct a new KorapResult object.
*
- * @param query Query representation as a string.
+ * @param serialQuery Query representation as a string.
* @param startIndex Offset position in match array.
* @param itemsPerPage Number of matches per page.
* @param context Requested {@link SearchContext}
@@ -82,7 +82,7 @@
// mapper.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
this.matches = new ArrayList<>(itemsPerPage);
- this.query = query;
+ this.serialQuery = query;
this.startIndex = startIndex;
this.itemsPerPage =
(itemsPerPage > ITEMS_PER_PAGE_MAX || itemsPerPage < 1) ?
@@ -187,8 +187,8 @@
*
* @return The string representation of the search query.
*/
- public String getQuery () {
- return this.query;
+ public String getSerialQuery () {
+ return this.serialQuery;
};
@@ -281,8 +281,8 @@
// TODO: <test>
if (this.request != null)
json.put("request", this.request);
- if (this.query != null)
- json.put("query", this.query);
+ if (this.serialQuery != null)
+ json.put("serialQuery", this.serialQuery);
// </test>
return json;
@@ -298,7 +298,7 @@
StringBuilder sb = new StringBuilder();
sb.append("Search for: ")
- .append(this.query)
+ .append(this.serialQuery)
.append("\n");
int i = 1;
diff --git a/src/main/java/de/ids_mannheim/korap/KorapSearch.java b/src/main/java/de/ids_mannheim/korap/KorapSearch.java
index 88100df..1021bb0 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapSearch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapSearch.java
@@ -15,31 +15,35 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
+/**
+ * Krill is a corpus data retrieval index using Lucene for Look-Ups.
+ * It is the reference implementation for KoralQuery consumption.
+ *
+ * <blockquote><pre>
+ * // Create a new krill search object passing a KoralQuery string
+ * Krill krill = new Krill(jsonString);
+ *
+ * // Run the query on an index
+ * KrillResult kr = krill.apply(new KrillIndex());
+ * </pre></blockquote>
+ *
+ * @author diewald
+ * @author margaretha
+ */
/*
- * Todo: Use configuration file
+ * Todo: Use a configuration file
* Todo: Let this class extend KorapResult!
* KorapResult = new KorapSearch(String json).run(KorapIndex ki);
* Todo: Set timeout default value per config file
*/
-/**
- * KorapSearch is the central class for parameterized searches
- * in the index, including the query, the collection,
- * and result parameters.
- *
- * @author diewald
- *
- */
public class KorapSearch extends Notifications {
- private int
- startIndex = 0,
- limit = 0;
- private short
- count = 25,
- countMax = 50;
+ private int startIndex = 0, limit = 0;
+ private short count = 25, countMax = 50, itemsPerResource = 0;
private boolean cutOff = false;
- private short itemsPerResource = 0;
- private SpanQuery query;
+
+ private SpanQuery spanQuery;
+
private KorapCollection collection;
private KorapIndex index;
@@ -47,6 +51,7 @@
private long timeout = (long) 120_000;
private HashSet<String> fields;
+ private HashSet<Integer> highlights;
private JsonNode request;
@@ -58,8 +63,9 @@
{
context = new SearchContext();
- // Lift legacy fields per default
fields = new HashSet<String>(16);
+
+ // Lift legacy fields per default
for (String field : new String[]{
"ID",
"UID",
@@ -76,153 +82,217 @@
"tokenization"}) {
fields.add(field);
};
+
+ // Classes used for highlights
+ highlights = new HashSet<Integer>(3);
};
- public KorapSearch (String jsonString) {
- ObjectMapper mapper = new ObjectMapper();
+ /**
+ * Construct a new Krill object.
+ */
+ public KorapSearch () {};
+
+
+ /**
+ * Construct a new Krill object,
+ * consuming a {@link SpanQueryWrapper} object.
+ *
+ * @param query The {@link SpanQueryWrapper} object.
+ */
+ public KorapSearch (SpanQueryWrapper query) {
try {
- // Todo - use correct method!
- this.request = mapper.readTree(jsonString);
-
- // "query" value
- if (this.request.has("query")) {
- try {
- KorapQuery kq = new KorapQuery("tokens");
- SpanQueryWrapper qw = kq.fromJson(this.request.get("query"));
-
- if (qw.isEmpty()) {
-
- // Unable to process result
- this.addError(780, "This query matches everywhere");
- }
- else {
- this.query = qw.toQuery();
- if (qw.isOptional())
- this.addWarning(781, "Optionality of query is ignored");
- if (qw.isNegative())
- this.addWarning(782, "Exclusivity of query is ignored");
-
- };
- // Copy notifications from query
- this.copyNotificationsFrom(kq);
- kq.clearNotifications();
- }
- catch (QueryException q) {
- this.addError(q.getErrorCode(), q.getMessage());
- };
- }
- else {
- this.addError(700, "No query given");
- };
-
- // <legacycode>
- if (this.request.has("warning") &&
- this.request.get("warning").asText().length() > 0) {
- this.addWarning(
- 799,
- this.request.get("warning").asText()
- );
- };
- // </legacycode>
-
- // <legacycode>
- if (this.request.has("warnings")) {
- JsonNode warnings = this.request.get("warnings");
- for (JsonNode node : warnings)
- if (node.asText().length() > 0)
- this.addWarning(799, node.asText());
- };
- // </legacycode>
-
- // Copy notifications from request
- this.copyNotificationsFrom(this.request);
-
- // virtual collections
- if (this.request.has("collection") ||
- // <legacycode>
- this.request.has("collections")
- // </legacycode>
- ) {
- this.setCollection(new KorapCollection(jsonString));
- };
-
- // No errors - go on with parsing
- if (!this.hasErrors()) {
- if (this.request.has("meta")) {
- JsonNode meta = this.request.get("meta");
-
- // Defined count
- if (meta.has("count"))
- this.setCount(meta.get("count").asInt());
-
- // Defined startIndex
- if (meta.has("startIndex"))
- this.setStartIndex(meta.get("startIndex").asInt());
-
- // Defined startPage
- if (meta.has("startPage"))
- this.setStartPage(meta.get("startPage").asInt());
-
- // Defined cutOff
- if (meta.has("cutOff"))
- this.setCutOff(meta.get("cutOff").asBoolean());
-
- // Defined contexts
- if (meta.has("context"))
- this.context.fromJson(meta.get("context"));
-
- // Defined resource count
- if (meta.has("timeout"))
- this.setTimeOut(meta.get("timeout").asLong());
-
- // Defined resource count
- if (meta.has("itemsPerResource"))
- this.setItemsPerResource(
- meta.get("itemsPerResource").asInt()
- );
-
- // Only lift a limited amount of fields from the metadata
- if (meta.has("fields")) {
-
- // Remove legacy default fields
- this.fields.clear();
-
- // Add fields
- if (meta.get("fields").isArray()) {
- for (JsonNode field : (JsonNode) meta.get("fields")) {
- this.addField(field.asText());
- };
- }
- else
- this.addField(meta.get("fields").asText());
- };
- };
- };
- }
-
- // Unable to parse JSON
- catch (IOException e) {
- this.addError(621, "Unable to parse JSON");
- };
- };
-
- // Maybe accept queryWrapperStuff
- public KorapSearch (SpanQueryWrapper sqwi) {
- try {
- this.query = sqwi.toQuery();
+ this.spanQuery = query.toQuery();
}
catch (QueryException q) {
this.addError(q.getErrorCode(), q.getMessage());
};
};
- public KorapSearch (SpanQuery sq) {
- this.query = sq;
+
+ /**
+ * Construct a new Krill object,
+ * consuming a {@link SpanQuery} object.
+ *
+ * @param query The {@link SpanQuery} object.
+ */
+ public KorapSearch (SpanQuery query) {
+ this.spanQuery = query;
};
- // Empty constructor
- public KorapSearch () { };
+
+ 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());
+ };
+ };
+
+
+ public KorapSearch fromJson (JsonNode json) throws QueryException {
+ // Parse "query" attribute
+ if (json.has("query")) {
+ try {
+ KorapQuery kq = new KorapQuery("tokens");
+ SpanQueryWrapper qw = kq.fromJson(json.get("query"));
+
+ // Unable to process result
+ if (qw.isEmpty())
+ this.addError(780, "This query matches everywhere");
+ else {
+ this.spanQuery = qw.toQuery();
+ if (qw.isOptional())
+ this.addWarning(781, "Optionality of query is ignored");
+ if (qw.isNegative())
+ this.addWarning(782, "Exclusivity of query is ignored");
+ };
+ // Copy notifications from query
+ this.copyNotificationsFrom(kq);
+ kq.clearNotifications();
+ }
+ catch (QueryException q) {
+ this.addError(q.getErrorCode(), q.getMessage());
+ };
+ }
+ else
+ this.addError(700, "No query given");
+
+ // <legacycode>
+ if (json.has("warning") &&
+ json.get("warning").asText().length() > 0) {
+ this.addWarning(799, json.get("warning").asText());
+ };
+ // </legacycode>
+
+ // <legacycode>
+ if (json.has("warnings")) {
+ JsonNode warnings = json.get("warnings");
+ for (JsonNode node : warnings)
+ if (node.asText().length() > 0)
+ this.addWarning(799, node.asText());
+ };
+ // </legacycode>
+
+ // Copy notifications from request
+ this.copyNotificationsFrom(json);
+
+ // virtual collections
+ 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);
+ };
+
+ this.setCollection(kc);
+ };
+ // </legacycode>
+
+
+ // No errors
+ if (!this.hasErrors()) {
+
+ // Parse meta section
+ if (json.has("meta")) {
+ JsonNode meta = json.get("meta");
+
+ // Defined count
+ if (meta.has("count"))
+ this.setCount(meta.get("count").asInt());
+
+ // Defined startIndex
+ if (meta.has("startIndex"))
+ this.setStartIndex(meta.get("startIndex").asInt());
+
+ // Defined startPage
+ if (meta.has("startPage"))
+ this.setStartPage(meta.get("startPage").asInt());
+
+ // Defined cutOff
+ if (meta.has("cutOff"))
+ this.setCutOff(meta.get("cutOff").asBoolean());
+
+ // Defined contexts
+ if (meta.has("context"))
+ this.context.fromJson(meta.get("context"));
+
+ // Defined resource count
+ if (meta.has("timeout"))
+ this.setTimeOut(meta.get("timeout").asLong());
+
+ // Defined resource count
+ if (meta.has("itemsPerResource"))
+ this.setItemsPerResource(
+ meta.get("itemsPerResource").asInt()
+ );
+
+ // Defined highlights
+ if (meta.has("highlight")) {
+
+ // Add highlights
+ if (meta.get("highlight").isArray()) {
+ for (JsonNode highlight : (JsonNode) meta.get("highlight")) {
+ this.addHighlight(highlight.asInt());
+ };
+ }
+ else
+ this.addHighlight(meta.get("highlight").asInt());
+ };
+
+ // Only lift a limited amount of fields from the metadata
+ if (meta.has("fields")) {
+
+ // Remove legacy default fields
+ this.fields.clear();
+
+ // Add fields
+ if (meta.get("fields").isArray()) {
+ for (JsonNode field : (JsonNode) meta.get("fields")) {
+ this.addField(field.asText());
+ };
+ }
+ else
+ this.addField(meta.get("fields").asText());
+ };
+ };
+ };
+ 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;
@@ -232,18 +302,18 @@
this.timeout = timeout;
};
- public SpanQuery getQuery () {
- return this.query;
+ public SpanQuery getSpanQuery () {
+ return this.spanQuery;
};
public JsonNode getRequest () {
return this.request;
};
- public KorapSearch setQuery (SpanQueryWrapper sqwi) {
+ public KorapSearch setSpanQuery (SpanQueryWrapper sqwi) {
// this.copyNotifications(sqwi);
try {
- this.query = sqwi.toQuery();
+ this.spanQuery = sqwi.toQuery();
}
catch (QueryException q) {
this.addError(q.getErrorCode(), q.getMessage());
@@ -251,8 +321,8 @@
return this;
};
- public KorapSearch setQuery (SpanQuery sq) {
- this.query = sq;
+ public KorapSearch setSpanQuery (SpanQuery sq) {
+ this.spanQuery = sq;
return this;
};
@@ -335,21 +405,44 @@
return this.itemsPerResource;
};
- // Add field to set of fields
+
+ // Get set of fields
+ /**
+ * Get the fields as a set
+ */
+ public HashSet<String> getFields () {
+ return this.fields;
+ };
+
+
+ /**
+ * Add a field to the set of fields to retrieve.
+ *
+ * @param field The field to retrieve.
+ * @return The {@link KorapSearch} object for chaining.
+ */
public KorapSearch addField (String field) {
this.fields.add(field);
return this;
};
- // Get set of fields
- public HashSet<String> getFields () {
- return this.fields;
+
+ /**
+ * Add class numbers to highlight in KWIC view.
+ *
+ * @param classNumber The number of a class to highlight.
+ * @return The {@link KorapSearch} object for chaining.
+ */
+ public KorapSearch addHighlight (int classNumber) {
+ this.highlights.add(classNumber);
+ return this;
};
+
public KorapSearch setCollection (KorapCollection kc) {
this.collection = kc;
- // Copy messages from the collection
+ // Move messages from the collection
this.copyNotificationsFrom(kc);
kc.clearNotifications();
return this;
@@ -361,8 +454,12 @@
return this.collection;
};
- public KorapResult run (KorapIndex ki) {
- if (this.query == null) {
+
+ /**
+ * Apply the KoralQuery to an index.
+ */
+ public KorapResult apply (KorapIndex ki) {
+ if (this.spanQuery == null) {
KorapResult kr = new KorapResult();
kr.setRequest(this.request);
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 f7043e7..bc70cd1 100644
--- a/src/main/java/de/ids_mannheim/korap/node/Resource.java
+++ b/src/main/java/de/ids_mannheim/korap/node/Resource.java
@@ -234,7 +234,7 @@
// Only return the first match per text
ks.setItemsPerResource(1);
- return ks.run(index).toJsonString();
+ return ks.apply(index).toJsonString();
};
KorapResult kr = new KorapResult();
kr.setNode(KorapNode.getName());
@@ -329,7 +329,7 @@
// Search index
if (index != null) {
- KorapResult kr = new KorapSearch(json).run(index);
+ KorapResult kr = new KorapSearch(json).apply(index);
kr.setNode(KorapNode.getName());
return kr.toJsonString();
};
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 17dea33..ce3e202 100644
--- a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
+++ b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
@@ -46,7 +46,7 @@
t1 = System.nanoTime();
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).run(ki);
+ kr = new KorapSearch(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).run(ki);
+ kr = new KorapSearch(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).run(ki);
+ kr = new KorapSearch(json).apply(ki);
};
t2 = System.nanoTime();
@@ -182,7 +182,7 @@
t1 = System.nanoTime();
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).run(ki);
+ kr = new KorapSearch(json).apply(ki);
};
t2 = System.nanoTime();
@@ -197,7 +197,7 @@
t1 = System.nanoTime();
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).run(ki);
+ kr = new KorapSearch(json).apply(ki);
};
t2 = System.nanoTime();
@@ -212,7 +212,7 @@
t1 = System.nanoTime();
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).run(ki);
+ kr = new KorapSearch(json).apply(ki);
};
t2 = System.nanoTime();
@@ -329,7 +329,7 @@
t1 = System.nanoTime();
for (int i = 1; i <= rounds; i++) {
- kr = new KorapSearch(json).run(ki);
+ kr = new KorapSearch(json).apply(ki);
};
t2 = System.nanoTime();
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 7e47153..0118e1b 100644
--- a/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
+++ b/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
@@ -282,8 +282,8 @@
String json = getString(getClass().getResource("/queries/bugs/greater_highlights_15.jsonld").getFile());
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
- assertEquals(kr.getQuery(),"{15: tokens:s:Alphabet}");
+ KorapResult kr = ks.apply(ki);
+ assertEquals(kr.getSerialQuery(),"{15: tokens:s:Alphabet}");
assertEquals(kr.getTotalResults(),7);
assertEquals(kr.getStartIndex(),0);
assertEquals(kr.getMatch(0).getSnippetBrackets(),"... 2. Herkunft Die aus dem proto-semitischen [{15:Alphabet}] stammende Urform des Buchstaben ist wahrscheinlich ...");
@@ -293,8 +293,8 @@
// 16
ks = new KorapSearch(json);
- kr = ks.run(ki);
- assertEquals(kr.getQuery(),"{16: tokens:s:Alphabet}");
+ kr = ks.apply(ki);
+ assertEquals(kr.getSerialQuery(),"{16: tokens:s:Alphabet}");
assertEquals(kr.getTotalResults(),7);
assertEquals(kr.getStartIndex(),0);
assertEquals(kr.getMatch(0).getSnippetBrackets(),"... 2. Herkunft Die aus dem proto-semitischen [{16:Alphabet}] stammende Urform des Buchstaben ist wahrscheinlich ...");
@@ -304,8 +304,8 @@
json = getString(getClass().getResource("/queries/bugs/greater_highlights_127.jsonld").getFile());
ks = new KorapSearch(json);
- kr = ks.run(ki);
- assertEquals(kr.getQuery(),"{127: tokens:s:Alphabet}");
+ kr = ks.apply(ki);
+ assertEquals(kr.getSerialQuery(),"{127: tokens:s:Alphabet}");
assertEquals(kr.getTotalResults(),7);
assertEquals(kr.getStartIndex(),0);
assertEquals(kr.getMatch(0).getSnippetBrackets(),"... 2. Herkunft Die aus dem proto-semitischen [{127:Alphabet}] stammende Urform des Buchstaben ist wahrscheinlich ...");
@@ -315,8 +315,8 @@
json = getString(getClass().getResource("/queries/bugs/greater_highlights_255.jsonld").getFile());
ks = new KorapSearch(json);
- kr = ks.run(ki);
- assertEquals(kr.getQuery(),"{255: tokens:s:Alphabet}");
+ kr = ks.apply(ki);
+ assertEquals(kr.getSerialQuery(),"{255: tokens:s:Alphabet}");
assertEquals(kr.getTotalResults(),7);
assertEquals(kr.getStartIndex(),0);
assertEquals(kr.getMatch(0).getSnippetBrackets(),"... 2. Herkunft Die aus dem proto-semitischen [Alphabet] stammende Urform des Buchstaben ist wahrscheinlich ...");
@@ -326,7 +326,7 @@
json = getString(getClass().getResource("/queries/bugs/greater_highlights_300.jsonld").getFile());
ks = new KorapSearch(json);
- kr = ks.run(ki);
+ 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 df3c6f3..04ea612 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
@@ -198,7 +198,7 @@
ks.context.left.setCharacter(true).setLength(6);
ks.context.right.setToken(true).setLength(6);
- assertEquals("... okal. [Der Buchstabe A hat in {1:deutschen Texten} eine durchschnittliche Häufigkeit von 6,51 %.] Er ist damit der sechsthäufigste Buchstabe ...", ks.run(ki).getMatch(0).getSnippetBrackets());
+ assertEquals("... okal. [Der Buchstabe A hat in {1:deutschen Texten} eine durchschnittliche Häufigkeit von 6,51 %.] Er ist damit der sechsthäufigste Buchstabe ...", ks.apply(ki).getMatch(0).getSnippetBrackets());
};
@Test
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
index c3ad7c7..90c88f3 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
@@ -388,7 +388,7 @@
);
kr = ki.search(sq, (short) 10);
- assertEquals(kr.getQuery(), "spanContain({2: <base:s />}, {3: base:s:b})");
+ assertEquals(kr.getSerialQuery(), "spanContain({2: <base:s />}, {3: base:s:b})");
assertEquals(kr.getMatch(0).getSnippetBrackets(), "a[{2:{3:b}cab}]cabac");
sq = new SpanFocusQuery(
@@ -399,7 +399,7 @@
);
kr = ki.search(sq, (short) 10);
- assertEquals(kr.getQuery(), "focus(3: spanContain({2: <base:s />}, {3: base:s:b}))");
+ assertEquals(kr.getSerialQuery(), "focus(3: spanContain({2: <base:s />}, {3: base:s:b}))");
assertEquals(kr.getMatch(0).getSnippetBrackets(), "a[{3:b}]cabcab ...");
};
@@ -491,7 +491,7 @@
// System.err.println(kr.getOverview());
- assertEquals(kr.getQuery(), "spanContain(<base:p />, focus(3: spanContain({2: <base:s />}, {3: base:s:a})))");
+ assertEquals(kr.getSerialQuery(), "spanContain(<base:p />, focus(3: spanContain({2: <base:s />}, {3: base:s:a})))");
assertEquals(12, kr.getTotalResults());
assertEquals("[a{2:bc{3:a}b}cabac]", kr.getMatch(0).getSnippetBrackets());
assertEquals("[ab{2:c{3:a}bcab}ac]", kr.getMatch(1).getSnippetBrackets());
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 070665e..7d0fc46 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
@@ -38,7 +38,7 @@
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.setTimeOut(10000);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
System.err.println(kr.toJsonString());
assertEquals(8, kr.getTotalResults());
};
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 ef34315..20273bc 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
@@ -61,22 +61,22 @@
assertEquals("[affe] afffe ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("affe [afffe] baum ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").re("s:baum.*").toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").re("s:baum.*").toQuery()));
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... afffe [baum] baumgarten ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... baum [baumgarten] steingarten ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").re("s:.....?garten").toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").re("s:.....?garten").toQuery()));
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... baum [baumgarten] steingarten ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... baumgarten [steingarten] franz ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").re("s:ha.s").toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").re("s:ha.s").toQuery()));
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... franz [hans] haus ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... hans [haus] efeu ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").re("s:.*ff.*").toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").re("s:.*ff.*").toQuery()));
assertEquals((long) 3, kr.getTotalResults());
assertEquals("[affe] afffe ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("affe [afffe] baum ...", kr.getMatch(1).getSnippetBrackets());
@@ -118,25 +118,25 @@
assertEquals("[affe] afffe ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("affe [afffe] baum ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").wc("s:baum.*").toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").wc("s:baum.*").toQuery()));
assertEquals((long) 0, kr.getTotalResults());
- kr = ki.search(ks.setQuery(new KorapQuery("base").wc("s:baum*").toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").wc("s:baum*").toQuery()));
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... afffe [baum] baumgarten ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... baum [baumgarten] steingarten ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").wc("s:*garten").toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").wc("s:*garten").toQuery()));
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... baum [baumgarten] steingarten ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... baumgarten [steingarten] franz ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").wc("s:ha?s").toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").wc("s:ha?s").toQuery()));
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... franz [hans] haus ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... hans [haus] efeu ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").wc("s:?ff?").toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").wc("s:?ff?").toQuery()));
assertEquals((long) 2, kr.getTotalResults());
assertEquals("[affe] afffe ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... efeu [effe]", kr.getMatch(1).getSnippetBrackets());
@@ -177,30 +177,30 @@
assertEquals("[AfFe] aFfFE ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("AfFe [aFfFE] Baum ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").re("s:Af.*e").toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").re("s:Af.*e").toQuery()));
assertEquals((long) 1, kr.getTotalResults());
assertEquals("[AfFe] aFfFE ...", kr.getMatch(0).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").re("s:baum.*", true).toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").re("s:baum.*", true).toQuery()));
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... aFfFE [Baum] Baumgarten ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... Baum [Baumgarten] SteinGarten ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").re("s:.*garten", true).toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").re("s:.*garten", true).toQuery()));
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... Baum [Baumgarten] SteinGarten ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... Baumgarten [SteinGarten] franZ ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").re("s:.*garten", false).toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").re("s:.*garten", false).toQuery()));
assertEquals((long) 1, kr.getTotalResults());
assertEquals("... Baum [Baumgarten] SteinGarten ...", kr.getMatch(0).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").re("s:ha.s", true).toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").re("s:ha.s", true).toQuery()));
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... franZ [HaNs] Haus ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... HaNs [Haus] Efeu ...", kr.getMatch(1).getSnippetBrackets());
- kr = ki.search(ks.setQuery(new KorapQuery("base").re("s:.*f*e", true).toQuery()));
+ kr = ki.search(ks.setSpanQuery(new KorapQuery("base").re("s:.*f*e", true).toQuery()));
assertEquals((long) 3, kr.getTotalResults());
assertEquals("[AfFe] aFfFE ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("AfFe [aFfFE] Baum ...", kr.getMatch(1).getSnippetBrackets());
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 5d8b5d2..6711653 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
@@ -71,18 +71,18 @@
// ordered
sq = createDistanceQuery("s:Wir", "s:kommen", 1, 1, true,false);
ks = new KorapSearch(sq);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 8);
// unordered
sq = createDistanceQuery("s:Wir", "s:kommen", 1, 1, false,false);
ks = new KorapSearch(sq);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 11);
sq = createDistanceQuery("s:kommen", "s:Wir", 1, 1, false,false);
ks = new KorapSearch(sq);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 11);
//System.out.println(kr.getTotalResults());
//for (KorapMatch km : kr.getMatches()){
@@ -98,20 +98,20 @@
SpanQuery q = new SpanTermQuery(new Term("tokens","s:Wir"));
ks = new KorapSearch(q);
- kr = ks.run(ki);
+ 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);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1899);
// unordered
sq = createDistanceQuery("s:Wir", "s:kommen", 1, 1, false, true);
ks = new KorapSearch(sq);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1896);
}
@@ -122,13 +122,13 @@
SpanDistanceQuery sq = createElementDistanceQuery("s","s:weg", "s:fahren",
0, 1, true, false);
ks = new KorapSearch(sq);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 3);
// unordered
sq = createElementDistanceQuery("s","s:weg", "s:fahren", 0, 1, false,false);
ks = new KorapSearch(sq);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 5);
// only 0
@@ -145,7 +145,7 @@
// only 1
sq = createElementDistanceQuery("s","s:weg", "s:fahren", 1, 1, false,false);
ks = new KorapSearch(sq);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 3);
}
@@ -154,7 +154,7 @@
public void testCase4() throws IOException{
SpanDistanceQuery sq = createElementDistanceQuery("s","s:weg", "s:fahren", 1, 1, false, true);
ks = new KorapSearch(sq);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 979);
//0.8s
@@ -164,7 +164,7 @@
KorapCollection kc = new KorapCollection();
kc.filter(bf);
ks.setCollection(kc);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(1094,kr.getMatch(0).getStartPos());
assertEquals(451,kr.getMatch(1).getEndPos());
}
@@ -175,18 +175,18 @@
SpanQuery sq;
sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens","mate/p:ADJA")),1,2, true);
ks = new KorapSearch(sq);
- kr = ks.run(ki);
+ 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);
- kr = ks.run(ki);
+ 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);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 236745);
//0.65s
}
@@ -199,14 +199,14 @@
new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens","mate/p:ADJA")),2,2, true)
);
ks = new KorapSearch(sq);
- kr = ks.run(ki);
+ 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);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 26607);
// 1.1s
}
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 33a776a..73ada81 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
@@ -53,8 +53,8 @@
json = getString(getClass().getResource("/queries/bugs/cosmas_classrefcheck.jsonld").getFile());
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
- assertEquals(kr.getQuery(),"focus(130: {131: spanContain({129: <tokens:s />}, {130: tokens:s:wegen})})");
+ KorapResult kr = ks.apply(ki);
+ assertEquals(kr.getSerialQuery(),"focus(130: {131: spanContain({129: <tokens:s />}, {130: tokens:s:wegen})})");
assertEquals(kr.getTotalResults(),0);
assertEquals(kr.getStartIndex(),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 f07b184..80776b5 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapResult.java
@@ -62,7 +62,7 @@
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("/query").asText());
+ 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());
@@ -112,7 +112,7 @@
String json = getString(getClass().getResource("/queries/bugs/optionality_warning.jsonld").getFile());
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals((long) 2, kr.getTotalResults());
ObjectMapper mapper = new ObjectMapper();
@@ -154,14 +154,14 @@
String json = getString(getClass().getResource("/queries/bsp-result-check.jsonld").getFile());
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals((long) 7, kr.getTotalResults());
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("/query").asText());
+ 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());
@@ -228,7 +228,7 @@
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("/query").asText());
+ assertEquals("spanNext(base:s:a, base:s:b)", res.at("/serialQuery").asText());
assertEquals(0, res.at("/startIndex").asInt());
assertEquals(25, res.at("/itemsPerPage").asInt());
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 b5f3dcf..a13f0bc 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
@@ -70,7 +70,7 @@
new KorapQuery("field1").seg("a").with("b")
);
// query
- assertEquals(ks.getQuery().toString(), "spanSegment(field1:a, field1:b)");
+ assertEquals(ks.getSpanQuery().toString(), "spanSegment(field1:a, field1:b)");
};
@@ -103,7 +103,7 @@
ks.setStartIndex(5);
ks.context.left.setLength(1);
ks.context.right.setLength(1);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 6);
assertEquals(
kr.getMatch(0).getSnippetBrackets(),
@@ -136,7 +136,7 @@
);
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 66);
assertEquals(5, kr.getItemsPerPage());
assertEquals(5, kr.getStartIndex());
@@ -178,14 +178,14 @@
);
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1);
ks = new KorapSearch(json);
// Ignore the collection part of the query!
ks.setCollection(new KorapCollection());
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 5);
@@ -194,14 +194,14 @@
);
ks = new KorapSearch(json);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1);
json = getString(
getClass().getResource("/queries/metaquery6.jsonld").getFile()
);
ks = new KorapSearch(json);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 1);
};
@@ -225,7 +225,7 @@
);
};
ki.commit();
- KorapResult kr = new KorapSearch("{ query").run(ki);
+ KorapResult kr = new KorapSearch("{ 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).run(ki);
+ KorapResult kr = new KorapSearch(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).run(ki);
+ KorapResult kr = new KorapSearch(json).apply(ki);
assertEquals(50, kr.getItemsPerPage());
assertEquals(49950, kr.getStartIndex());
assertEquals(kr.getTotalResults(), 0);
@@ -315,7 +315,7 @@
);
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 10);
assertEquals("A bzw. a ist der erste Buchstabe des" +
" lateinischen [Alphabets] und ein Vokal." +
@@ -325,7 +325,7 @@
ks.setCount(5);
ks.setStartPage(2);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 10);
assertEquals(5, kr.getStartIndex());
assertEquals(5, kr.getItemsPerPage());
@@ -334,7 +334,7 @@
getClass().getResource("/queries/bsp-context-2.jsonld").getFile()
);
- kr = new KorapSearch(json).run(ki);
+ kr = new KorapSearch(json).apply(ki);
assertEquals(kr.getTotalResults(), -1);
assertEquals("... lls seit den Griechen beibehalten worden." +
" 3. Bedeutungen in der Biologie steht A für"+
@@ -374,7 +374,7 @@
);
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 10);
assertEquals(5, kr.getStartIndex());
assertEquals(5, kr.getItemsPerPage());
@@ -383,7 +383,7 @@
getClass().getResource("/queries/bsp-cutoff.jsonld").getFile()
);
ks = ks = new KorapSearch(json);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), -1);
assertEquals(2, kr.getStartIndex());
assertEquals(2, kr.getItemsPerPage());
@@ -422,7 +422,7 @@
);
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 10);
assertEquals(0, kr.getStartIndex());
assertEquals(20, kr.getItemsPerPage());
@@ -437,7 +437,7 @@
ks = new KorapSearch(json);
ks.setItemsPerResource(1);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals("WPD_AAA.00001", kr.getMatch(0).getDocID());
assertEquals("WPD_AAA.00002", kr.getMatch(1).getDocID());
@@ -450,7 +450,7 @@
ks = new KorapSearch(json);
ks.setItemsPerResource(2);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals("WPD_AAA.00001", kr.getMatch(0).getDocID());
assertEquals("WPD_AAA.00001", kr.getMatch(1).getDocID());
@@ -467,7 +467,7 @@
ks.setStartIndex(1);
ks.setCount(1);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals("WPD_AAA.00002", kr.getMatch(0).getDocID());
@@ -517,7 +517,7 @@
kc.setIndex(ki);
ks.setCollection(kc);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 2);
assertEquals(0, kr.getStartIndex());
@@ -604,7 +604,7 @@
seg("mate/m:case:nom").
with("mate/m:number:pl")
);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 148);
assertEquals(0, kr.getStartIndex());
@@ -695,7 +695,7 @@
seg("mate/m:case:nom").
with("mate/m:number:sg")
);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 6);
assertEquals(0, kr.getStartIndex());
@@ -731,9 +731,9 @@
)
);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(
- kr.getQuery(),
+ kr.getSerialQuery(),
"focus(1: spanContain(<tokens:base/s:s />, {1: tokens:s:Leben}))"
);
assertEquals(
@@ -750,9 +750,9 @@
)
);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(
- kr.getQuery(),
+ kr.getSerialQuery(),
"focus(129: spanContain(<tokens:base/s:s />, {129: tokens:s:Leben}))"
);
assertEquals(
@@ -762,9 +762,9 @@
);
ks = new KorapSearch(json);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(
- kr.getQuery(),
+ kr.getSerialQuery(),
"focus(129: spanElementDistance({129: tokens:s:Namen}, " +
"{129: tokens:s:Leben}, [(base/s:s[0:1], notOrdered, notExcluded)]))"
);
@@ -807,9 +807,9 @@
);
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(
- kr.getQuery(),
+ kr.getSerialQuery(),
"{4: spanNext({1: spanNext({2: tokens:s:ins}, "+
"{3: tokens:s:Leben})}, tokens:s:gerufen)}"
);
@@ -852,7 +852,7 @@
);
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
ObjectMapper mapper = new ObjectMapper();
JsonNode res = mapper.readTree(kr.toTokenListJsonString());
@@ -861,7 +861,7 @@
assertEquals(
"{4: spanNext({1: spanNext({2: tokens:s:ins}, " +
"{3: tokens:s:Leben})}, tokens:s:gerufen)}",
- res.at("/query").asText());
+ res.at("/serialQuery").asText());
assertEquals(0, res.at("/startIndex").asInt());
assertEquals(25, res.at("/itemsPerPage").asInt());
@@ -918,10 +918,10 @@
ks.setCollection(kc);
assertEquals(1, kc.numberOf("documents"));
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(
- kr.getQuery(),
+ kr.getSerialQuery(),
"spanOr([SpanMultiTermQueryWrapper(tokens:/tt/p:N.*/), " +
"spanNext(spanRepetition(SpanMultiTermQueryWrapper"+
"(tokens:/tt/p:A.*/){1,3}), " +
@@ -986,7 +986,7 @@
);
KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 276);
assertEquals(0, kr.getStartIndex());
assertEquals(10, kr.getItemsPerPage());
@@ -998,7 +998,7 @@
);
ks = new KorapSearch(json);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 147);
assertEquals("WPD_AAA.00001", kr.getMatch(0).getDocID());
@@ -1012,7 +1012,7 @@
);
ks = new KorapSearch(json);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 28);
assertEquals("WPD_AAA.00002", kr.getMatch(0).getDocID());
@@ -1026,7 +1026,7 @@
);
ks = new KorapSearch(json);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 0);
assertEquals(0, kr.getStartIndex());
@@ -1039,7 +1039,7 @@
);
ks = new KorapSearch(json);
- kr = ks.run(ki);
+ kr = ks.apply(ki);
assertEquals("filter with QueryWrapperFilter("+
"+(ID:WPD_AAA.00003 (+tokens:s:die"+
@@ -1085,7 +1085,7 @@
sc.left.setLength((short) 10);
sc.right.setLength((short) 10);
- KorapResult kr = ks.run(ki);
+ KorapResult kr = ks.apply(ki);
assertEquals(
kr.getMatch(1).getSnippetBrackets(),
"... dezimalen [Wert] 65 sowohl ..."
@@ -1101,7 +1101,7 @@
getFile()
);
- kr = new KorapSearch(json).run(ki);
+ kr = new KorapSearch(json).apply(ki);
assertEquals(
kr.getMatch(0).getSnippetBrackets(),
"steht a für den dezimalen [Wert] 97 sowohl im ASCII-"+
@@ -1150,7 +1150,7 @@
getFile()
);
- KorapResult kr = new KorapSearch(json).run(ki);
+ KorapResult kr = new KorapSearch(json).apply(ki);
assertEquals(
kr.getError(0).getMessage(),
@@ -1183,7 +1183,7 @@
getFile()
);
- KorapResult kr = new KorapSearch(json).run(ki);
+ KorapResult kr = new KorapSearch(json).apply(ki);
assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " +
"[der alte Digraph Aa durch Å] ersetzt worden, " +
"in Eigennamen und Ortsnamen ...",
@@ -1199,7 +1199,7 @@
getFile()
);
- kr = new KorapSearch(json).run(ki);
+ kr = new KorapSearch(json).apply(ki);
assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " +
"[der alte Digraph Aa durch Å] ersetzt worden, " +
@@ -1229,7 +1229,7 @@
getFile()
);
- kr = new KorapSearch(json).run(ki);
+ kr = new KorapSearch(json).apply(ki);
assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " +
"[der alte Digraph Aa durch Å] ersetzt worden, " +
@@ -1245,7 +1245,7 @@
getFile()
);
- kr = new KorapSearch(json).run(ki);
+ kr = new KorapSearch(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 387b2cb..4074176 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
@@ -33,68 +33,69 @@
@Test
public void searchMetaFields () throws IOException {
- // Construct index
- KorapIndex ki = new KorapIndex();
- // Indexing test files
- for (String i : new String[] {"00001",
- "00002"}) {
- ki.addDocFile(
- getClass().getResource("/wiki/" + i + ".json.gz").getFile(), true
+ // Construct index
+ KorapIndex ki = new KorapIndex();
+ // Indexing test files
+ for (String i : new String[] {"00001",
+ "00002"}) {
+ ki.addDocFile(
+ getClass().getResource("/wiki/" + i + ".json.gz").getFile(), true
);
- };
- ki.commit();
+ };
+ ki.commit();
- String json = getString(
+ String jsonString = getString(
getClass().getResource("/queries/metas/fields.jsonld").getFile()
);
- KorapSearch ks = new KorapSearch(json);
- KorapResult kr = ks.run(ki);
- assertEquals((long) 17, kr.getTotalResults());
- assertEquals(0, kr.getStartIndex());
- assertEquals(9, kr.getItemsPerPage());
+ KorapSearch ks = new KorapSearch(jsonString);
- ObjectMapper mapper = new ObjectMapper();
- JsonNode res = mapper.readTree(kr.toJsonString());
- assertEquals(0, res.at("/matches/0/UID").asInt());
- assertEquals("WPD", res.at("/matches/0/corpusID").asText());
- assertEquals("", res.at("/matches/0/docID").asText());
- assertEquals("", res.at("/matches/0/textSigle").asText());
- assertEquals("", res.at("/matches/0/ID").asText());
- assertEquals("", res.at("/matches/0/author").asText());
- assertEquals("", res.at("/matches/0/title").asText());
- assertEquals("", res.at("/matches/0/subTitle").asText());
- assertEquals("", res.at("/matches/0/textClass").asText());
- assertEquals("", res.at("/matches/0/pubPlace").asText());
- assertEquals("", res.at("/matches/0/pubDate").asText());
- assertEquals("", res.at("/matches/0/foundries").asText());
- assertEquals("", res.at("/matches/0/layerInfo").asText());
- assertEquals("", res.at("/matches/0/tokenization").asText());
+ KorapResult kr = ks.apply(ki);
+ assertEquals((long) 17, kr.getTotalResults());
+ assertEquals(0, kr.getStartIndex());
+ assertEquals(9, kr.getItemsPerPage());
+
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res = mapper.readTree(kr.toJsonString());
+ assertEquals(0, res.at("/matches/0/UID").asInt());
+ assertEquals("WPD", res.at("/matches/0/corpusID").asText());
+ assertEquals("", res.at("/matches/0/docID").asText());
+ assertEquals("", res.at("/matches/0/textSigle").asText());
+ assertEquals("", res.at("/matches/0/ID").asText());
+ assertEquals("", res.at("/matches/0/author").asText());
+ assertEquals("", res.at("/matches/0/title").asText());
+ assertEquals("", res.at("/matches/0/subTitle").asText());
+ assertEquals("", res.at("/matches/0/textClass").asText());
+ assertEquals("", res.at("/matches/0/pubPlace").asText());
+ assertEquals("", res.at("/matches/0/pubDate").asText());
+ assertEquals("", res.at("/matches/0/foundries").asText());
+ assertEquals("", res.at("/matches/0/layerInfo").asText());
+ assertEquals("", res.at("/matches/0/tokenization").asText());
- json = getString(
+ jsonString = getString(
getClass().getResource("/queries/metas/fields_2.jsonld").getFile()
);
- ks = new KorapSearch(json);
- kr = ks.run(ki);
- assertEquals((long) 17, kr.getTotalResults());
- assertEquals(0, kr.getStartIndex());
- assertEquals(2, kr.getItemsPerPage());
-
- mapper = new ObjectMapper();
- res = mapper.readTree(kr.toJsonString());
- assertEquals(0, res.at("/matches/0/UID").asInt());
- assertEquals("", res.at("/matches/0/corpusID").asText());
- assertEquals("Ruru,Jens.Ol,Aglarech", res.at("/matches/0/author").asText());
- assertEquals("A", res.at("/matches/0/title").asText());
- assertEquals("WPD_AAA.00001", res.at("/matches/0/docID").asText());
- assertEquals("", res.at("/matches/0/textSigle").asText());
- assertEquals("match-WPD_AAA.00001-p6-7", res.at("/matches/0/ID").asText());
- assertEquals("", res.at("/matches/0/subTitle").asText());
- assertEquals("", res.at("/matches/0/textClass").asText());
- assertEquals("", res.at("/matches/0/pubPlace").asText());
- assertEquals("", res.at("/matches/0/pubDate").asText());
- assertEquals("", res.at("/matches/0/foundries").asText());
- assertEquals("", res.at("/matches/0/layerInfo").asText());
- assertEquals("", res.at("/matches/0/tokenization").asText());
+ ks = new KorapSearch(jsonString);
+ kr = ks.apply(ki);
+ assertEquals((long) 17, kr.getTotalResults());
+ assertEquals(0, kr.getStartIndex());
+ assertEquals(2, kr.getItemsPerPage());
+
+ mapper = new ObjectMapper();
+ res = mapper.readTree(kr.toJsonString());
+ assertEquals(0, res.at("/matches/0/UID").asInt());
+ assertEquals("", res.at("/matches/0/corpusID").asText());
+ assertEquals("Ruru,Jens.Ol,Aglarech", res.at("/matches/0/author").asText());
+ assertEquals("A", res.at("/matches/0/title").asText());
+ assertEquals("WPD_AAA.00001", res.at("/matches/0/docID").asText());
+ assertEquals("", res.at("/matches/0/textSigle").asText());
+ assertEquals("match-WPD_AAA.00001-p6-7", res.at("/matches/0/ID").asText());
+ assertEquals("", res.at("/matches/0/subTitle").asText());
+ assertEquals("", res.at("/matches/0/textClass").asText());
+ assertEquals("", res.at("/matches/0/pubPlace").asText());
+ assertEquals("", res.at("/matches/0/pubDate").asText());
+ assertEquals("", res.at("/matches/0/foundries").asText());
+ assertEquals("", res.at("/matches/0/layerInfo").asText());
+ assertEquals("", res.at("/matches/0/tokenization").asText());
};
};