Added some JavaDocs to API classes
diff --git a/Changes b/Changes
index bb99706..a2f7ddf 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,7 @@
+0.49.3 2014-01-15
+ - [documentation] Improved documentation for API classes (diewald)
+ - [documentation] Improved documentation for various queries (margaretha)
+
0.49.2 2014-12-05
- [documentation] Improved documentation for various queries (margaretha)
- [feature] Added @Experimental support (margaretha)
diff --git a/pom.xml b/pom.xml
index 8bf1d63..bbcfb33 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<groupId>KorAP-modules</groupId>
<artifactId>KorAP-lucene-index</artifactId>
- <version>0.49.2</version>
+ <version>0.49.3</version>
<packaging>jar</packaging>
<name>KorAP-lucene-index</name>
diff --git a/src/main/java/de/ids_mannheim/korap/KorapCollection.java b/src/main/java/de/ids_mannheim/korap/KorapCollection.java
index eca212f..e7b8d02 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapCollection.java
@@ -58,8 +58,8 @@
public static final boolean DEBUG = false;
public KorapCollection (KorapIndex ki) {
- this.index = ki;
- this.filter = new ArrayList<FilterOperation>(5);
+ this.index = ki;
+ this.filter = new ArrayList<FilterOperation>(5);
};
/**
@@ -68,60 +68,60 @@
* legacy collections with the key "collections".
*/
public KorapCollection (String jsonString) {
- ObjectMapper mapper = new ObjectMapper();
- this.filter = new ArrayList<FilterOperation>(5);
+ ObjectMapper mapper = new ObjectMapper();
+ this.filter = new ArrayList<FilterOperation>(5);
- try {
- JsonNode json = mapper.readTree(jsonString);
+ try {
+ JsonNode json = mapper.readTree(jsonString);
- if (json.has("collection")) {
- this.fromJSON(json.get("collection"));
- }
+ if (json.has("collection")) {
+ this.fromJSON(json.get("collection"));
+ }
- // Legacy collection serialization
- // This will be removed!
- else if (json.has("collections")) {
- this.addMessage(
- 850,
- "Collections are deprecated in favour of a single collection"
+ // Legacy collection serialization
+ // This will be removed!
+ else if (json.has("collections")) {
+ this.addMessage(
+ 850,
+ "Collections are deprecated in favour of a single collection"
);
- for (JsonNode collection : json.get("collections")) {
- this.fromJSONLegacy(collection);
- };
- };
- }
- catch (QueryException qe) {
- this.addError(qe.getErrorCode(),qe.getMessage());
- }
- catch (IOException e) {
- this.addError(
- 621,
- "Unable to parse JSON",
- "KorapCollection",
- e.getLocalizedMessage()
- );
- };
+ for (JsonNode collection : json.get("collections")) {
+ this.fromJSONLegacy(collection);
+ };
+ };
+ }
+ catch (QueryException qe) {
+ this.addError(qe.getErrorCode(),qe.getMessage());
+ }
+ catch (IOException e) {
+ this.addError(
+ 621,
+ "Unable to parse JSON",
+ "KorapCollection",
+ e.getLocalizedMessage()
+ );
+ };
};
public KorapCollection () {
- this.filter = new ArrayList<FilterOperation>(5);
+ this.filter = new ArrayList<FilterOperation>(5);
};
public void fromJSON (String jsonString) throws QueryException {
- ObjectMapper mapper = new ObjectMapper();
- try {
- this.fromJSON((JsonNode) mapper.readTree(jsonString));
- }
- catch (Exception e) {
- this.addError(621, "Unable to parse JSON", "KorapCollection");
- };
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ this.fromJSON((JsonNode) mapper.readTree(jsonString));
+ }
+ catch (Exception e) {
+ this.addError(621, "Unable to parse JSON", "KorapCollection");
+ };
};
public void fromJSON (JsonNode json) throws QueryException {
- this.filter(new KorapFilter(json));
+ this.filter(new KorapFilter(json));
};
@@ -129,13 +129,13 @@
* Legacy API for collection filters.
*/
public void fromJSONLegacy (String jsonString) throws QueryException {
- ObjectMapper mapper = new ObjectMapper();
- try {
- this.fromJSONLegacy((JsonNode) mapper.readValue(jsonString, JsonNode.class));
- }
- catch (Exception e) {
- this.addError(621, "Unable to parse JSON", "KorapCollection");
- };
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ this.fromJSONLegacy((JsonNode) mapper.readValue(jsonString, JsonNode.class));
+ }
+ catch (Exception e) {
+ this.addError(621, "Unable to parse JSON", "KorapCollection");
+ };
};
@@ -143,112 +143,110 @@
* Legacy API for collection filters.
*/
public void fromJSONLegacy (JsonNode json) throws QueryException {
- if (!json.has("@type"))
- throw new QueryException(701, "JSON-LD group has no @type attribute");
+ 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");
+ if (!json.has("@value"))
+ throw new QueryException(851, "Legacy filter need @value fields");
- String type = json.get("@type").asText();
+ String type = json.get("@type").asText();
- KorapFilter kf = new KorapFilter();
- kf.setBooleanFilter(
- kf.fromJSONLegacy(json.get("@value"), "tokens")
- );
- if (type.equals("korap:meta-filter")) {
- if (DEBUG)
- log.trace("Add Filter LEGACY");
- this.filter(kf);
- }
+ KorapFilter kf = new KorapFilter();
+ kf.setBooleanFilter(kf.fromJSONLegacy(json.get("@value"), "tokens"));
+ if (type.equals("korap:meta-filter")) {
+ if (DEBUG)
+ log.trace("Add Filter LEGACY");
+ this.filter(kf);
+ }
- else if (type.equals("korap:meta-extend")) {
- if (DEBUG)
- log.trace("Add Extend LEGACY");
- this.extend(kf);
- };
+ else if (type.equals("korap:meta-extend")) {
+ if (DEBUG)
+ log.trace("Add Extend LEGACY");
+ this.extend(kf);
+ };
};
public int getCount() {
- return this.filterCount;
+ return this.filterCount;
};
public void setIndex (KorapIndex ki) {
- this.index = ki;
+ this.index = ki;
};
// The checks asre not necessary
public KorapCollection filter (BooleanFilter filter) {
- if (DEBUG)
- log.trace("Added filter: {}", filter.toString());
+ if (DEBUG)
+ log.trace("Added filter: {}", filter.toString());
+
+ if (filter == null) {
+ this.addWarning(830, "Filter was empty");
+ return this;
+ };
- if (filter == null) {
- this.addWarning(830, "Filter was empty");
- return this;
- };
-
- Filter f = (Filter) new QueryWrapperFilter(filter.toQuery());
- if (f == null) {
- this.addWarning(831, "Filter is not wrappable");
- return this;
- };
- FilterOperation fo = new FilterOperation(f, false);
- if (fo == null) {
- this.addWarning(832, "Filter operation is invalid");
- return this;
- };
- this.filter.add(fo);
- this.filterCount++;
- return this;
+ Filter f = (Filter) new QueryWrapperFilter(filter.toQuery());
+ if (f == null) {
+ this.addWarning(831, "Filter is not wrappable");
+ return this;
+ };
+ FilterOperation fo = new FilterOperation(f, false);
+ if (fo == null) {
+ this.addWarning(832, "Filter operation is invalid");
+ return this;
+ };
+ this.filter.add(fo);
+ this.filterCount++;
+ return this;
};
// Filter based on UIDs
public KorapCollection filterUIDs (String ... uids) {
- BooleanFilter filter = new BooleanFilter();
- filter.or("UID", uids);
- if (DEBUG)
- log.debug("UID based filter: {}", filter.toString());
- return this.filter(filter);
+ BooleanFilter filter = new BooleanFilter();
+ filter.or("UID", uids);
+ if (DEBUG)
+ log.debug("UID based filter: {}", filter.toString());
+ return this.filter(filter);
};
public KorapCollection filter (KorapFilter filter) {
- return this.filter(filter.getBooleanFilter());
+ return this.filter(filter.getBooleanFilter());
};
public KorapCollection extend (BooleanFilter filter) {
- if (DEBUG)
- log.trace("Added extension: {}", filter.toString());
- this.filter.add(
- new FilterOperation(
- (Filter) new QueryWrapperFilter(filter.toQuery()),
+ if (DEBUG)
+ log.trace("Added extension: {}", filter.toString());
+ this.filter.add(
+ new FilterOperation(
+ (Filter) new QueryWrapperFilter(filter.toQuery()),
true
)
);
- this.filterCount++;
- return this;
+ this.filterCount++;
+ return this;
};
public KorapCollection extend (KorapFilter filter) {
- return this.extend(filter.getBooleanFilter());
+ return this.extend(filter.getBooleanFilter());
};
public ArrayList<FilterOperation> getFilters () {
- return this.filter;
+ return this.filter;
};
public FilterOperation getFilter (int i) {
- return this.filter.get(i);
+ return this.filter.get(i);
};
public String toString () {
- StringBuilder sb = new StringBuilder();
- for (FilterOperation fo : this.filter) {
- sb.append(fo.toString()).append("; ");
- };
- return sb.toString();
+ StringBuilder sb = new StringBuilder();
+ for (FilterOperation fo : this.filter) {
+ sb.append(fo.toString()).append("; ");
+ };
+ return sb.toString();
};
/**
@@ -256,178 +254,174 @@
* testing purposes and not recommended for serious usage.
*/
public KorapResult search (SpanQuery query) {
- return this.index.search(
+ return this.index.search(
this,
- query,
- 0,
- (short) 20,
- true, (short) 5,
- true, (short) 5
- );
+ query,
+ 0,
+ (short) 20,
+ true, (short) 5,
+ true, (short) 5
+ );
};
public FixedBitSet bits (AtomicReaderContext atomic) throws IOException {
+ /*
+ Use Bits.MatchAllBits(int len)
+ */
+ boolean noDoc = true;
+ FixedBitSet bitset;
- /*
- Use Bits.MatchAllBits(int len)
- */
+ if (this.filterCount > 0) {
+ bitset = new FixedBitSet(atomic.reader().maxDoc());
- boolean noDoc = true;
- FixedBitSet bitset;
+ ArrayList<FilterOperation> filters = (ArrayList<FilterOperation>) this.filter.clone();
- if (this.filterCount > 0) {
- bitset = new FixedBitSet(atomic.reader().maxDoc());
+ FilterOperation kcInit = filters.remove(0);
+ if (DEBUG)
+ log.trace("FILTER: {}", kcInit);
- ArrayList<FilterOperation> filters = (ArrayList<FilterOperation>) this.filter.clone();
+ // Init vector
+ DocIdSet docids = kcInit.filter.getDocIdSet(atomic, null);
- FilterOperation kcInit = filters.remove(0);
- if (DEBUG)
- log.trace("FILTER: {}", kcInit);
+ DocIdSetIterator filterIter = docids.iterator();
- // Init vector
- DocIdSet docids = kcInit.filter.getDocIdSet(atomic, null);
+ if (filterIter != null) {
+ if (DEBUG)
+ log.trace("InitFilter has effect");
+ bitset.or(filterIter);
+ noDoc = false;
+ };
- DocIdSetIterator filterIter = docids.iterator();
+ if (!noDoc) {
+ for (FilterOperation kc : filters) {
+ if (DEBUG)
+ log.trace("FILTER: {}", kc);
- if (filterIter != null) {
- if (DEBUG)
- log.trace("InitFilter has effect");
- bitset.or(filterIter);
- noDoc = false;
- };
+ // TODO: BUG!!!!!!!!!!
+ docids = kc.filter.getDocIdSet(atomic, kc.isExtension() ? null : bitset);
+ filterIter = docids.iterator();
- if (!noDoc) {
- for (FilterOperation kc : filters) {
- if (DEBUG)
- log.trace("FILTER: {}", kc);
+ if (filterIter == null) {
+ // There must be a better way ...
+ if (kc.isFilter()) {
+ // TODO: Check if this is really correct!
+ // Maybe here is the bug
+ bitset.clear(0, bitset.length());
+ noDoc = true;
+ }
+ else {
+ // System.err.println("No term found");
+ };
+ continue;
+ };
+ if (kc.isExtension()) {
+ // System.err.println("Term found!");
+ // System.err.println("Old Card:" + bitset.cardinality());
+ bitset.or(filterIter);
+ // System.err.println("New Card:" + bitset.cardinality());
+ }
+ else {
+ bitset.and(filterIter);
+ };
+ };
- // TODO: BUG!!!!!!!!!!
- docids = kc.filter.getDocIdSet(atomic, kc.isExtension() ? null : bitset);
- filterIter = docids.iterator();
+ if (!noDoc) {
+ FixedBitSet livedocs = (FixedBitSet) atomic.reader().getLiveDocs();
+ if (livedocs != null) {
+ bitset.and(livedocs);
+ };
+ };
+ }
+ else {
+ return bitset;
+ };
+ }
+ else {
+ bitset = (FixedBitSet) atomic.reader().getLiveDocs();
+ };
- if (filterIter == null) {
- // There must be a better way ...
- if (kc.isFilter()) {
- // TODO: Check if this is really correct!
- // Maybe here is the bug
- bitset.clear(0, bitset.length());
- noDoc = true;
- }
- else {
- // System.err.println("No term found");
- };
- continue;
- };
- if (kc.isExtension()) {
- // System.err.println("Term found!");
- // System.err.println("Old Card:" + bitset.cardinality());
- bitset.or(filterIter);
- // System.err.println("New Card:" + bitset.cardinality());
- }
- else {
- bitset.and(filterIter);
- };
- };
-
- if (!noDoc) {
- FixedBitSet livedocs = (FixedBitSet) atomic.reader().getLiveDocs();
- if (livedocs != null) {
- bitset.and(livedocs);
- };
- };
- }
- else {
- return bitset;
- };
- }
- else {
- bitset = (FixedBitSet) atomic.reader().getLiveDocs();
- };
-
- return bitset;
+ return bitset;
};
public long numberOf (String foundry, String type) throws IOException {
- if (this.index == null)
- return (long) -1;
+ if (this.index == null)
+ return (long) -1;
- return this.index.numberOf(this, foundry, type);
+ return this.index.numberOf(this, foundry, type);
};
public long numberOf (String type) throws IOException {
- if (this.index == null)
- return (long) -1;
-
- return this.index.numberOf(this, "tokens", type);
+ if (this.index == null)
+ return (long) -1;
+
+ return this.index.numberOf(this, "tokens", type);
};
// This is only for testing purposes!
@Deprecated
public HashMap getTermRelation(String field) throws Exception {
- if (this.index == null) {
- HashMap<String,Long> map = new HashMap<>(1);
- map.put("-docs", (long) 0);
- return map;
- };
+ if (this.index == null) {
+ HashMap<String,Long> map = new HashMap<>(1);
+ map.put("-docs", (long) 0);
+ return map;
+ };
- return this.index.getTermRelation(this, field);
+ return this.index.getTermRelation(this, field);
};
@Deprecated
public String getTermRelationJSON(String field) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
- StringWriter sw = new StringWriter();
- sw.append("{\"field\":");
- mapper.writeValue(sw,field);
- sw.append(",");
+ ObjectMapper mapper = new ObjectMapper();
+ StringWriter sw = new StringWriter();
+ sw.append("{\"field\":");
+ mapper.writeValue(sw,field);
+ sw.append(",");
- try {
- HashMap<String, Long> map = this.getTermRelation(field);
+ try {
+ HashMap<String, Long> map = this.getTermRelation(field);
- sw.append("\"documents\":");
- mapper.writeValue(sw,map.remove("-docs"));
- sw.append(",");
+ sw.append("\"documents\":");
+ mapper.writeValue(sw,map.remove("-docs"));
+ sw.append(",");
- String[] keys = map.keySet().toArray(new String[map.size()]);
+ String[] keys = map.keySet().toArray(new String[map.size()]);
- HashMap<String,Integer> setHash = new HashMap<>(20);
- ArrayList<HashMap<String,Long>> set = new ArrayList<>(20);
- ArrayList<Long[]> overlap = new ArrayList<>(100);
+ HashMap<String,Integer> setHash = new HashMap<>(20);
+ ArrayList<HashMap<String,Long>> set = new ArrayList<>(20);
+ ArrayList<Long[]> overlap = new ArrayList<>(100);
- int count = 0;
- for (String key : keys) {
- if (!key.startsWith("#__")) {
- HashMap<String,Long> simpleMap = new HashMap<>();
- simpleMap.put(key, map.remove(key));
- set.add(simpleMap);
- setHash.put(key, count++);
- };
- };
+ int count = 0;
+ for (String key : keys) {
+ if (!key.startsWith("#__")) {
+ HashMap<String,Long> simpleMap = new HashMap<>();
+ simpleMap.put(key, map.remove(key));
+ set.add(simpleMap);
+ setHash.put(key, count++);
+ };
+ };
- keys = map.keySet().toArray(new String[map.size()]);
- for (String key : keys) {
- String[] comb = key.substring(3).split(":###:");
- Long[] l = new Long[3];
- l[0] = (long) setHash.get(comb[0]);
- l[1] = (long) setHash.get(comb[1]);
- l[2] = map.remove(key);
- overlap.add(l);
- };
+ keys = map.keySet().toArray(new String[map.size()]);
+ for (String key : keys) {
+ String[] comb = key.substring(3).split(":###:");
+ Long[] l = new Long[3];
+ l[0] = (long) setHash.get(comb[0]);
+ l[1] = (long) setHash.get(comb[1]);
+ l[2] = map.remove(key);
+ overlap.add(l);
+ };
-
- sw.append("\"sets\":");
- mapper.writeValue(sw, (Object) set);
- sw.append(",\"overlaps\":");
- mapper.writeValue(sw, (Object) overlap);
- sw.append(",\"error\":null");
+ sw.append("\"sets\":");
+ mapper.writeValue(sw, (Object) set);
+ sw.append(",\"overlaps\":");
+ mapper.writeValue(sw, (Object) overlap);
+ sw.append(",\"error\":null");
+ }
+ catch (Exception e) {
+ sw.append("\"error\":");
+ mapper.writeValue(sw,e.getMessage());
+ };
- }
- catch (Exception e) {
- sw.append("\"error\":");
- mapper.writeValue(sw,e.getMessage());
- };
-
- sw.append("}");
- return sw.getBuffer().toString();
+ sw.append("}");
+ return sw.getBuffer().toString();
};
};
diff --git a/src/main/java/de/ids_mannheim/korap/KorapDocument.java b/src/main/java/de/ids_mannheim/korap/KorapDocument.java
index 2602b46..33e3f3b 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapDocument.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapDocument.java
@@ -10,12 +10,20 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.annotation.*;
-/* Todo:: Author and textClass may be arrays! */
+/*
+ * Todo:: Author and textClass may be arrays!
+ */
/**
- * Abstract class representing a document in the KorAP index.
+ * Abstract class representing a document in the
+ * KorAP index.
*
- * @author Nils Diewald
+ * This model is rather specific to DeReKo data and
+ * should be considered experimental. It may be replaced
+ * by a more agnostic model.
+ * string fields, e.g. may be combined with a prefix.
+ *
+ * @author diewald
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class KorapDocument extends KorapResponse {
@@ -23,504 +31,993 @@
@JsonIgnore
public int
- internalDocID,
- localDocID,
- UID;
+ internalDocID,
+ localDocID,
+ UID;
private KorapDate
- pubDate,
- // newly added
- creationDate
- ;
+ pubDate,
+ // newly added
+ creationDate;
private String
- // No longer supported
- ID,
- corpusID,
- field,
- layerInfo,
- tokenization,
- // Still supported
- foundries,
- title,
- subTitle,
- author,
- textClass,
- pubPlace,
+ // No longer supported
+ ID,
+ corpusID,
+ field,
+ layerInfo,
+ tokenization,
- // newly added
- textSigle,
- docSigle,
- corpusSigle,
- publisher,
- editor,
- textType,
- textTypeArt,
- textTypeRef,
- textColumn,
- textDomain,
- license,
- pages,
- fileEditionStatement,
- biblEditionStatement,
- reference,
- language,
- corpusTitle,
- corpusSubTitle,
- corpusAuthor,
- corpusEditor,
- docTitle,
- docSubTitle,
- docAuthor,
- docEditor,
- keywords,
- tokenSource,
- layerInfos
- ;
+ // Still supported
+ foundries,
+ textClass,
+ pubPlace,
+
+ // Newly added for the corpus/doc/text distinction of DeReKo
+ textSigle, docSigle, corpusSigle,
+ title, subTitle, author, editor,
+ docTitle, docSubTitle, docAuthor, docEditor,
+ corpusTitle, corpusSubTitle, corpusAuthor, corpusEditor,
+ textType, textTypeArt, textTypeRef, textColumn, textDomain,
+ fileEditionStatement, biblEditionStatement,
+ publisher,
+ reference,
+ language,
+ license,
+ pages,
+ keywords,
+
+ // Meta information regarding annotations
+ tokenSource,
+ layerInfos;
/**
- * Set the publication date of the document the match occurs in.
+ * Get the publication date of the document
+ * as a KorapDate object.
+ *
+ * @return A KorapDate object for chaining.
+ * @see KorapDate
+ */
+ @JsonIgnore
+ public KorapDate getPubDate () {
+ return this.pubDate;
+ };
+
+
+ /**
+ * Get the publication date of the document
+ * as a string.
+ *
+ * @return A string containing the KorapDate.
+ * @see KorapDate
+ */
+ @JsonProperty("pubDate")
+ public String getPubDateString () {
+ if (this.pubDate != null)
+ return this.pubDate.toDisplay();
+ return null;
+ };
+
+
+ /**
+ * Set the publication date of the document.
*
* @param date The date as a KorapDate compatible string representation.
* @return A KorapDate object for chaining.
* @see KorapDate#Constructor(String)
*/
public KorapDate setPubDate (String date) {
- this.pubDate = new KorapDate(date);
- return this.pubDate;
- };
-
- /**
- * Set the creation date of the document the match occurs in.
- *
- * @param date The date as a KorapDate compatible string representation.
- * @return A KorapDate object for chaining.
- * @see KorapDate#Constructor(String)
- */
- public KorapDate setCreationDate (String date) {
- this.creationDate = new KorapDate(date);
- return this.creationDate;
+ this.pubDate = new KorapDate(date);
+ return this.pubDate;
};
/**
- * Set the publication date of the document the match occurs in.
+ * Set the publication date of the document.
*
* @param date The date as a KorapDate object.
* @return A KorapDate object for chaining.
* @see KorapDate
*/
public KorapDate setPubDate (KorapDate date) {
- return (this.pubDate = date);
+ return (this.pubDate = date);
};
/**
- * Set the creation date of the document the match occurs in.
+ * Get the creation date of the document
+ * as a KorapDate object.
+ *
+ * @return A KorapDate object for chaining.
+ * @see KorapDate
+ */
+ @JsonIgnore
+ public KorapDate getCreationDate () {
+ return this.creationDate;
+ };
+
+
+ /**
+ * Get the creation date of the document
+ * as a string.
+ *
+ * @return A string containing the KorapDate.
+ * @see KorapDate
+ */
+ @JsonProperty("creationDate")
+ public String getCreationDateString () {
+ if (this.creationDate != null)
+ return this.creationDate.toDisplay();
+ return null;
+ };
+
+
+ /**
+ * Set the creation date of the document.
+ *
+ * @param date The date as a KorapDate compatible string representation.
+ * @return A KorapDate object for chaining.
+ * @see KorapDate#Constructor(String)
+ */
+ public KorapDate setCreationDate (String date) {
+ this.creationDate = new KorapDate(date);
+ return this.creationDate;
+ };
+
+
+ /**
+ * Set the creation date of the document.
*
* @param date The date as a KorapDate object.
* @return A KorapDate object for chaining.
* @see KorapDate
*/
public KorapDate setCreationDate (KorapDate date) {
- return (this.creationDate = date);
- };
+ return (this.creationDate = date);
+ };
/**
- * Get the publication date of the document the match occurs in as a KorapDate object.
+ * Get the name of the author of the document.
+ *
+ * @return The name of the author as a string.
*/
- @JsonIgnore
- public KorapDate getPubDate () {
- return this.pubDate;
- };
-
-
- /**
- * Get the creation date of the document the match occurs in as a KorapDate object.
- */
- @JsonIgnore
- public KorapDate getCreationDate () {
- return this.creationDate;
- };
-
- @JsonProperty("pubDate")
- public String getPubDateString () {
- if (this.pubDate != null)
- return this.pubDate.toDisplay();
- return null;
- };
-
- @JsonProperty("creationDate")
- public String getCreationDateString () {
- if (this.creationDate != null)
- return this.creationDate.toDisplay();
- return null;
- };
-
- public void setAuthor (String author) {
- this.author = author;
- };
-
public String getAuthor () {
- return this.author;
+ return this.author;
};
+
- public void setTextClass (String textClass) {
- this.textClass = textClass;
+ /**
+ * Set the name of the author of the document.
+ *
+ * @param author The name of the author as a string.
+ */
+ public void setAuthor (String author) {
+ this.author = author;
};
+
+ /**
+ * Get the text class of the document.
+ *
+ * @return The text class of the document as a string.
+ */
public String getTextClass () {
- return this.textClass;
+ return this.textClass;
};
- public void setPubPlace (String pubPlace) {
- this.pubPlace = pubPlace;
+
+ /**
+ * Set the text class of the document.
+ *
+ * @param textClass The text class of the document as a string.
+ */
+ public void setTextClass (String textClass) {
+ this.textClass = textClass;
};
+
+ /**
+ * Get the publication place of the document.
+ *
+ * @return The publication place of the document as a string.
+ */
public String getPubPlace () {
- return this.pubPlace;
+ return this.pubPlace;
};
-
- // No longer supported
- public void setCorpusID (String corpusID) {
- this.corpusID = corpusID;
- };
-
- // No longer supported
- @JsonProperty("corpusID")
- public String getCorpusID () {
- return this.corpusID;
- };
-
- // No longer supported
- public void setID (String ID) {
- this.ID = ID;
- };
-
- // No longer supported
- @JsonProperty("ID")
- public String getID () {
- return this.ID;
- };
-
- public void setUID (int UID) {
- this.UID = UID;
- };
-
- public void setUID (String UID) {
- if (UID != null)
- this.UID = Integer.parseInt(UID);
- };
+
+
+ /**
+ * Set the publication place of the document.
+ *
+ * @param pubPlace The publication place of the document as a string.
+ */
+ public void setPubPlace (String pubPlace) {
+ this.pubPlace = pubPlace;
+ };
+ /**
+ * Get the unique identifier of the document.
+ *
+ * @return The unique identifier of the document as an integer.
+ */
@JsonProperty("UID")
public int getUID () {
- return this.UID;
+ return this.UID;
+ };
+
+
+ /**
+ * Set the unique identifier of the document.
+ *
+ * @param UID The unique identifier of the document as an integer.
+ */
+ public void setUID (int UID) {
+ this.UID = UID;
};
- public void setTitle (String title) {
- this.title = title;
+
+ /**
+ * Set the unique identifier of the document.
+ *
+ * @param UID The unique identifier of the document as a
+ * string representing an integer.
+ * @throws NumberFormatException
+ */
+ public void setUID (String UID) throws NumberFormatException {
+ if (UID != null)
+ this.UID = Integer.parseInt(UID);
};
+
+ /**
+ * Get the title of the document.
+ *
+ * @return The title of the document as a string.
+ */
public String getTitle () {
- return this.title;
+ return this.title;
};
- public void setSubTitle (String subTitle) {
- this.subTitle = subTitle;
- };
+ /**
+ * Set the title of the document.
+ *
+ * @param title The title of the document as a string.
+ */
+ public void setTitle (String title) {
+ this.title = title;
+ };
+
+
+ /**
+ * Get the subtitle of the document.
+ *
+ * @return The subtitle of the document as a string.
+ */
public String getSubTitle () {
- return this.subTitle;
+ return this.subTitle;
};
+
+ /**
+ * Set the subtitle of the document.
+ *
+ * @param subTitle The subtitle of the document as a string.
+ */
+ public void setSubTitle (String subTitle) {
+ this.subTitle = subTitle;
+ };
+
+
+ /**
+ * Get the primary data of the document.
+ *
+ * @return The primary data of the document as a string.
+ */
+ public String getPrimaryData () {
+ if (this.primaryData == null)
+ return "";
+ return this.primaryData.toString();
+ };
+
+
+ /**
+ * Get the primary data of the document,
+ * starting with a given character offset.
+ *
+ * @param startOffset The starting character offset.
+ * @return The substring of primary data of the document as a string.
+ */
+ public String getPrimaryData (int startOffset) {
+ return this.primaryData.substring(startOffset);
+ };
+
+
+ /**
+ * Get the primary data of the document,
+ * starting with a given character offset and ending
+ * with a given character offset.
+ *
+ * @param startOffset The starting character offset.
+ * @param endOffset The ending character offset.
+ * @return The substring of the primary data of the document as a string.
+ */
+ public String getPrimaryData (int startOffset, int endOffset) {
+ return this.primaryData.substring(startOffset, endOffset);
+ };
+
+
+ /**
+ * Set the primary data of the document.
+ *
+ * @param primary The primary data of the document as a string.
+ */
@JsonIgnore
public void setPrimaryData (String primary) {
- this.primaryData = new KorapPrimaryData(primary);
+ this.primaryData = new KorapPrimaryData(primary);
};
+
+ /**
+ * Set the primary data of the document.
+ *
+ * @param primary The primary data of the document
+ * as a KorapPrimaryData object.
+ * @see KorapPrimaryData
+ */
public void setPrimaryData (KorapPrimaryData primary) {
- this.primaryData = primary;
+ this.primaryData = primary;
};
- public String getPrimaryData () {
- if (this.primaryData == null)
- return "";
- return this.primaryData.toString();
- };
- public String getPrimaryData (int startOffset) {
- return this.primaryData.substring(startOffset);
- };
-
- public String getPrimaryData (int startOffset, int endOffset) {
- return this.primaryData.substring(startOffset, endOffset);
- };
-
+ /**
+ * Get the length of the primary data of the document
+ * (i.e. the number of characters).
+ *
+ * @return The length of the primary data of the document as an integer.
+ */
@JsonIgnore
public int getPrimaryDataLength () {
- return this.primaryData.length();
+ return this.primaryData.length();
};
- public void setFoundries (String foundries) {
- this.foundries = foundries;
- };
+ /**
+ * Get information on the foundries the document
+ * is annotated with as a string.
+ *
+ * @return The foundry information string.
+ */
public String getFoundries () {
- return this.foundries;
+ return this.foundries;
};
- // No longer supported
- public void setTokenization (String tokenization) {
- this.tokenization = tokenization;
+
+ /**
+ * Set information on the foundries the document
+ * is annotated with.
+ *
+ * @param foundries The foundry information string.
+ */
+ public void setFoundries (String foundries) {
+ this.foundries = foundries;
};
- // No longer supported
- public String getTokenization () {
- return this.tokenization;
- };
- // No longer supported
- public void setLayerInfo (String layerInfo) {
- this.layerInfo = layerInfo;
- };
-
- // No longer supported
- public String getLayerInfo () {
- return this.layerInfo;
- };
-
- public void setLayerInfos (String layerInfos) {
- this.layerInfos = layerInfos;
- };
-
+ /**
+ * Get information on the layers the document
+ * is annotated with as a string.
+ *
+ * @return The layer information string.
+ */
public String getLayerInfos () {
- return this.layerInfos;
+ return this.layerInfos;
};
- // No longer necessary
- public void setField (String field) {
- this.field = field;
+
+ /**
+ * Set information on the layers the document
+ * is annotated with as a string.
+ *
+ * @param layerInfos The layer information string.
+ */
+ public void setLayerInfos (String layerInfos) {
+ this.layerInfos = layerInfos;
};
- // No longer necessary
- public String getField () {
- return this.field;
- };
// This is the new text id
+ /**
+ * Get the text sigle as a string.
+ *
+ * @return The text sigle as a string.
+ */
public String getTextSigle () {
- return this.textSigle;
+ return this.textSigle;
};
+
// This is the new text id
+ /**
+ * Set the text sigle as a string.
+ *
+ * @param textSigle The text sigle as a string.
+ */
public void setTextSigle (String textSigle) {
- this.textSigle = textSigle;
+ this.textSigle = textSigle;
};
+
// This is the new corpus id
+ /**
+ * Get the corpus sigle as a string.
+ *
+ * @return The corpus sigle as a string.
+ */
public String getCorpusSigle () {
- return this.corpusSigle;
+ return this.corpusSigle;
};
+
// This is the new corpus id
+ /**
+ * Set the corpus sigle as a string.
+ *
+ * @param corpusSigle The corpus sigle as a string.
+ */
public void setCorpusSigle (String corpusSigle) {
- this.corpusSigle = corpusSigle;
+ this.corpusSigle = corpusSigle;
};
+
+ /**
+ * Get the document sigle as a string.
+ *
+ * @return The document sigle as a string.
+ */
public String getDocSigle () {
- return this.docSigle;
+ return this.docSigle;
};
+
+ /**
+ * Set the document sigle as a string.
+ *
+ * @param docSigle The document sigle as a string.
+ */
public void setDocSigle (String docSigle) {
- this.docSigle = docSigle;
+ this.docSigle = docSigle;
};
+
+ /**
+ * Get the name of the publisher as a string.
+ *
+ * @return The name of the publisher as a string.
+ */
public String getPublisher () {
- return this.publisher;
+ return this.publisher;
};
+
+ /**
+ * Set the name of the publisher as a string.
+ *
+ * @param publisher The name of the publisher as a string.
+ */
public void setPublisher (String publisher) {
- this.publisher = publisher;
+ this.publisher = publisher;
};
+
+ /**
+ * Get the name of the editor as a string.
+ *
+ * @return The name of the editor as a string.
+ */
public String getEditor () {
- return this.editor;
+ return this.editor;
};
+
+ /**
+ * Set the name of the editor as a string.
+ *
+ * @param editor The name of the editor as a string.
+ */
public void setEditor (String editor) {
- this.editor = editor;
+ this.editor = editor;
};
+
+ /**
+ * Get the type of the text as a string.
+ *
+ * @return The type of the text as a string.
+ */
public String getTextType () {
- return this.textType;
+ return this.textType;
};
+
+ /**
+ * Set the type of the text as a string.
+ *
+ * @param textType The type of the text as a string.
+ */
public void setTextType (String textType) {
- this.textType = textType;
+ this.textType = textType;
};
+
+ /**
+ * Get the type art of the text as a string.
+ *
+ * @return The type art of the text as a string.
+ */
public String getTextTypeArt () {
- return this.textTypeArt;
+ return this.textTypeArt;
};
+
+ /**
+ * Set the type art of the text as a string.
+ *
+ * @param textTypeArt The type art of the text as a string.
+ */
public void setTextTypeArt (String textTypeArt) {
- this.textTypeArt = textTypeArt;
+ this.textTypeArt = textTypeArt;
};
- public String getTextTypeRef () {
- return this.textTypeRef;
- };
+ /**
+ * Set the type reference of the text as a string.
+ *
+ * @param textTypeRef The type reference of the text as a string.
+ */
public void setTextTypeRef (String textTypeRef) {
- this.textTypeRef = textTypeRef;
+ this.textTypeRef = textTypeRef;
};
+
+ /**
+ * Get the type reference of the text as a string.
+ *
+ * @return The type reference of the text as a string.
+ */
+ public String getTextTypeRef () {
+ return this.textTypeRef;
+ };
+
+
+ /**
+ * Get the column of the text as a string.
+ *
+ * @return The column of the text as a string.
+ */
public String getTextColumn () {
- return this.textColumn;
+ return this.textColumn;
};
+
+ /**
+ * Set the column of the text as a string.
+ *
+ * @param textColumn The column of the text as a string.
+ */
public void setTextColumn (String textColumn) {
- this.textColumn = textColumn;
+ this.textColumn = textColumn;
};
+
+ /**
+ * Get the domain of the text as a string.
+ *
+ * @return The domain of the text as a string.
+ */
public String getTextDomain () {
- return this.textDomain;
+ return this.textDomain;
};
+
+ /**
+ * Set the domain of the text as a string.
+ *
+ * @param textDomain The domain of the text as a string.
+ */
public void setTextDomain (String textDomain) {
- this.textDomain = textDomain;
+ this.textDomain = textDomain;
};
+
+ /**
+ * Get the license of the text as a string.
+ *
+ * @return The license of the text as a string.
+ */
public String getLicense () {
- return this.license;
+ return this.license;
};
+
+ /**
+ * Set the license of the text as a string.
+ *
+ * @param license The license of the text as a string.
+ */
public void setLicense (String license) {
- this.license = license;
+ this.license = license;
};
+
+ /**
+ * Get the page numbers of the text as a string.
+ *
+ * @return The page numbers of the text as a string.
+ */
public String getPages () {
- return this.pages;
+ return this.pages;
};
+
+ /**
+ * Set the page numbers of the text as a string.
+ *
+ * @param pages The page numbers of the text as a string.
+ */
public void setPages (String pages) {
- this.pages = pages;
+ this.pages = pages;
};
+
+ /**
+ * Get the file edition statement of the text as a string.
+ *
+ * @return The file edition statement of the text as a string.
+ */
public String getFileEditionStatement () {
- return this.fileEditionStatement;
+ return this.fileEditionStatement;
};
+
+ /**
+ * Set the file edition statement of the text as a string.
+ *
+ * @param fileEditionStatement The file edition statement
+ * of the text as a string.
+ */
public void setFileEditionStatement (String fileEditionStatement) {
- this.fileEditionStatement = fileEditionStatement;
+ this.fileEditionStatement = fileEditionStatement;
};
+
+ /**
+ * Get the bibliograhic edition statement of the text as a string.
+ *
+ * @return The bibliograhic edition statement of the text as a string.
+ */
public String getBiblEditionStatement () {
- return this.biblEditionStatement;
+ return this.biblEditionStatement;
};
+
+ /**
+ * Set the bibliograhic edition statement of the text as a string.
+ *
+ * @param biblEditionStatement The bibliograhic edition statement
+ * of the text as a string.
+ */
public void setBiblEditionStatement (String biblEditionStatement) {
- this.biblEditionStatement = biblEditionStatement;
+ this.biblEditionStatement = biblEditionStatement;
};
+
+ /**
+ * Get the reference of the text as a string.
+ *
+ * @return The reference of the text as a string.
+ */
public String getReference () {
- return this.reference;
+ return this.reference;
};
+
+ /**
+ * Set the reference of the text as a string.
+ *
+ * @param reference The reference of the text as a string.
+ */
public void setReference (String reference) {
- this.reference = reference;
+ this.reference = reference;
};
+
+ /**
+ * Get the language of the text as a string.
+ *
+ * @return The language of the text as a string.
+ */
public String getLanguage () {
- return this.language;
+ return this.language;
};
+
+ /**
+ * Set the language of the text as a string.
+ *
+ * @param language The language of the text as a string.
+ */
public void setLanguage (String language) {
- this.language = language;
+ this.language = language;
};
+
+ /**
+ * Get the corpus title of the text as a string.
+ *
+ * @return The corpus title of the text as a string.
+ */
public String getCorpusTitle () {
- return this.corpusTitle;
+ return this.corpusTitle;
};
+
+ /**
+ * Set the corpus title of the text as a string.
+ *
+ * @param corpusTitle The corpus title of the text as a string.
+ */
public void setCorpusTitle (String corpusTitle) {
- this.corpusTitle = corpusTitle;
+ this.corpusTitle = corpusTitle;
};
+
+ /**
+ * Get the corpus subtitle of the text as a string.
+ *
+ * @return The corpus subtitle of the text as a string.
+ */
public String getCorpusSubTitle () {
- return this.corpusSubTitle;
+ return this.corpusSubTitle;
};
+
+ /**
+ * Set the corpus subtitle of the text as a string.
+ *
+ * @param corpusSubTitle The corpus subtitle of the
+ * text as a string.
+ */
public void setCorpusSubTitle (String corpusSubTitle) {
- this.corpusSubTitle = corpusSubTitle;
+ this.corpusSubTitle = corpusSubTitle;
};
+
+ /**
+ * Get the corpus author of the text as a string.
+ *
+ * @return The corpus author of the text as a string.
+ */
public String getCorpusAuthor () {
- return this.corpusAuthor;
+ return this.corpusAuthor;
};
+
+ /**
+ * Set the corpus author of the text as a string.
+ *
+ * @return The corpus author of the text as a string.
+ */
public void setCorpusAuthor (String corpusAuthor) {
- this.corpusAuthor = corpusAuthor;
+ this.corpusAuthor = corpusAuthor;
};
+
+ /**
+ * Get the corpus editor of the text as a string.
+ *
+ * @return The corpus editor of the text as a string.
+ */
public String getCorpusEditor () {
- return this.corpusEditor;
+ return this.corpusEditor;
};
+
+ /**
+ * Set the corpus editor of the text as a string.
+ *
+ * @param corpusEditor The corpus editor of the text as a string.
+ */
public void setCorpusEditor (String corpusEditor) {
- this.corpusEditor = corpusEditor;
+ this.corpusEditor = corpusEditor;
};
+
+ /**
+ * Get the document title of the text as a string.
+ *
+ * @return The document title of the text as a string.
+ */
public String getDocTitle () {
- return this.docTitle;
+ return this.docTitle;
};
+ /**
+ * Set the document title of the text as a string.
+ *
+ * @param docTitle The document title of the text as a string.
+ */
public void setDocTitle (String docTitle) {
- this.docTitle = docTitle;
+ this.docTitle = docTitle;
};
+
+ /**
+ * Get the subtitle of the document of the text as a string.
+ *
+ * @return The subtitle of the document of the text as a string.
+ */
public String getDocSubTitle () {
- return this.docSubTitle;
+ return this.docSubTitle;
};
+
+ /**
+ * Set the subtitle of the document of the text as a string.
+ *
+ * @param docSubTitle The subtitle of the document of the
+ * text as a string.
+ */
public void setDocSubTitle (String docSubTitle) {
- this.docSubTitle = docSubTitle;
+ this.docSubTitle = docSubTitle;
};
+
+ /**
+ * Get the author of the document of the text as a string.
+ *
+ * @return The author of the document of the text as a string.
+ */
public String getDocAuthor () {
- return this.docAuthor;
+ return this.docAuthor;
};
+
+ /**
+ * Set the author of the document of the text as a string.
+ *
+ * @param docAuthor The author of the document of the text as a string.
+ */
public void setDocAuthor (String docAuthor) {
- this.docAuthor = docAuthor;
+ this.docAuthor = docAuthor;
};
+
+ /**
+ * Get the editor of the document of the text as a string.
+ *
+ * @return The editor of the document of the text as a string.
+ */
public String getDocEditor () {
- return this.docEditor;
+ return this.docEditor;
};
+
+ /**
+ * Set the editor of the document of the text as a string.
+ *
+ * @param docEditor The editor of the document of the text as a string.
+ */
public void setDocEditor (String docEditor) {
- this.docEditor = docEditor;
+ this.docEditor = docEditor;
};
+
+ /**
+ * Get the keywords of the text as a string.
+ *
+ * @return The keywords of the text as a string.
+ */
public String getKeywords () {
- return this.keywords;
+ return this.keywords;
};
+
+ /**
+ * Set the keywords of the text as a string.
+ *
+ * @param keywords The keywords of the text as a string.
+ */
public void setKeywords (String keywords) {
- this.keywords = keywords;
+ this.keywords = keywords;
};
+
+ /**
+ * Get information about the source of tokenization
+ * as a string.
+ *
+ * @return The tokenization information as a string.
+ */
public String getTokenSource () {
- return this.tokenSource;
+ return this.tokenSource;
};
+
+ /**
+ * Set information about the source of tokenization
+ * as a string.
+ *
+ * @param tokenSource The tokenization information as a string.
+ */
public void setTokenSource (String tokenSource) {
- this.tokenSource = tokenSource;
+ this.tokenSource = tokenSource;
+ };
+
+
+ @Deprecated
+ public void setTokenization (String tokenization) {
+ this.tokenization = tokenization;
+ };
+
+
+ @Deprecated
+ public String getTokenization () {
+ return this.tokenization;
+ };
+
+
+ @Deprecated
+ public void setLayerInfo (String layerInfo) {
+ this.layerInfo = layerInfo;
+ };
+
+
+ @Deprecated
+ public String getLayerInfo () {
+ return this.layerInfo;
+ };
+
+
+ @Deprecated
+ public void setField (String field) {
+ this.field = field;
+ };
+
+
+ @Deprecated
+ public String getField () {
+ return this.field;
+ };
+
+
+ @Deprecated
+ @JsonProperty("corpusID")
+ public String getCorpusID () {
+ return this.corpusID;
+ };
+
+
+ @Deprecated
+ public void setCorpusID (String corpusID) {
+ this.corpusID = corpusID;
+ };
+
+
+ @Deprecated
+ @JsonProperty("ID")
+ public String getID () {
+ return this.ID;
+ };
+
+
+ @Deprecated
+ public void setID (String ID) {
+ this.ID = ID;
};
};
diff --git a/src/main/java/de/ids_mannheim/korap/KorapFilter.java b/src/main/java/de/ids_mannheim/korap/KorapFilter.java
index 32573f9..539c061 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapFilter.java
@@ -36,115 +36,117 @@
public static final boolean DEBUG = false;
public KorapFilter () {
- filter = new BooleanFilter();
+ filter = new BooleanFilter();
};
public KorapFilter (JsonNode json) throws QueryException {
- filter = this.fromJSON(json, "tokens");
+ filter = this.fromJSON(json, "tokens");
};
protected BooleanFilter fromJSON (JsonNode json, String field) throws QueryException {
- BooleanFilter bfilter = new BooleanFilter();
+ BooleanFilter bfilter = new BooleanFilter();
- // TODO: THIS UNFORTUNATELY BREAKS TESTS
- if (!json.has("@type"))
- throw new QueryException(701, "JSON-LD group has no @type attribute");
+ // TODO: THIS UNFORTUNATELY BREAKS TESTS
+ if (!json.has("@type"))
+ throw new QueryException(701, "JSON-LD group has no @type attribute");
- String type = json.get("@type").asText();
+ String type = json.get("@type").asText();
+
+ // Single filter
+ if (type.equals("korap:doc")) {
- // Single filter
- if (type.equals("korap:doc")) {
+ String key = "tokens";
+ String valtype = "type:string";
+ String match = "match:eq";
- String key = "tokens";
- String valtype = "type:string";
- String match = "match:eq";
+ if (json.has("key"))
+ key = json.get("key").asText();
+
+ if (json.has("type"))
+ valtype = json.get("type").asText();
- if (json.has("key"))
- key = json.get("key").asText();
+ // Filter based on date
+ if (valtype.equals("type:date")) {
- if (json.has("type"))
- valtype = json.get("type").asText();
+ if (!json.has("value"))
+ throw new QueryException(612, "Dates require value fields");
+//-
+ String dateStr = json.get("value").asText();
+ if (json.has("match"))
+ match = json.get("match").asText();
- // Filter based on date
- if (valtype.equals("type:date")) {
+ // TODO: This isn't stable yet
+ switch (match) {
+ case "match:eq":
+ bfilter.date(dateStr);
+ break;
+ case "match:geq":
+ bfilter.since(dateStr);
+ break;
+ case "match:leq":
+ bfilter.till(dateStr);
+ break;
+ };
+ /*
+ No good reason for gt or lt
+ */
+ return bfilter;
+ }
+ else if (valtype.equals("type:string")) {
+ if (json.has("match"))
+ match = json.get("match").asText();
- if (!json.has("value"))
- throw new QueryException(612, "Dates require value fields");
+ if (match.equals("match:eq")) {
+ bfilter.and(key, json.get("value").asText());
+ };
+ return bfilter;
+ };
+ }
- String dateStr = json.get("value").asText();
- if (json.has("match"))
- match = json.get("match").asText();
+ // nested group
+ else if (type.equals("korap:docGroup")) {
+ if (!json.has("operands") || !json.get("operands").isArray())
+//-
+ throw new QueryException(612, "Groups need operands");
- // TODO: This isn't stable yet
- switch (match) {
- case "match:eq":
- bfilter.date(dateStr);
- break;
- case "match:geq":
- bfilter.since(dateStr);
- break;
- case "match:leq":
- bfilter.till(dateStr);
- break;
- };
- /*
- No good reason for gt or lt
- */
- return bfilter;
- }
- else if (valtype.equals("type:string")) {
- if (json.has("match"))
- match = json.get("match").asText();
+ String operation = "operation:and";
+ if (json.has("operation"))
+ operation = json.get("operation").asText();
- if (match.equals("match:eq")) {
- bfilter.and(key, json.get("value").asText());
- };
- return bfilter;
- };
- }
+ BooleanFilter group = new BooleanFilter();
- // nested group
- else if (type.equals("korap:docGroup")) {
- if (!json.has("operands") || !json.get("operands").isArray())
- throw new QueryException(612, "Groups need operands");
+ for (JsonNode operand : json.get("operands")) {
+ if (operation.equals("operation:and")) {
+ group.and(this.fromJSON(operand, field));
+ }
+ else if (operation.equals("operation:or")) {
+ group.or(this.fromJSON(operand, field));
+ }
+ else {
+ throw new QueryException(613, "Unknown document group operation");
+ };
+ };
+ bfilter.and(group);
+ return bfilter;
+ }
- String operation = "operation:and";
- if (json.has("operation"))
- operation = json.get("operation").asText();
+ // Unknown type
+ else {
+// -
+ throw new QueryException(613, "Collection query type has to be doc or docGroup");
+ };
- BooleanFilter group = new BooleanFilter();
-
- for (JsonNode operand : json.get("operands")) {
- if (operation.equals("operation:and")) {
- group.and(this.fromJSON(operand, field));
- }
- else if (operation.equals("operation:or")) {
- group.or(this.fromJSON(operand, field));
- }
- else {
- throw new QueryException(613, "Unknown document group operation");
- };
- };
- bfilter.and(group);
- return bfilter;
- }
-
- // UNknown type
- else {
- throw new QueryException(613, "Collection query type has to be doc or docGroup");
- };
-
- return new BooleanFilter();
+ return new BooleanFilter();
};
/*
- String type = json.get("@type").asText();
- String field = _getField(json);
+ String type = json.get("@type").asText();
+ String field = _getField(json);
- if (type.equals("korap:term")) {
- this.fromJSON(json, field);
- }
- else if (type.equals("korap:group")) {
+ if (type.equals("korap:term")) {
+ this.fromJSON(json, field);
+ }
+ else if (type.equals("korap:group")) {
// TODO: relation
for (JsonNode operand : json.get("operands")) {
this.fromJSON(operand, field);
@@ -153,198 +155,206 @@
*/
// };
- protected BooleanFilter fromJSONLegacy (JsonNode json, String field) throws QueryException {
- BooleanFilter bfilter = new BooleanFilter();
+ protected BooleanFilter fromJSONLegacy (JsonNode json, String field)
+ throws QueryException {
+ BooleanFilter bfilter = new BooleanFilter();
- if (!json.has("@type"))
- throw new QueryException(612, "JSON-LD group has no @type attribute");
+//-
+ if (!json.has("@type"))
+ throw new QueryException(612, "JSON-LD group has no @type attribute");
- String type = json.get("@type").asText();
+ String type = json.get("@type").asText();
- if (DEBUG)
- log.trace("@type: " + type);
+ if (DEBUG)
+ log.trace("@type: " + type);
- if (json.has("@field"))
- field = _getFieldLegacy(json);
+ if (json.has("@field"))
+ field = _getFieldLegacy(json);
- if (type.equals("korap:term")) {
- if (field != null && json.has("@value"))
- bfilter.and(field, json.get("@value").asText());
- return bfilter;
- }
- else if (type.equals("korap:group")) {
- if (!json.has("relation"))
- throw new QueryException(612, "Group needs relation");
+ if (type.equals("korap:term")) {
+ if (field != null && json.has("@value"))
+ bfilter.and(field, json.get("@value").asText());
+ return bfilter;
+ }
+ else if (type.equals("korap:group")) {
+//-
+ if (!json.has("relation"))
+ throw new QueryException(612, "Group needs relation");
- if (!json.has("operands"))
- throw new QueryException(612, "Group needs operand list");
+ if (!json.has("operands"))
+//-
+ throw new QueryException(612, "Group needs operand list");
//return bfilter;
- String dateStr, till;
- JsonNode operands = json.get("operands");
+ String dateStr, till;
+ JsonNode operands = json.get("operands");
- if (!operands.isArray())
- throw new QueryException(612, "Group needs operand list");
+ if (!operands.isArray())
+//-
+ throw new QueryException(612, "Group needs operand list");
- if (DEBUG)
- log.trace("relation found {}", json.get("relation").asText());
+ if (DEBUG)
+ log.trace("relation found {}", json.get("relation").asText());
- BooleanFilter group = new BooleanFilter();
+ BooleanFilter group = new BooleanFilter();
- switch (json.get("relation").asText()) {
- case "between":
- dateStr = _getDateLegacy(json, 0);
- till = _getDateLegacy(json, 1);
- if (dateStr != null && till != null)
- bfilter.between(dateStr, till);
- break;
+ switch (json.get("relation").asText()) {
+ case "between":
+ dateStr = _getDateLegacy(json, 0);
+ till = _getDateLegacy(json, 1);
+ if (dateStr != null && till != null)
+ bfilter.between(dateStr, till);
+ break;
- case "until":
- dateStr = _getDateLegacy(json, 0);
- if (dateStr != null)
- bfilter.till(dateStr);
- break;
+ case "until":
+ dateStr = _getDateLegacy(json, 0);
+ if (dateStr != null)
+ bfilter.till(dateStr);
+ break;
- case "since":
- dateStr = _getDateLegacy(json, 0);
- if (dateStr != null)
- bfilter.since(dateStr);
- break;
+ case "since":
+ dateStr = _getDateLegacy(json, 0);
+ if (dateStr != null)
+ bfilter.since(dateStr);
+ break;
- case "equals":
- dateStr = _getDateLegacy(json, 0);
- if (dateStr != null)
- bfilter.date(dateStr);
- break;
+ case "equals":
+ dateStr = _getDateLegacy(json, 0);
+ if (dateStr != null)
+ bfilter.date(dateStr);
+ break;
- case "and":
- if (operands.size() < 1)
- throw new QueryException(612, "Operation needs at least two operands");
+ case "and":
+//-
+ if (operands.size() < 1)
+ throw new QueryException(612, "Operation needs at least two operands");
- for (JsonNode operand : operands) {
- group.and(this.fromJSONLegacy(operand, field));
- };
- bfilter.and(group);
- break;
+ for (JsonNode operand : operands) {
+ group.and(this.fromJSONLegacy(operand, field));
+ };
+ bfilter.and(group);
+ break;
- case "or":
- if (operands.size() < 1)
- throw new QueryException(612, "Operation needs at least two operands");
+ case "or":
+//-
+ if (operands.size() < 1)
+ throw new QueryException(612, "Operation needs at least two operands");
- for (JsonNode operand : operands) {
- group.or(this.fromJSONLegacy(operand, field));
- };
- bfilter.and(group);
- break;
+ for (JsonNode operand : operands) {
+ group.or(this.fromJSONLegacy(operand, field));
+ };
+ bfilter.and(group);
+ break;
- default:
- throw new QueryException(613, "Relation is not supported");
- };
- }
- else {
- throw new QueryException(613, "Filter type is not a supported group");
- };
- return bfilter;
+//-
+ default:
+ throw new QueryException(613, "Relation is not supported");
+ };
+ }
+ else {
+ throw new QueryException(613, "Filter type is not a supported group");
+ };
+ return bfilter;
};
private static String _getFieldLegacy (JsonNode json) {
- if (!json.has("@field"))
- return (String) null;
+ if (!json.has("@field"))
+ return (String) null;
- String field = json.get("@field").asText();
- return field.replaceFirst("korap:field#", "");
+ String field = json.get("@field").asText();
+ return field.replaceFirst("korap:field#", "");
};
private static String _getDateLegacy (JsonNode json, int index) {
- if (!json.has("operands"))
- return (String) null;
+ if (!json.has("operands"))
+ return (String) null;
- if (!json.get("operands").has(index))
- return (String) null;
+ if (!json.get("operands").has(index))
+ return (String) null;
- JsonNode date = json.get("operands").get(index);
+ JsonNode date = json.get("operands").get(index);
- if (!date.has("@type"))
- return (String) null;
+ if (!date.has("@type"))
+ return (String) null;
- if (!date.get("@type").asText().equals("korap:date"))
- return (String) null;
+ if (!date.get("@type").asText().equals("korap:date"))
+ return (String) null;
+
+ if (!date.has("@value"))
+ return (String) null;
- if (!date.has("@value"))
- return (String) null;
-
- return date.get("@value").asText();
+ return date.get("@value").asText();
};
public BooleanFilter and (String type, String ... terms) {
- BooleanFilter bf = new BooleanFilter();
- bf.and(type, terms);
- return bf;
+ BooleanFilter bf = new BooleanFilter();
+ bf.and(type, terms);
+ return bf;
};
public BooleanFilter or (String type, String ... terms) {
- if (DEBUG)
- log.debug("Got some terms here");
- BooleanFilter bf = new BooleanFilter();
- bf.or(type, terms);
- return bf;
+ if (DEBUG)
+ log.debug("Got some terms here");
+ BooleanFilter bf = new BooleanFilter();
+ bf.or(type, terms);
+ return bf;
};
public BooleanFilter and (String type, RegexFilter re) {
- BooleanFilter bf = new BooleanFilter();
- bf.and(type, re);
- return bf;
+ BooleanFilter bf = new BooleanFilter();
+ bf.and(type, re);
+ return bf;
};
public BooleanFilter or (String type, RegexFilter re) {
- BooleanFilter bf = new BooleanFilter();
- bf.or(type, re);
- return bf;
+ BooleanFilter bf = new BooleanFilter();
+ bf.or(type, re);
+ return bf;
};
public BooleanFilter since (String date) {
- BooleanFilter bf = new BooleanFilter();
- bf.since(date);
- return bf;
+ BooleanFilter bf = new BooleanFilter();
+ bf.since(date);
+ return bf;
};
public BooleanFilter till (String date) {
- BooleanFilter bf = new BooleanFilter();
- bf.till(date);
- return bf;
+ BooleanFilter bf = new BooleanFilter();
+ bf.till(date);
+ return bf;
};
public BooleanFilter date (String date) {
- BooleanFilter bf = new BooleanFilter();
- bf.date(date);
- return bf;
+ BooleanFilter bf = new BooleanFilter();
+ bf.date(date);
+ return bf;
};
public BooleanFilter between (String date1, String date2) {
- BooleanFilter bf = new BooleanFilter();
- bf.between(date1, date2);
- return bf;
+ BooleanFilter bf = new BooleanFilter();
+ bf.between(date1, date2);
+ return bf;
};
public RegexFilter re (String regex) {
- return new RegexFilter(regex);
+ return new RegexFilter(regex);
};
public BooleanFilter getBooleanFilter() {
- return this.filter;
+ return this.filter;
};
public void setBooleanFilter (BooleanFilter bf) {
- this.filter = bf;
+ this.filter = bf;
};
public Query toQuery () {
- return this.filter.toQuery();
+ return this.filter.toQuery();
};
public String toString () {
- return this.filter.toQuery().toString();
+ return this.filter.toQuery().toString();
};
};
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java
index 28df548..78309e2 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java
@@ -41,7 +41,7 @@
*
* </ul>
*
- * @author Nils Diewald
+ * @author diewald
* @author margaretha
*/
public class SpanElementQuery extends SpanWithIdQuery {
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanNextQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanNextQuery.java
index d77a4bb..dbef6db 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanNextQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanNextQuery.java
@@ -1,11 +1,5 @@
package de.ids_mannheim.korap.query;
-// Based on SpanNearQuery
-
-/*
- * Todo: Make one Spanarray and switch between the results of A and B.
- */
-
import java.io.IOException;
import java.util.Map;
@@ -22,6 +16,11 @@
import de.ids_mannheim.korap.query.spans.NextSpans;
+/*
+ * Based on SpanNearQuery
+ * Todo: Make one Spanarray and switch between the results of A and B.
+ */
+
/**
* SpanNextQuery matches two spans which are directly next to each other. It is
* identical to a phrase query with exactly two clauses.
@@ -37,7 +36,8 @@
* new SpanTermQuery(new Term("tokens", "s:off")));
* </pre>
*
- * @author diewald, margaretha
+ * @author diewald
+ * @author margaretha
*
*/
public class SpanNextQuery extends SimpleSpanQuery implements Cloneable {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java
index f01bd1f..a4d7159 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java
@@ -22,7 +22,7 @@
* paragraphs.
*
* @author margaretha
- * @author Nils Diewald
+ * @author diewald
*/
public class ElementSpans extends SpansWithId {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/NextSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/NextSpans.java
index 2d79132..44045ef 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/NextSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/NextSpans.java
@@ -22,7 +22,7 @@
* The implementation allows multiple matches at the same firstspan position.
*
* @author margaretha, diewald
- * */
+ */
public class NextSpans extends SimpleSpans {
private List<CandidateSpan> matchList;
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
index 609dcdc..3d88522 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
@@ -25,7 +25,7 @@
/**
* Compare two spans and check how they relate positionally.
*
- * @author Nils Diewald
+ * @author diewald
*/
public class WithinSpans extends Spans {
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 c826f71..d8bfe38 100644
--- a/src/main/java/de/ids_mannheim/korap/response/KorapResponse.java
+++ b/src/main/java/de/ids_mannheim/korap/response/KorapResponse.java
@@ -25,6 +25,7 @@
*
* @author Nils Diewald
* @see de.ids_mannheim.korap.response.Notifications
+ * @see de.ids_mannheim.korap.response.serialize.KorapResponseDeserializer
*/
@JsonDeserialize(using = KorapResponseDeserializer.class)
public class KorapResponse extends Notifications {
@@ -34,6 +35,7 @@
private String benchmark;
private boolean timeExceeded = false;
+
/**
* Construct a new KorapResponse object.
*
@@ -43,6 +45,17 @@
/**
+ * Get string representation of the backend's version.
+ *
+ * @return String representation of the backend's version
+ */
+ @JsonIgnore
+ public String getVersion () {
+ return this.version;
+ };
+
+
+ /**
* Set the string representation of the backend's version.
*
* @param version The string representation of the backend's version
@@ -56,13 +69,14 @@
/**
- * Get string representation of the backend's version.
+ * Get string representation of the backend's name.
+ * All nodes in a cluster should have the same backend name.
*
- * @return String representation of the backend's version
+ * @return String representation of the backend's name
*/
@JsonIgnore
- public String getVersion () {
- return this.version;
+ public String getName () {
+ return this.name;
};
@@ -81,14 +95,14 @@
/**
- * Get string representation of the backend's name.
- * All nodes in a cluster should have the same backend name.
+ * Get string representation of the node's name.
+ * Each node in a cluster has a unique name.
*
- * @return String representation of the backend's name
+ * @return String representation of the node's name
*/
@JsonIgnore
- public String getName () {
- return this.name;
+ public String getNode () {
+ return this.node;
};
@@ -107,14 +121,14 @@
/**
- * Get string representation of the node's name.
- * Each node in a cluster has a unique name.
+ * Check if the response time was exceeded.
*
- * @return String representation of the node's name
+ * @return <tt>true</tt> in case the response had a timeout,
+ * otherwise <tt>false</tt>
*/
@JsonIgnore
- public String getNode () {
- return this.node;
+ public boolean hasTimeExceeded () {
+ return this.timeExceeded;
};
@@ -139,16 +153,16 @@
/**
- * Check if the response time was exceeded.
+ * Get the benchmark time as a string.
*
- * @return <tt>true</tt> in case the response had a timeout,
- * otherwise <tt>false</tt>
+ * @return String representation of the benchmark
+ * (including trailing time unit)
*/
@JsonIgnore
- public boolean hasTimeExceeded () {
- return this.timeExceeded;
+ public String getBenchmark () {
+ return this.benchmark;
};
-
+
/**
* Set the benchmark as timestamp differences.
@@ -181,19 +195,18 @@
this.benchmark = bm;
return this;
};
-
+
/**
- * Get the benchmark time as a string.
+ * Get the listener URI as a string.
*
- * @return String representation of the benchmark
- * (including trailing time unit)
+ * @return The listener URI as a string representation
*/
@JsonIgnore
- public String getBenchmark () {
- return this.benchmark;
+ public String getListener () {
+ return this.listener;
};
-
+
/**
* Set the listener URI as a String. This is probably the localhost
@@ -212,17 +225,6 @@
this.listener = listener;
return this;
};
-
-
- /**
- * Get the listener URI as a string.
- *
- * @return The listener URI as a string representation
- */
- @JsonIgnore
- public String getListener () {
- return this.listener;
- };
/**
@@ -266,6 +268,7 @@
return (JsonNode) json;
};
+
/**
* Serialize response as a JSON string.
* <p>
diff --git a/src/main/java/de/ids_mannheim/korap/response/Message.java b/src/main/java/de/ids_mannheim/korap/response/Message.java
index 9a0c91b..c121c9d 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Message.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Message.java
@@ -29,6 +29,7 @@
private int code = 0;
private LinkedList<String> parameters;
+
/**
* Construct a new message object.
*
@@ -37,8 +38,8 @@
* @return The new message object
*/
public Message (int code, String msg) {
- this.code = code;
- this.msg = msg;
+ this.code = code;
+ this.msg = msg;
};
/**
@@ -48,17 +49,6 @@
*/
public Message () {};
- /**
- * Set the string representation of the message.
- *
- * @param msg String representation of the message
- * @return Message object for chaining
- */
- @JsonIgnore
- public Message setMessage (String msg) {
- this.msg = msg;
- return this;
- };
/**
* Return the string representation of the message.
@@ -67,9 +57,35 @@
*/
@JsonIgnore
public String getMessage () {
- return this.msg;
+ return this.msg;
};
+
+ /**
+ * Set the string representation of the message.
+ *
+ * @param msg String representation of the message
+ * @return Message object for chaining
+ */
+ @JsonIgnore
+ public Message setMessage (String msg) {
+ this.msg = msg;
+ return this;
+ };
+
+
+ /**
+ * Return the integer code representation of the message.
+ *
+ * @return Integer code representation of the message
+ */
+ @JsonIgnore
+ public int getCode () {
+ return this.code;
+ };
+
+
+
/**
* Set the integer representation of the message.
*
@@ -78,18 +94,8 @@
*/
@JsonIgnore
public Message setCode (int code) {
- this.code = code;
- return this;
- };
-
- /**
- * Return the integer code representation of the message.
- *
- * @return Integer code representation of the message
- */
- @JsonIgnore
- public int getCode () {
- return this.code;
+ this.code = code;
+ return this;
};
@@ -99,12 +105,13 @@
* @return Message object for chaining
*/
public Message addParameter (String param) {
- if (this.parameters == null)
- this.parameters = new LinkedList<String>();
- this.parameters.add(param);
- return this;
+ if (this.parameters == null)
+ this.parameters = new LinkedList<String>();
+ this.parameters.add(param);
+ return this;
};
+
/**
* Create a clone of the Message.
*
@@ -112,23 +119,23 @@
* @throws CloneNotSupportedException if message can't be cloned
*/
public Object clone () throws CloneNotSupportedException {
- Message clone = new Message();
+ Message clone = new Message();
- // Copy message string
- if (this.msg != null)
- clone.msg = this.msg;
+ // Copy message string
+ if (this.msg != null)
+ clone.msg = this.msg;
- // Copy message code
- clone.code = this.code;
+ // Copy message code
+ clone.code = this.code;
+
+ // Copy parameters
+ if (this.parameters != null) {
+ for (String p : this.parameters) {
+ clone.addParameter(p);
+ };
+ };
- // Copy parameters
- if (this.parameters != null) {
- for (String p : this.parameters) {
- clone.addParameter(p);
- };
- };
-
- return clone;
+ return clone;
};
/**
@@ -137,16 +144,16 @@
* @return JsonNode representation of the message
*/
public JsonNode toJsonNode () {
- ArrayNode message = mapper.createArrayNode();
+ ArrayNode message = mapper.createArrayNode();
- if (this.code != 0)
- message.add(this.getCode());
-
- message.add(this.getMessage());
- if (parameters != null)
- for (String p : parameters)
- message.add(p);
- return (JsonNode) message;
+ if (this.code != 0)
+ message.add(this.getCode());
+
+ message.add(this.getMessage());
+ if (parameters != null)
+ for (String p : parameters)
+ message.add(p);
+ return (JsonNode) message;
};
@@ -160,16 +167,16 @@
* @return String representation of the message
*/
public String toJsonString () {
- String msg = "";
- try {
- return mapper.writeValueAsString(this.toJsonNode());
- }
- catch (Exception e) {
- // Bad in case the message contains quotes!
- msg = ", \"" + e.getLocalizedMessage() + "\"";
- };
- return
- "[620, " +
- "\"Unable to generate JSON\"" + msg + "]";
+ String msg = "";
+ try {
+ return mapper.writeValueAsString(this.toJsonNode());
+ }
+ catch (Exception e) {
+ // Bad in case the message contains quotes!
+ msg = ", \"" + e.getLocalizedMessage() + "\"";
+ };
+ return
+ "[620, " +
+ "\"Unable to generate JSON\"" + msg + "]";
};
};
diff --git a/src/main/java/de/ids_mannheim/korap/response/Messages.java b/src/main/java/de/ids_mannheim/korap/response/Messages.java
index c78e6aa..cc7b723 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Messages.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Messages.java
@@ -34,36 +34,38 @@
// Private class for iterator implementation
private class MessageIterator implements Iterator<Message> {
- int index;
+ int index;
- // Constructor
+ // Constructor
public MessageIterator () {
this.index = 0;
};
@Override
- public boolean hasNext () {
+ public boolean hasNext () {
return this.index < messages.size();
};
@Override
- public Message next () {
+ public Message next () {
return messages.get(this.index++);
};
@Override
public void remove () {
- messages.remove(this.index);
+ messages.remove(this.index);
};
};
+
/**
* Construct a new Messages object.
*/
public Messages () {
- this.messages = new ArrayList<Message>(3);
+ this.messages = new ArrayList<Message>(3);
};
+
/**
* Get the iterator object.
*
@@ -73,6 +75,7 @@
return new MessageIterator();
};
+
/**
* Append a new message.
*
@@ -82,16 +85,17 @@
* @return New Message object
*/
public Message add (int code,
- String message,
- String ... terms) {
- Message newMsg = new Message(code, message);
- messages.add(newMsg);
- if (terms != null)
- for (String t : terms)
- newMsg.addParameter(t);
- return newMsg;
+ String message,
+ String ... terms) {
+ Message newMsg = new Message(code, message);
+ messages.add(newMsg);
+ if (terms != null)
+ for (String t : terms)
+ newMsg.addParameter(t);
+ return newMsg;
};
+
/**
* Append an existing message.
*
@@ -99,14 +103,14 @@
* @return Cloned Message object
*/
public Message add (Message msg) {
- try {
- Message msgClone = (Message) msg.clone();
- messages.add(msgClone);
- return msgClone;
- }
- catch (CloneNotSupportedException e) {
- };
- return (Message) null;
+ try {
+ Message msgClone = (Message) msg.clone();
+ messages.add(msgClone);
+ return msgClone;
+ }
+ catch (CloneNotSupportedException e) {
+ };
+ return (Message) null;
};
/**
@@ -117,34 +121,34 @@
* @throws QueryException if notification is not well formed (Error 750)
*/
public Message add (JsonNode msg) throws QueryException {
- if (!msg.isArray() || !msg.has(0))
- throw new QueryException(
- 750, "Passed notifications are not well formed"
- );
+ if (!msg.isArray() || !msg.has(0))
+ throw new QueryException(
+ 750, "Passed notifications are not well formed"
+ );
- // Valid message
- Message newMsg = new Message();
- short i = 1;
- if (msg.get(0).isNumber()) {
- newMsg.setCode(msg.get(0).asInt());
- if (!msg.has(1))
- throw new QueryException(
- 750, "Passed notifications are not well formed"
- );
- newMsg.setMessage(msg.get(1).asText());
- i++;
- }
- else {
- newMsg.setMessage(msg.get(0).asText());
- };
+ // Valid message
+ Message newMsg = new Message();
+ short i = 1;
+ if (msg.get(0).isNumber()) {
+ newMsg.setCode(msg.get(0).asInt());
+ if (!msg.has(1))
+ throw new QueryException(
+ 750, "Passed notifications are not well formed"
+ );
+ newMsg.setMessage(msg.get(1).asText());
+ i++;
+ }
+ else {
+ newMsg.setMessage(msg.get(0).asText());
+ };
- // Add parameters
- while (msg.has(i))
- newMsg.addParameter(msg.get(i++).asText());
-
- // Add messages to list
- this.add(newMsg);
- return newMsg;
+ // Add parameters
+ while (msg.has(i))
+ newMsg.addParameter(msg.get(i++).asText());
+
+ // Add messages to list
+ this.add(newMsg);
+ return newMsg;
};
@@ -155,32 +159,34 @@
* @return Messages object for chaining.
*/
public Messages add (Messages msgs) {
- try {
- for (Message msg : msgs.getMessages())
- this.add((Message) msg.clone());
- }
- catch (CloneNotSupportedException e) {
- };
- return this;
+ try {
+ for (Message msg : msgs.getMessages())
+ this.add((Message) msg.clone());
+ }
+ catch (CloneNotSupportedException e) {
+ };
+ return this;
};
+
/**
* Clear all messages.
*
* @return Messages object for chaining
*/
public Messages clear () {
- this.messages.clear();
- return this;
+ this.messages.clear();
+ return this;
};
+
/**
* Get the number of the messages.
*
* @param Integer representing the number of messages in the list.
*/
public int size () {
- return this.messages.size();
+ return this.messages.size();
};
@@ -192,11 +198,12 @@
*/
@JsonIgnore
public Message get (int index) {
- if (index >= this.size())
- return (Message) null;
- return this.messages.get(index);
+ if (index >= this.size())
+ return (Message) null;
+ return this.messages.get(index);
};
+
/**
* Return all messages.
*
@@ -204,7 +211,7 @@
*/
@JsonIgnore
public List<Message> getMessages () {
- return this.messages;
+ return this.messages;
};
@@ -215,24 +222,25 @@
* @throws CloneNotSupportedException if messages can't be cloned
*/
public Object clone () throws CloneNotSupportedException {
- Messages clone = new Messages();
- for (Message m : this.messages) {
- clone.add((Message) m.clone());
- };
+ Messages clone = new Messages();
+ for (Message m : this.messages) {
+ clone.add((Message) m.clone());
+ };
- return clone;
+ return clone;
};
+
/**
* Serialize Messages as a JsonNode.
*
* @return JsonNode representation of all messages
*/
public JsonNode toJsonNode () {
- ArrayNode messageArray = mapper.createArrayNode();
- for (Message msg : this.messages)
- messageArray.add(msg.toJsonNode());
- return (JsonNode) messageArray;
+ ArrayNode messageArray = mapper.createArrayNode();
+ for (Message msg : this.messages)
+ messageArray.add(msg.toJsonNode());
+ return (JsonNode) messageArray;
};
@@ -249,17 +257,17 @@
* @return String representation of all messages
*/
public String toJsonString () {
- String msg = "";
- try {
- return mapper.writeValueAsString(this.toJsonNode());
- }
- catch (Exception e) {
- // Bad in case the message contains quotes!
- msg = ", \"" + e.getLocalizedMessage() + "\"";
- };
+ String msg = "";
+ try {
+ return mapper.writeValueAsString(this.toJsonNode());
+ }
+ catch (Exception e) {
+ // Bad in case the message contains quotes!
+ msg = ", \"" + e.getLocalizedMessage() + "\"";
+ };
- return
- "[620, " +
- "\"Unable to generate JSON\"" + msg + "]";
+ return
+ "[620, " +
+ "\"Unable to generate JSON\"" + msg + "]";
};
};
diff --git a/src/main/java/de/ids_mannheim/korap/response/Notifications.java b/src/main/java/de/ids_mannheim/korap/response/Notifications.java
index 9074828..ad65024 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Notifications.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Notifications.java
@@ -45,9 +45,43 @@
// Create object mapper for JSON generation
ObjectMapper mapper = new ObjectMapper();
- private Messages warnings,
- errors,
- messages;
+ private Messages warnings, errors, messages;
+
+
+ /**
+ * Check for warnings.
+ *
+ * @return <tt>true</tt> in case there are warnings, otherwise <tt>false</tt>
+ */
+ public boolean hasWarnings () {
+ if (this.warnings == null || this.warnings.size() == 0)
+ return false;
+ return true;
+ };
+
+
+ /**
+ * Return all warnings.
+ *
+ * @return The <code>Messages</code> object representing all warnings
+ */
+ public Messages getWarnings () {
+ return this.warnings;
+ };
+
+
+ /**
+ * Return a specific warning based on an index.
+ *
+ * @param index The index of the warning in the list of warnings.
+ * @return The message in case it exists, otherwise <code>null</code>
+ */
+ public Message getWarning (int index) {
+ if (this.warnings != null)
+ return this.warnings.get(index);
+ return (Message) null;
+ };
+
/**
* Appends a new warning.
@@ -58,12 +92,13 @@
* @return Notification object for chaining
*/
public Notifications addWarning (int code, String msg, String ... terms) {
- if (this.warnings == null)
- this.warnings = new Messages();
- this.warnings.add(code, msg, terms);
- return this;
+ if (this.warnings == null)
+ this.warnings = new Messages();
+ this.warnings.add(code, msg, terms);
+ return this;
};
+
/**
* Appends a new warning.
*
@@ -71,19 +106,20 @@
* @return Notification object for chaining
*/
public Notifications addWarning (JsonNode node) {
- if (this.warnings == null)
- this.warnings = new Messages();
-
- try {
- this.warnings.add(node);
- }
- catch (QueryException qe) {
- this.warnings.add(qe.getErrorCode(), qe.getMessage());
- };
-
- return this;
+ if (this.warnings == null)
+ this.warnings = new Messages();
+
+ try {
+ this.warnings.add(node);
+ }
+ catch (QueryException qe) {
+ this.warnings.add(qe.getErrorCode(), qe.getMessage());
+ };
+
+ return this;
};
+
/**
* Appends new warnings.
*
@@ -91,105 +127,21 @@
* @return Notification object for chaining
*/
public Notifications addWarnings (Messages msgs) {
- if (this.warnings == null)
- this.warnings = msgs;
- else
- this.warnings.add(msgs);
- return this;
+ if (this.warnings == null)
+ this.warnings = msgs;
+ else
+ this.warnings.add(msgs);
+ return this;
};
/**
- * Return all warnings.
- *
- * @return The <code>Messages</code> object representing all warnings
- */
- public Messages getWarnings () {
- return this.warnings;
- };
-
- /**
- * Return a specific warning based on an index.
- *
- * @param index The index of the warning in the list of warnings.
- * @return The message in case it exists, otherwise <code>null</code>
- */
- public Message getWarning (int index) {
- if (this.warnings != null)
- return this.warnings.get(index);
- return (Message) null;
- };
-
-
- /**
- * Check for warnings.
- *
- * @return <tt>true</tt> in case there are warnings, otherwise <tt>false</tt>
- */
- public boolean hasWarnings () {
- if (this.warnings == null || this.warnings.size() == 0)
- return false;
- return true;
- };
-
- /**
- * Appends a new error.
- *
- * @param code Integer code representation of the error
- * @param msg String representation of the error
- * @param terms Optional strings of additional information
- * @return Notification object for chaining
- */
- public Notifications addError (int code, String msg, String ... terms) {
- if (this.errors == null)
- this.errors = new Messages();
- this.errors.add(code, msg, terms);
- return this;
- };
-
- /**
- * Appends a new error.
- *
- * @param node <code>JsonNode</code> representing an error message
- * @return Notification object for chaining
- */
- public Notifications addError (JsonNode msg) {
- if (this.errors == null)
- this.errors = new Messages();
- try {
- this.errors.add(msg);
- }
- catch (QueryException qe) {
- this.errors.add(qe.getErrorCode(), qe.getMessage());
- };
-
- return this;
- };
-
-
- /**
- * Appends new errors.
- *
- * @param msgs <code>Messages</code> representing multiple errors
- * @return Notification object for chaining
- */
- public Notifications addErrors (Messages msgs) {
- if (this.errors == null)
- this.errors = msgs;
- else
- this.errors.add(msgs);
- return this;
- };
-
-
-
- /**
* Return all errors.
*
* @return The <code>Messages</code> object representing all errors
*/
public Messages getErrors () {
- return this.errors;
+ return this.errors;
};
@@ -200,9 +152,9 @@
* @return The message in case it exists, otherwise <code>null</code>
*/
public Message getError (int index) {
- if (this.errors != null)
- return this.errors.get(index);
- return (Message) null;
+ if (this.errors != null)
+ return this.errors.get(index);
+ return (Message) null;
};
@@ -212,9 +164,94 @@
* @return <tt>true</tt> in case there are errors, otherwise <tt>false</tt>
*/
public boolean hasErrors () {
- if (this.errors == null || this.errors.size() == 0)
- return false;
- return true;
+ if (this.errors == null || this.errors.size() == 0)
+ return false;
+ return true;
+ };
+
+
+ /**
+ * Appends a new error.
+ *
+ * @param code Integer code representation of the error
+ * @param msg String representation of the error
+ * @param terms Optional strings of additional information
+ * @return Notification object for chaining
+ */
+ public Notifications addError (int code, String msg, String ... terms) {
+ if (this.errors == null)
+ this.errors = new Messages();
+ this.errors.add(code, msg, terms);
+ return this;
+ };
+
+
+ /**
+ * Appends a new error.
+ *
+ * @param node <code>JsonNode</code> representing an error message
+ * @return Notification object for chaining
+ */
+ public Notifications addError (JsonNode msg) {
+ if (this.errors == null)
+ this.errors = new Messages();
+ try {
+ this.errors.add(msg);
+ }
+ catch (QueryException qe) {
+ this.errors.add(qe.getErrorCode(), qe.getMessage());
+ };
+
+ return this;
+ };
+
+
+ /**
+ * Appends new errors.
+ *
+ * @param msgs <code>Messages</code> representing multiple errors
+ * @return Notification object for chaining
+ */
+ public Notifications addErrors (Messages msgs) {
+ if (this.errors == null)
+ this.errors = msgs;
+ else
+ this.errors.add(msgs);
+ return this;
+ };
+
+
+ /**
+ * Return all messages.
+ *
+ * @return The <code>Messages</code> object representing all messages
+ */
+ public Messages getMessages () {
+ return this.messages;
+ };
+
+ /**
+ * Return a specific message based on an index.
+ *
+ * @param index The index of the message in the list of messages.
+ * @return The message in case it exists, otherwise <code>null</code>
+ */
+ public Message getMessage (int index) {
+ if (this.messages != null)
+ return this.messages.get(index);
+ return (Message) null;
+ };
+
+
+ /**
+ * Check for messages.
+ *
+ * @return <tt>true</tt> in case there are messages, otherwise <tt>false</tt>
+ */
+ public boolean hasMessages () {
+ if (this.messages == null || this.messages.size() == 0)
+ return false;
+ return true;
};
@@ -227,12 +264,13 @@
* @return Notification object for chaining
*/
public Notifications addMessage (int code, String msg, String ... terms) {
- if (this.messages == null)
- this.messages = new Messages();
- this.messages.add(code, msg, terms);
- return this;
+ if (this.messages == null)
+ this.messages = new Messages();
+ this.messages.add(code, msg, terms);
+ return this;
};
+
/**
* Appends a new message.
*
@@ -240,15 +278,15 @@
* @return Notification object for chaining
*/
public Notifications addMessage (JsonNode msg) {
- if (this.messages == null)
- this.messages = new Messages();
- try {
- this.messages.add(msg);
- }
- catch (QueryException qe) {
- this.messages.add(qe.getErrorCode(), qe.getMessage());
- };
- return this;
+ if (this.messages == null)
+ this.messages = new Messages();
+ try {
+ this.messages.add(msg);
+ }
+ catch (QueryException qe) {
+ this.messages.add(qe.getErrorCode(), qe.getMessage());
+ };
+ return this;
};
@@ -259,45 +297,11 @@
* @return Notification object for chaining
*/
public Notifications addMessages (Messages msgs) {
- if (this.messages == null)
- this.messages = msgs;
- else
- this.messages.add(msgs);
- return this;
- };
-
-
- /**
- * Return all messages.
- *
- * @return The <code>Messages</code> object representing all messages
- */
- public Messages getMessages () {
- return this.messages;
- };
-
- /**
- * Return a specific message based on an index.
- *
- * @param index The index of the message in the list of messages.
- * @return The message in case it exists, otherwise <code>null</code>
- */
- public Message getMessage (int index) {
- if (this.messages != null)
- return this.messages.get(index);
- return (Message) null;
- };
-
-
- /**
- * Check for messages.
- *
- * @return <tt>true</tt> in case there are messages, otherwise <tt>false</tt>
- */
- public boolean hasMessages () {
- if (this.messages == null || this.messages.size() == 0)
- return false;
- return true;
+ if (this.messages == null)
+ this.messages = msgs;
+ else
+ this.messages.add(msgs);
+ return this;
};
@@ -308,17 +312,17 @@
* @return Notification object for chaining
*/
public Notifications copyNotificationsFrom (Notifications notes) {
- try {
- if (notes.hasErrors())
- this.addErrors((Messages) notes.getErrors().clone());
- if (notes.hasWarnings())
- this.addWarnings((Messages) notes.getWarnings().clone());
- if (notes.hasMessages())
- this.addMessages((Messages) notes.getMessages().clone());
- }
- catch (CloneNotSupportedException cnse) {
- };
- return this;
+ try {
+ if (notes.hasErrors())
+ this.addErrors((Messages) notes.getErrors().clone());
+ if (notes.hasWarnings())
+ this.addWarnings((Messages) notes.getWarnings().clone());
+ if (notes.hasMessages())
+ this.addMessages((Messages) notes.getMessages().clone());
+ }
+ catch (CloneNotSupportedException cnse) {
+ };
+ return this;
};
@@ -330,33 +334,33 @@
*/
public Notifications copyNotificationsFrom (JsonNode request) {
- // Add warnings from JSON
- if (request.has("warnings") &&
- request.get("warnings").isArray()) {
- JsonNode msgs = request.get("warnings");
- for (JsonNode msg : msgs)
- this.addWarning(msg);
- };
+ // Add warnings from JSON
+ if (request.has("warnings") &&
+ request.get("warnings").isArray()) {
+ JsonNode msgs = request.get("warnings");
+ for (JsonNode msg : msgs)
+ this.addWarning(msg);
+ };
- // Add messages from JSON
- if (request.has("messages") &&
- request.get("messages").isArray()) {
- JsonNode msgs = request.get("messages");
- if (msgs.isArray())
- for (JsonNode msg : msgs)
- this.addMessage(msg);
- };
+ // Add messages from JSON
+ if (request.has("messages") &&
+ request.get("messages").isArray()) {
+ JsonNode msgs = request.get("messages");
+ if (msgs.isArray())
+ for (JsonNode msg : msgs)
+ this.addMessage(msg);
+ };
- // Add errors from JSON
- if (request.has("errors") &&
- request.get("errors").isArray()) {
- JsonNode msgs = request.get("errors");
- if (msgs.isArray())
- for (JsonNode msg : msgs)
- this.addError(msg);
- };
-
- return this;
+ // Add errors from JSON
+ if (request.has("errors") &&
+ request.get("errors").isArray()) {
+ JsonNode msgs = request.get("errors");
+ if (msgs.isArray())
+ for (JsonNode msg : msgs)
+ this.addError(msg);
+ };
+
+ return this;
};
@@ -366,13 +370,13 @@
* @return Notification object for chaining
*/
public Notifications clearNotifications () {
- if (this.warnings != null)
- this.warnings.clear();
- if (this.messages != null)
- this.messages.clear();
- if (this.errors != null)
- this.errors.clear();
- return this;
+ if (this.warnings != null)
+ this.warnings.clear();
+ if (this.messages != null)
+ this.messages.clear();
+ if (this.errors != null)
+ this.errors.clear();
+ return this;
};
@@ -382,19 +386,20 @@
* @return JsonNode representation of all warnings, errors, and messages
*/
public JsonNode toJsonNode () {
- ObjectNode json = mapper.createObjectNode();
+ ObjectNode json = mapper.createObjectNode();
- // Add messages
- if (this.hasWarnings())
- json.put("warnings", this.getWarnings().toJsonNode());
- if (this.hasErrors())
- json.put("errors", this.getErrors().toJsonNode());
- if (this.hasMessages())
- json.put("messages", this.getMessages().toJsonNode());
-
- return (JsonNode) json;
+ // Add messages
+ if (this.hasWarnings())
+ json.put("warnings", this.getWarnings().toJsonNode());
+ if (this.hasErrors())
+ json.put("errors", this.getErrors().toJsonNode());
+ if (this.hasMessages())
+ json.put("messages", this.getMessages().toJsonNode());
+
+ return (JsonNode) json;
};
+
/**
* Serialize Notifications as a JSON string.
* <p>
@@ -413,22 +418,22 @@
* @return String representation of all warnings, errors, and messages
*/
public String toJsonString () {
- String msg = "";
- try {
- JsonNode node = this.toJsonNode();
- if (node == null)
- return "{}";
- return mapper.writeValueAsString(node);
- }
- catch (Exception e) {
- // Bad in case the message contains quotes!
- msg = ", \"" + e.getLocalizedMessage() + "\"";
- };
+ String msg = "";
+ try {
+ JsonNode node = this.toJsonNode();
+ if (node == null)
+ return "{}";
+ return mapper.writeValueAsString(node);
+ }
+ catch (Exception e) {
+ // Bad in case the message contains quotes!
+ msg = ", \"" + e.getLocalizedMessage() + "\"";
+ };
- return
- "{\"errors\" : [" +
- "[620, " +
- "\"Unable to generate JSON\"" + msg + "]" +
- "]}";
+ return
+ "{\"errors\" : [" +
+ "[620, " +
+ "\"Unable to generate JSON\"" + msg + "]" +
+ "]}";
};
};
diff --git a/src/main/java/de/ids_mannheim/korap/response/serialize/KorapResponseDeserializer.java b/src/main/java/de/ids_mannheim/korap/response/serialize/KorapResponseDeserializer.java
index 3e009bd..23525ff 100644
--- a/src/main/java/de/ids_mannheim/korap/response/serialize/KorapResponseDeserializer.java
+++ b/src/main/java/de/ids_mannheim/korap/response/serialize/KorapResponseDeserializer.java
@@ -4,15 +4,30 @@
import java.io.*;
import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.DeserializationContext;
import de.ids_mannheim.korap.response.KorapResponse;
+/**
+ * JSON Deserialization class for Jackson, used by KorapResponse.
+ * No direct usage intended.
+ *
+ * @author Nils Diewald
+ * @see de.ids_mannheim.korap.KorapResponse
+ */
public class KorapResponseDeserializer extends JsonDeserializer<KorapResponse> {
-
+
+ /**
+ * Deserialization of JSON format.
+ *
+ * @param parser A parser instance for consuming JSON.
+ * @param ctxt A deserialization context.
+ * @return The deserialized KorapResponse object.
+ */
+
@Override
public KorapResponse deserialize (JsonParser parser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
@@ -27,7 +42,7 @@
// Is combined name and version
if (found > 0 && (found + 1 < fullVersion.length())) {
kresp.setName(fullVersion.substring(0, found))
- .setVersion(fullVersion.substring(found + 1));
+ .setVersion(fullVersion.substring(found + 1));
}
// Is only version number
else {
@@ -36,9 +51,8 @@
};
// Deserialize timeout information
- if (node.has("timeExceeded") && node.get("timeExceeded").asBoolean()) {
+ if (node.has("timeExceeded") && node.get("timeExceeded").asBoolean())
kresp.setTimeExceeded(true);
- };
// Deserialize benchmark information
if (node.has("benchmark"))
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestKorapDocument.java b/src/test/java/de/ids_mannheim/korap/index/TestKorapDocument.java
new file mode 100644
index 0000000..ed38e70
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/index/TestKorapDocument.java
@@ -0,0 +1,141 @@
+package de.ids_mannheim.korap.index;
+
+import java.util.*;
+import java.io.*;
+
+// This may be better in a model subdirectory
+
+import org.apache.lucene.util.Version;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.Bits;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.Ignore;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import de.ids_mannheim.korap.KorapDocument;
+
+@RunWith(JUnit4.class)
+public class TestKorapDocument {
+
+ private class KorapRealDocument extends KorapDocument {};
+
+ @Test
+ public void createDocument () throws IOException {
+ KorapRealDocument krd = new KorapRealDocument();
+ krd.setPubDate("2014-10-12");
+ assertEquals("20141012", krd.getPubDate().toString());
+ assertEquals("2014-10-12", krd.getPubDateString());
+
+ krd.setCreationDate("2012-09-05");
+ assertEquals("20120905", krd.getCreationDate().toString());
+ assertEquals("2012-09-05", krd.getCreationDateString());
+
+ krd.setAuthor("Stephen King");
+ assertEquals("Stephen King", krd.getAuthor());
+
+ krd.setPubPlace("Düsseldorf");
+ assertEquals("Düsseldorf", krd.getPubPlace());
+
+ krd.setUID(415);
+ assertEquals(415, krd.getUID());
+
+ krd.setUID("561");
+ assertEquals(561, krd.getUID());
+
+ try {
+ krd.setUID("zzz");
+ }
+ catch (NumberFormatException e) {
+ };
+ assertEquals(561, krd.getUID());
+
+ krd.setTitle("An Example");
+ assertEquals("An Example", krd.getTitle());
+
+ krd.setSubTitle("An Example");
+ assertEquals("An Example", krd.getSubTitle());
+
+ krd.setPrimaryData("We don't need no education");
+ assertEquals("We don't need no education", krd.getPrimaryData());
+ assertEquals("don't need no education", krd.getPrimaryData(3));
+ assertEquals("do", krd.getPrimaryData(3,5));
+ assertEquals(26, krd.getPrimaryDataLength());
+
+ krd.setPrimaryData("abc");
+ assertEquals(3, krd.getPrimaryDataLength());
+ krd.setPrimaryData("öäüß");
+ assertEquals(4, krd.getPrimaryDataLength());
+
+ krd.setTextSigle("U-abc-001");
+ assertEquals("U-abc-001", krd.getTextSigle());
+
+ krd.setDocSigle("U-abc");
+ assertEquals("U-abc", krd.getDocSigle());
+
+ krd.setCorpusSigle("U");
+ assertEquals("U", krd.getCorpusSigle());
+
+ krd.setPublisher("Pope Francis");
+ assertEquals("Pope Francis", krd.getPublisher());
+
+ krd.setEditor("Michael Knight");
+ assertEquals("Michael Knight", krd.getEditor());
+
+ krd.setTextType("shortstory");
+ assertEquals("shortstory", krd.getTextType());
+
+ krd.setTextTypeArt("Reportage");
+ assertEquals("Reportage", krd.getTextTypeArt());
+
+ krd.setTextTypeRef("Hm");
+ assertEquals("Hm", krd.getTextTypeRef());
+
+ krd.setTextColumn("Feuilleton");
+ assertEquals("Feuilleton", krd.getTextColumn());
+
+ krd.setTextDomain("Comment");
+ assertEquals("Comment", krd.getTextDomain());
+
+ krd.setLicense("cc");
+ assertEquals("cc", krd.getLicense());
+
+ krd.setPages("56-78");
+ assertEquals("56-78", krd.getPages());
+
+ krd.setFileEditionStatement("no problemo 1");
+ assertEquals("no problemo 1", krd.getFileEditionStatement());
+
+ krd.setBiblEditionStatement("no problemo 2");
+ assertEquals("no problemo 2", krd.getBiblEditionStatement());
+
+ krd.setLanguage("de");
+ assertEquals("de", krd.getLanguage());
+
+ krd.setCorpusTitle("Mannheimer Morgen");
+ assertEquals("Mannheimer Morgen", krd.getCorpusTitle());
+
+ krd.setCorpusSubTitle("Zeitung für Mannheim");
+ assertEquals("Zeitung für Mannheim", krd.getCorpusSubTitle());
+
+ krd.setCorpusAuthor("Peter Gabriel");
+ assertEquals("Peter Gabriel", krd.getCorpusAuthor());
+
+ krd.setCorpusEditor("Phil Collins");
+ assertEquals("Phil Collins", krd.getCorpusEditor());
+
+ krd.setDocTitle("New York Times");
+ assertEquals("New York Times", krd.getDocTitle());
+
+ krd.setDocSubTitle("Newspaper for New York");
+ assertEquals("Newspaper for New York", krd.getDocSubTitle());
+
+ krd.setDocAuthor("Dean Baquet");
+ assertEquals("Dean Baquet", krd.getDocAuthor());
+
+ krd.setDocEditor("Arthur Ochs Sulzberger Jr.");
+ assertEquals("Arthur Ochs Sulzberger Jr.", krd.getDocEditor());
+ };
+};
diff --git a/src/test/java/de/ids_mannheim/korap/response/TestResponse.java b/src/test/java/de/ids_mannheim/korap/response/TestResponse.java
index 43686f0..2ec3345 100644
--- a/src/test/java/de/ids_mannheim/korap/response/TestResponse.java
+++ b/src/test/java/de/ids_mannheim/korap/response/TestResponse.java
@@ -131,18 +131,25 @@
assertTrue(kresp.hasTimeExceeded());
assertTrue(kresp.hasWarnings());
-
jsonResponse = "{\"warnings\":[[123,\"This is a warning\"]," +
"[124,\"This is a second warning\"]],"+
- "\"error\":[[125,\"This is a single error\"]], "+
+ "\"errors\":[[125,\"This is a single error\"]], "+
" \"node\":\"tanja\", \"version\":\"seaweed-0.49\", " +
" \"benchmark\":\"40.5s\", \"listener\":\"10.0.10.14:678\"," +
"\"timeExceeded\":true }";
kresp = mapper.readValue(jsonResponse, KorapResponse.class);
-
- /*
-{,"version":"seaweed-0.49","timeExceeded":true,"node":"tanja","listener":"10.0.10.14:678","benchmark":"40.5s"}
- */
- // System.err.println(kresp.toJsonString());
+ assertTrue(kresp.hasWarnings());
+ assertTrue(kresp.hasErrors());
+ assertFalse(kresp.hasMessages());
+ assertEquals(kresp.getError(0).getMessage(), "This is a single error");
+ assertEquals(kresp.getWarning(0).getMessage(), "Response time exceeded");
+ assertEquals(kresp.getWarning(1).getMessage(), "This is a warning");
+ assertEquals(kresp.getWarning(2).getMessage(), "This is a second warning");
+ assertEquals("0.49", kresp.getVersion());
+ assertEquals("seaweed", kresp.getName());
+ assertEquals("40.5s", kresp.getBenchmark());
+ assertEquals("10.0.10.14:678", kresp.getListener());
+ assertEquals("tanja", kresp.getNode());
+ assertTrue(kresp.hasTimeExceeded());
};
};