Fix serialization of 'und', 'oder', and 'nicht' in Cosmas II
Change-Id: Idc16a73bfa6ed649e913889310f157933c4f2b05
diff --git a/Changes b/Changes
index ffea7ec..2747707 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
0.22 2016-06-03
- Spans now always wrap terms (diewald)
+ - Cosmas-II "und", "oder", and "nicht" operations
+ now serialize to unordered sequences (diewald)
0.21 2015-10-27
- Improved meta query builder (hanl)
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
index 1baa50a..ae544a1 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
@@ -25,7 +25,7 @@
* of the KoralQuery tree. See the official documentation for VC query
* syntax
* and functionality.
- *
+ *
* @author Michael Hanl (hanl@ids-mannheim.de)
* @author Joachim Bingel (bingel@ids-mannheim.de)
* @version 0.3.0
@@ -36,26 +36,31 @@
private static Logger log = LoggerFactory
.getLogger(CollectionQueryProcessor.class);
- public CollectionQueryProcessor() {
+
+ public CollectionQueryProcessor () {
KoralObjectGenerator.setQueryProcessor(this);
}
- public CollectionQueryProcessor(boolean verbose) {
+
+ public CollectionQueryProcessor (boolean verbose) {
KoralObjectGenerator.setQueryProcessor(this);
CollectionQueryProcessor.verbose = verbose;
}
- public CollectionQueryProcessor(String query) {
+
+ public CollectionQueryProcessor (String query) {
KoralObjectGenerator.setQueryProcessor(this);
process(query);
}
+
@Override
- public void process(String query) {
+ public void process (String query) {
ParseTree tree = parseCollectionQuery(query);
if (this.parser != null) {
super.parser = this.parser;
- }else {
+ }
+ else {
throw new NullPointerException("Parser has not been instantiated!");
}
log.info("Processing virtual collection query: " + query);
@@ -64,13 +69,15 @@
if (tree != null) {
log.debug("ANTLR parse tree: " + tree.toStringTree(parser));
processNode(tree);
- }else {
- addError(StatusCodes.MALFORMED_QUERY,
- "Could not parse query >>> " + query + " <<<.");
+ }
+ else {
+ addError(StatusCodes.MALFORMED_QUERY, "Could not parse query >>> "
+ + query + " <<<.");
}
}
- private void processNode(ParseTree node) {
+
+ private void processNode (ParseTree node) {
// Top-down processing
String nodeCat = getNodeCat(node);
openNodeCats.push(nodeCat);
@@ -90,8 +97,8 @@
*/
if (nodeCat.equals("relation")) {
- String operator = getNodeCat(node.getChild(1).getChild(0))
- .equals("&") ? "and" : "or";
+ String operator = getNodeCat(node.getChild(1).getChild(0)).equals(
+ "&") ? "and" : "or";
LinkedHashMap<String, Object> relationGroup = KoralObjectGenerator
.makeDocGroup(operator);
putIntoSuperObject(relationGroup);
@@ -114,14 +121,14 @@
requestMap = new LinkedHashMap<String, Object>();
return;
}
-// if (QueryUtils.checkDateValidity(valueNode.getText())) {
-// addWarning("The collection query contains a value that looks"
-// + " like a date ('" + valueNode.getText() + "') and an"
-// + " operator that is only defined for strings" + " ('"
-// + match + "'). The value is interpreted as"
-// + " a string. Use a date operator to ensure the value"
-// + " is treated as a date");
-// }
+ // if (QueryUtils.checkDateValidity(valueNode.getText())) {
+ // addWarning("The collection query contains a value that looks"
+ // + " like a date ('" + valueNode.getText() + "') and an"
+ // + " operator that is only defined for strings" + " ('"
+ // + match + "'). The value is interpreted as"
+ // + " a string. Use a date operator to ensure the value"
+ // + " is treated as a date");
+ // }
putIntoSuperObject(term);
}
@@ -192,7 +199,8 @@
}
}
token.put("wrap", term);
- }else {
+ }
+ else {
// child is 'term' or 'termGroup' -> process in extra method
LinkedHashMap<String, Object> termOrTermGroup = parseTermOrTermGroup(
node.getChild(1), negated);
@@ -231,18 +239,19 @@
}
+
/**
* Checks whether the combination of operator and value is legal
* (inequation operators <,>,<=,>= may only be used with dates).
*/
- private boolean checkOperatorValueConformance(
+ private boolean checkOperatorValueConformance (
LinkedHashMap<String, Object> term) {
String match = (String) term.get("match");
String type = (String) term.get("type");
if (type == null || type.equals("type:regex")) {
- if (!(match.equals("match:eq") || match.equals("match:ne") || match
- .equals("match:contains") || match
- .equals("match:containsnot"))) {
+ if (!(match.equals("match:eq") || match.equals("match:ne")
+ || match.equals("match:contains") || match
+ .equals("match:containsnot"))) {
addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
"You used an inequation operator with a string value.");
return false;
@@ -251,7 +260,8 @@
return true;
}
- private LinkedHashMap<String, Object> parseValue(ParseTree valueNode) {
+
+ private LinkedHashMap<String, Object> parseValue (ParseTree valueNode) {
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
if (getNodeCat(valueNode).equals("date")) {
map.put("type", "type:date");
@@ -275,15 +285,16 @@
return map;
}
+
/**
* Checks if value is a date
- *
+ *
* @param valueNode
* @return
*/
@Deprecated
- private boolean checkDateValidity(ParseTree valueNode) {
+ private boolean checkDateValidity (ParseTree valueNode) {
Pattern p = Pattern.compile("[0-9]{4}(-([0-9]{2})(-([0-9]{2}))?)?");
Matcher m = p.matcher(valueNode.getText());
@@ -294,7 +305,8 @@
if (month != null) {
if (Integer.parseInt(month) > 12) {
return false;
- }else if (day != null) {
+ }
+ else if (day != null) {
if (Integer.parseInt(day) > 31) {
return false;
}
@@ -303,7 +315,8 @@
return true;
}
- private String interpretMatchOperator(String match) {
+
+ private String interpretMatchOperator (String match) {
String out = null;
switch (match) {
case "<":
@@ -351,8 +364,9 @@
return out;
}
+
@Deprecated
- private String invertInequation(String op) {
+ private String invertInequation (String op) {
String inv = null;
switch (op) {
case "lt":
@@ -371,41 +385,47 @@
return inv;
}
- private void putIntoSuperObject(LinkedHashMap<String, Object> object) {
+
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object) {
putIntoSuperObject(object, 0);
}
+
@SuppressWarnings({ "unchecked" })
- private void putIntoSuperObject(LinkedHashMap<String, Object> object,
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object,
int objStackPosition) {
if (objectStack.size() > objStackPosition) {
ArrayList<Object> topObjectOperands = (ArrayList<Object>) objectStack
.get(objStackPosition).get("operands");
topObjectOperands.add(object);
- }else {
+ }
+ else {
// requestMap = object;
requestMap.put("collection", object);
}
}
- private LinkedHashMap<String, Object> parseTermOrTermGroup(ParseTree node,
+
+ private LinkedHashMap<String, Object> parseTermOrTermGroup (ParseTree node,
boolean negated) {
return parseTermOrTermGroup(node, negated, "token");
}
+
/**
* Parses a (term) or (termGroup) node
- *
+ *
* @param node
- * @param negatedGlobal Indicates whether the term/termGroup is globally
- * negated, e.g. through a negation operator preceding
- * the related token
- * like "![base=foo]". Global negation affects the
- * "match" parameter.
+ * @param negatedGlobal
+ * Indicates whether the term/termGroup is globally
+ * negated, e.g. through a negation operator preceding
+ * the related token
+ * like "![base=foo]". Global negation affects the
+ * "match" parameter.
* @return A term or termGroup object, depending on input
*/
@SuppressWarnings("unchecked")
- private LinkedHashMap<String, Object> parseTermOrTermGroup(ParseTree node,
+ private LinkedHashMap<String, Object> parseTermOrTermGroup (ParseTree node,
boolean negatedGlobal, String mode) {
if (getNodeCat(node).equals("term")) {
String key = null;
@@ -479,7 +499,8 @@
}
}
return term;
- }else {
+ }
+ else {
// For termGroups, establish a boolean relation between operands
// and recursively call this function with the term or termGroup
// operands.
@@ -509,7 +530,8 @@
}
}
- private ParserRuleContext parseCollectionQuery(String query) {
+
+ private ParserRuleContext parseCollectionQuery (String query) {
Lexer lexer = new CollectionQueryLexer((CharStream) null);
ParserRuleContext tree = null;
Antlr4DescriptiveErrorListener errorListener = new Antlr4DescriptiveErrorListener(
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
index 1b22f39..fbf63ac 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
@@ -669,6 +669,7 @@
// Step I: create group
LinkedHashMap<String, Object> disjunction = KoralObjectGenerator
.makeGroup("disjunction");
+ disjunction.put("inOrder", false); // Order is not important
objectStack.push(disjunction);
stackedObjects++;
// Step II: decide where to put
@@ -681,6 +682,7 @@
String nodeCat = getNodeCat(node);
LinkedHashMap<String, Object> distgroup = KoralObjectGenerator
.makeGroup("sequence");
+ distgroup.put("inOrder", false); // Order is not important
ArrayList<Object> distances = new ArrayList<Object>();
LinkedHashMap<String, Object> zerodistance = KoralObjectGenerator
.makeDistance("t", 0, 0);
@@ -1350,4 +1352,4 @@
}
return tree;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
index cc51dd4..cad4319 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
@@ -17,41 +17,45 @@
private Map meta;
private SpanContext spanContext;
- public MetaQueryBuilder() {
+
+ public MetaQueryBuilder () {
this.meta = new LinkedHashMap();
// this.meta.put("fields", new LinkedList<>());
}
+
/**
* context segment if context is either of type char or token.
* size can differ for left and right span
- *
+ *
* @param left
* @param leftType
* @param right
* @param rightType
* @return
*/
- public MetaQueryBuilder setSpanContext(Integer left, String leftType,
+ public MetaQueryBuilder setSpanContext (Integer left, String leftType,
Integer right, String rightType) {
this.spanContext = new SpanContext(left, leftType, right, rightType);
return this;
}
- public SpanContext getSpanContext() {
+
+ public SpanContext getSpanContext () {
return this.spanContext;
}
+
/**
* context if of type paragraph or sentence where left and right
* size delimiters are irrelevant; or 2-token, 2-char p/paragraph,
* s/sentence or token, char.
* Distinguish
- *
+ *
* @param context
* @return
*/
- public MetaQueryBuilder setSpanContext(String context) {
+ public MetaQueryBuilder setSpanContext (String context) {
if (context != null) {
if (!p.matcher(context).find())
this.spanContext = new SpanContext(context);
@@ -66,13 +70,15 @@
return this;
}
- public MetaQueryBuilder addEntry(String name, Object value) {
+
+ public MetaQueryBuilder addEntry (String name, Object value) {
if (value != null)
meta.put(name, value);
return this;
}
- public Map raw() {
+
+ public Map raw () {
if (this.spanContext != null)
meta.putAll(this.spanContext.raw());
return meta;
@@ -85,24 +91,26 @@
private int right_size;
private String context = null;
+
/**
* context segment if context is either of type char or token.
* size can differ for left and right span
- *
+ *
* @param ls
* @param lt
* @param rs
* @param rt
* @return
*/
- public SpanContext(int ls, String lt, int rs, String rt) {
+ public SpanContext (int ls, String lt, int rs, String rt) {
this.left_type = lt;
this.left_size = ls;
this.right_type = rt;
this.right_size = rs;
}
- public SpanContext(String context) {
+
+ public SpanContext (String context) {
this.context = context;
}
@@ -122,9 +130,6 @@
return this.right_size;
}
-
-
-
public Map raw() {
Map meta = new LinkedHashMap();
if (this.context == null) {
@@ -138,7 +143,8 @@
r.add(this.right_size);
map.put("right", r);
meta.put("context", map);
- }else
+ }
+ else
meta.put("context", this.context);
return meta;
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
index c89bf59..dcf0d3d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
@@ -14,7 +14,7 @@
/**
* Main class for Koral, serializes queries from concrete QLs to
* KoralQuery
- *
+ *
* @author Joachim Bingel (bingel@ids-mannheim.de),
* Michael Hanl (hanl@ids-mannheim.de)
* @version 0.3.0
@@ -28,11 +28,10 @@
-
static {
qlProcessorAssignment = new HashMap<String, Class<? extends AbstractQueryProcessor>>();
- qlProcessorAssignment
- .put("poliqarpplus", PoliqarpPlusQueryProcessor.class);
+ qlProcessorAssignment.put("poliqarpplus",
+ PoliqarpPlusQueryProcessor.class);
qlProcessorAssignment.put("cosmas2", Cosmas2QueryProcessor.class);
qlProcessorAssignment.put("annis", AnnisQueryProcessor.class);
qlProcessorAssignment.put("cql", CqlQueryProcessor.class);
@@ -51,16 +50,18 @@
private org.slf4j.Logger log = LoggerFactory
.getLogger(QuerySerializer.class);
- public QuerySerializer() {
+
+ public QuerySerializer () {
this.errors = new LinkedList<>();
this.warnings = new LinkedList<>();
this.messages = new LinkedList<>();
}
+
/**
* @param args
*/
- public static void main(String[] args) {
+ public static void main (String[] args) {
/*
* just for testing...
*/
@@ -73,7 +74,8 @@
System.err
.println("Usage: QuerySerializer \"query\" queryLanguage");
System.exit(1);
- }else {
+ }
+ else {
queries = new String[] { args[0] };
ql = args[1];
}
@@ -82,95 +84,119 @@
try {
jg.run(q, ql);
System.out.println();
- }catch (NullPointerException npe) {
+ }
+ catch (NullPointerException npe) {
npe.printStackTrace();
System.out.println("null\n");
- }catch (IOException e) {
+ }
+ catch (IOException e) {
e.printStackTrace();
}
}
}
+
/**
* Runs the QuerySerializer by initializing the relevant
* AbstractSyntaxTree implementation (depending on specified query
* language) and transforms and writes the tree's requestMap to
* the specified output file.
- *
- * @param query The query string
- * @param queryLanguage The query language. As of 17 Dec 2014, this must be
- * one of 'poliqarpplus', 'cosmas2', 'annis' or 'cql'.
+ *
+ * @param query
+ * The query string
+ * @param queryLanguage
+ * The query language. As of 17 Dec 2014, this must be
+ * one of 'poliqarpplus', 'cosmas2', 'annis' or 'cql'.
* @throws IOException
*/
- public void run(String query, String queryLanguage) throws IOException {
+ public void run (String query, String queryLanguage) throws IOException {
if (queryLanguage.equalsIgnoreCase("poliqarp")) {
ast = new PoliqarpPlusQueryProcessor(query);
- }else if (queryLanguage.equalsIgnoreCase("cosmas2")) {
+ }
+ else if (queryLanguage.equalsIgnoreCase("cosmas2")) {
ast = new Cosmas2QueryProcessor(query);
- }else if (queryLanguage.equalsIgnoreCase("poliqarpplus")) {
+ }
+ else if (queryLanguage.equalsIgnoreCase("poliqarpplus")) {
ast = new PoliqarpPlusQueryProcessor(query);
- }else if (queryLanguage.equalsIgnoreCase("cql")) {
+ }
+ else if (queryLanguage.equalsIgnoreCase("cql")) {
ast = new CqlQueryProcessor(query);
- }else if (queryLanguage.equalsIgnoreCase("annis")) {
+ }
+ else if (queryLanguage.equalsIgnoreCase("annis")) {
ast = new AnnisQueryProcessor(query);
- }else {
- throw new IllegalArgumentException(
- queryLanguage + " is not a supported query language!");
+ }
+ else {
+ throw new IllegalArgumentException(queryLanguage
+ + " is not a supported query language!");
}
toJSON();
}
- public QuerySerializer setQuery(String query, String ql, String version) {
+
+ public QuerySerializer setQuery (String query, String ql, String version) {
ast = new DummyQueryProcessor();
if (query == null || query.isEmpty()) {
ast.addError(StatusCodes.NO_QUERY, "You did not specify a query!");
- }else if (ql == null || ql.isEmpty()) {
+ }
+ else if (ql == null || ql.isEmpty()) {
ast.addError(StatusCodes.NO_QUERY,
"You did not specify any query language!");
- }else if (ql.equalsIgnoreCase("poliqarp")) {
+ }
+ else if (ql.equalsIgnoreCase("poliqarp")) {
ast = new PoliqarpPlusQueryProcessor(query);
- }else if (ql.equalsIgnoreCase("cosmas2")) {
+ }
+ else if (ql.equalsIgnoreCase("cosmas2")) {
ast = new Cosmas2QueryProcessor(query);
- }else if (ql.equalsIgnoreCase("poliqarpplus")) {
+ }
+ else if (ql.equalsIgnoreCase("poliqarpplus")) {
ast = new PoliqarpPlusQueryProcessor(query);
- }else if (ql.equalsIgnoreCase("cql")) {
+ }
+ else if (ql.equalsIgnoreCase("cql")) {
if (version == null)
ast = new CqlQueryProcessor(query);
else
ast = new CqlQueryProcessor(query, version);
- }else if (ql.equalsIgnoreCase("annis")) {
+ }
+ else if (ql.equalsIgnoreCase("annis")) {
ast = new AnnisQueryProcessor(query);
- }else {
- ast.addError(StatusCodes.UNKNOWN_QL,
- ql + " is not a supported query language!");
+ }
+ else {
+ ast.addError(StatusCodes.UNKNOWN_QL, ql
+ + " is not a supported query language!");
}
return this;
}
- public QuerySerializer setQuery(String query, String ql) {
+
+ public QuerySerializer setQuery (String query, String ql) {
return setQuery(query, ql, "");
}
- public void setVerbose(boolean verbose) {
+
+ public void setVerbose (boolean verbose) {
AbstractQueryProcessor.verbose = verbose;
}
- public final String toJSON() {
+
+ public final String toJSON () {
String ser;
try {
ser = mapper.writeValueAsString(raw());
qllogger.info("Serialized query: " + ser);
- }catch (JsonProcessingException e) {
+ }
+ catch (JsonProcessingException e) {
return "";
}
return ser;
}
- public final Map build() {
+
+ public final Map build () {
return raw();
}
- private Map raw() {
+
+ private Map raw () {
if (ast != null) {
Map<String, Object> requestMap = new HashMap<>(ast.getRequestMap());
Map meta = (Map) requestMap.get("meta");
@@ -211,33 +237,38 @@
return new HashMap<>();
}
- private Map<String, Object> cleanup(Map<String, Object> requestMap) {
+
+ private Map<String, Object> cleanup (Map<String, Object> requestMap) {
Iterator<Map.Entry<String, Object>> set = requestMap.entrySet()
.iterator();
while (set.hasNext()) {
Map.Entry<String, Object> entry = set.next();
- if (entry.getValue() instanceof List && ((List) entry.getValue())
- .isEmpty())
+ if (entry.getValue() instanceof List
+ && ((List) entry.getValue()).isEmpty())
set.remove();
- else if (entry.getValue() instanceof Map && ((Map) entry.getValue())
- .isEmpty())
+ else if (entry.getValue() instanceof Map
+ && ((Map) entry.getValue()).isEmpty())
set.remove();
- else if (entry.getValue() instanceof String && ((String) entry
- .getValue()).isEmpty())
+ else if (entry.getValue() instanceof String
+ && ((String) entry.getValue()).isEmpty())
set.remove();
}
return requestMap;
}
- private Map<String, Object> mergeCollection(Map<String, Object> collection1,
- Map<String, Object> collection2) {
+
+ private Map<String, Object> mergeCollection (
+ Map<String, Object> collection1, Map<String, Object> collection2) {
if (collection1 == null || collection1.isEmpty()) {
return collection2;
- }else if (collection2 == null || collection2.isEmpty()) {
+ }
+ else if (collection2 == null || collection2.isEmpty()) {
return collection1;
- }else if (collection1.equals(collection2)) {
+ }
+ else if (collection1.equals(collection2)) {
return collection1;
- }else {
+ }
+ else {
LinkedHashMap<String, Object> docGroup = KoralObjectGenerator
.makeDocGroup("and");
ArrayList<Object> operands = (ArrayList<Object>) docGroup
@@ -248,8 +279,9 @@
}
}
+
@Deprecated
- public QuerySerializer addMeta(String cli, String cri, int cls, int crs,
+ public QuerySerializer addMeta (String cli, String cri, int cls, int crs,
int num, int pageIndex) {
MetaQueryBuilder meta = new MetaQueryBuilder();
meta.setSpanContext(cls, cli, crs, cri);
@@ -259,12 +291,14 @@
return this;
}
- public QuerySerializer setMeta(Map<String, Object> meta) {
+
+ public QuerySerializer setMeta (Map<String, Object> meta) {
this.meta = meta;
return this;
}
- public QuerySerializer setCollection(String collection) {
+
+ public QuerySerializer setCollection (String collection) {
CollectionQueryProcessor tree = new CollectionQueryProcessor();
tree.process(collection);
Map<String, Object> collectionRequest = tree.getRequestMap();
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
index 6980b2e..47b5e09 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
@@ -14,7 +14,7 @@
*/
public class QueryUtils {
- public static SimpleEntry<String, Integer> checkUnbalancedPars(String q) {
+ public static SimpleEntry<String, Integer> checkUnbalancedPars (String q) {
Map<Character, Character> brackets = new HashMap<Character, Character>();
brackets.put('[', ']');
brackets.put('{', '}');
@@ -31,8 +31,9 @@
if (brackets.containsKey(q.charAt(i))) {
stack.push(q.charAt(i));
lastOpenBracket = i;
- }else if (stack.empty() || (q.charAt(i) != brackets
- .get(stack.pop()))) {
+ }
+ else if (stack.empty()
+ || (q.charAt(i) != brackets.get(stack.pop()))) {
return new SimpleEntry<String, Integer>(
"Parantheses/brackets unbalanced.", i);
}
@@ -43,13 +44,15 @@
return null;
}
- public static List<String> parseMorph(String stringTree) {
+
+ public static List<String> parseMorph (String stringTree) {
ArrayList<String> morph = new ArrayList<String>();
return morph;
}
- public static String buildCypherQuery(String cypher, String ctypel,
+
+ public static String buildCypherQuery (String cypher, String ctypel,
String ctyper, int cl, int cr, int page, int limit) {
// todo: implies that there is only one type allowed!
String sctypel = "", sctyper = "";
@@ -100,7 +103,8 @@
return buffer.toString();
}
- public static String buildDotQuery(long sid, String graphdb_id) {
+
+ public static String buildDotQuery (long sid, String graphdb_id) {
StringBuffer b = new StringBuffer();
b.append("<query>");
b.append("<sentenceId>");
@@ -122,7 +126,8 @@
return b.toString();
}
- public String buildaggreQuery(String query) {
+
+ public String buildaggreQuery (String query) {
StringBuffer b = new StringBuffer();
b.append("<query><cypher><![CDATA[");
b.append(query);
@@ -151,9 +156,10 @@
return b.toString();
}
+
@Deprecated
- public static Map addParameters(Map request, int page, int num, String cli,
- String cri, int cls, int crs, boolean cutoff) {
+ public static Map addParameters (Map request, int page, int num,
+ String cli, String cri, int cls, int crs, boolean cutoff) {
Map ctx = new LinkedHashMap();
List left = new ArrayList();
left.add(cli);
@@ -172,14 +178,15 @@
return request;
}
+
/**
* Checks if value is a date
- *
+ *
* @param value
* @return
*/
- public static boolean checkDateValidity(String value) {
+ public static boolean checkDateValidity (String value) {
Pattern p = Pattern.compile("^[0-9]{4}(-([0-9]{2})(-([0-9]{2}))?)?$");
Matcher m = p.matcher(value);
@@ -190,7 +197,8 @@
if (month != null) {
if (Integer.parseInt(month) > 12) {
return false;
- }else if (day != null) {
+ }
+ else if (day != null) {
if (Integer.parseInt(day) > 31) {
return false;
}
@@ -199,7 +207,8 @@
return true;
}
- public static String escapeRegexSpecialChars(String key) {
+
+ public static String escapeRegexSpecialChars (String key) {
key.replace("\\", "\\\\");
Pattern p = Pattern
.compile("\\.|\\^|\\$|\\||\\?|\\*|\\+|\\(|\\)|\\[|\\]|\\{|\\}");
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryDuplicateTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryDuplicateTest.java
index ed8e40f..f7c4dd1 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryDuplicateTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryDuplicateTest.java
@@ -17,16 +17,20 @@
public class CollectionQueryDuplicateTest {
@Test
- public void testCollectionQueryDuplicateThrowsAssertionException() throws IOException {
+ public void testCollectionQueryDuplicateThrowsAssertionException ()
+ throws IOException {
QuerySerializer serializer = new QuerySerializer();
serializer.setQuery("[base=Haus]", "poliqarp");
serializer.setCollection("textClass=politik & corpusID=WPD");
ObjectMapper m = new ObjectMapper();
JsonNode first = m.readTree(serializer.toJSON());
assertNotNull(first);
- assertEquals(first.at("/collection"), m.readTree(serializer.toJSON()).at("/collection"));
- assertEquals(first.at("/collection"), m.readTree(serializer.toJSON()).at("/collection"));
- assertEquals(first.at("/collection"), m.readTree(serializer.toJSON()).at("/collection"));
+ assertEquals(first.at("/collection"), m.readTree(serializer.toJSON())
+ .at("/collection"));
+ assertEquals(first.at("/collection"), m.readTree(serializer.toJSON())
+ .at("/collection"));
+ assertEquals(first.at("/collection"), m.readTree(serializer.toJSON())
+ .at("/collection"));
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessorTest.java
index 1a24352..0e91058 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessorTest.java
@@ -22,8 +22,9 @@
ObjectMapper mapper = new ObjectMapper();
JsonNode res;
+
@Test
- public void testContext() throws JsonProcessingException, IOException {
+ public void testContext () throws JsonProcessingException, IOException {
collection = "textClass=politik";
String contextString = "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld";
qs.setQuery(query, ql);
@@ -32,8 +33,9 @@
assertEquals(contextString, res.get("@context").asText());
}
+
@Test
- public void testSimple() throws JsonProcessingException, IOException {
+ public void testSimple () throws JsonProcessingException, IOException {
collection = "textClass=politik";
qs.setQuery(query, ql);
qs.setCollection(collection);
@@ -53,9 +55,10 @@
assertEquals("match:ne", res.at("/collection/match").asText());
}
+
@Test
- public void testSpecialCharacters()
- throws JsonProcessingException, IOException {
+ public void testSpecialCharacters () throws JsonProcessingException,
+ IOException {
collection = "[base/n=alt]";
qs.setQuery(query, ql);
qs.setCollection(collection);
@@ -71,8 +74,9 @@
;
+
@Test
- public void testContains() throws JsonProcessingException, IOException {
+ public void testContains () throws JsonProcessingException, IOException {
collection = "title~Mannheim";
qs.setQuery(query, ql);
qs.setCollection(collection);
@@ -101,8 +105,9 @@
assertEquals("match:contains", res.at("/collection/match").asText());
}
+
@Test
- public void testNotDate() throws JsonProcessingException, IOException {
+ public void testNotDate () throws JsonProcessingException, IOException {
collection = "author=\"firefighter1974\"";
qs.setQuery(query, ql);
qs.setCollection(collection);
@@ -115,29 +120,29 @@
assertEquals("", res.at("/warnings/0/0").asText());
}
+
@Test
- public void testTwoConjuncts() throws JsonProcessingException, IOException {
+ public void testTwoConjuncts () throws JsonProcessingException, IOException {
collection = "textClass=Sport & pubDate in 2014";
qs.setQuery(query, ql);
qs.setCollection(collection);
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass",
- res.at("/collection/operands/0/key").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq",
- res.at("/collection/operands/0/match").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/1/@type").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+ .asText());
assertEquals("pubDate", res.at("/collection/operands/1/key").asText());
assertEquals("2014", res.at("/collection/operands/1/value").asText());
- assertEquals("type:date",
- res.at("/collection/operands/1/type").asText());
- assertEquals("match:eq",
- res.at("/collection/operands/1/match").asText());
+ assertEquals("type:date", res.at("/collection/operands/1/type")
+ .asText());
+ assertEquals("match:eq", res.at("/collection/operands/1/match")
+ .asText());
collection = "textClass=Sport & pubDate=2014";
qs.setQuery(query, ql);
@@ -146,166 +151,165 @@
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass",
- res.at("/collection/operands/0/key").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq",
- res.at("/collection/operands/0/match").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/1/@type").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+ .asText());
assertEquals("pubDate", res.at("/collection/operands/1/key").asText());
assertEquals("2014", res.at("/collection/operands/1/value").asText());
- assertEquals(true,
- res.at("/collection/operands/1/type").isMissingNode());
- assertEquals("match:eq",
- res.at("/collection/operands/1/match").asText());
+ assertEquals(true, res.at("/collection/operands/1/type")
+ .isMissingNode());
+ assertEquals("match:eq", res.at("/collection/operands/1/match")
+ .asText());
assertTrue(res.at("/warnings/0").isMissingNode());
// assertTrue(res.at("/warnings/0/0").asText().startsWith(
// "The collection query contains a value that looks like a date"));
}
+
@Test
- public void testThreeConjuncts()
- throws JsonProcessingException, IOException {
+ public void testThreeConjuncts () throws JsonProcessingException,
+ IOException {
collection = "textClass=Sport & pubDate in 2014 & corpusId=WPD";
qs.setQuery(query, ql);
qs.setCollection(collection);
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass",
- res.at("/collection/operands/0/key").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq",
- res.at("/collection/operands/0/match").asText());
- assertEquals("koral:docGroup",
- res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:and",
- res.at("/collection/operands/1/operation").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/1/operation").asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("pubDate",
- res.at("/collection/operands/1/operands/0/key").asText());
- assertEquals("2014",
- res.at("/collection/operands/1/operands/0/value").asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key")
+ .asText());
+ assertEquals("2014", res.at("/collection/operands/1/operands/0/value")
+ .asText());
assertEquals("type:date",
res.at("/collection/operands/1/operands/0/type").asText());
assertEquals("match:eq",
res.at("/collection/operands/1/operands/0/match").asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("corpusId",
- res.at("/collection/operands/1/operands/1/key").asText());
- assertEquals("WPD",
- res.at("/collection/operands/1/operands/1/value").asText());
+ assertEquals("corpusId", res
+ .at("/collection/operands/1/operands/1/key").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/1/value")
+ .asText());
assertEquals("match:eq",
res.at("/collection/operands/1/operands/1/match").asText());
}
+
@Test
- public void testTwoDisjuncts() throws JsonProcessingException, IOException {
+ public void testTwoDisjuncts () throws JsonProcessingException, IOException {
collection = "textClass=Sport | pubDate in 2014";
qs.setQuery(query, ql);
qs.setCollection(collection);
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass",
- res.at("/collection/operands/0/key").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq",
- res.at("/collection/operands/0/match").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/1/@type").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+ .asText());
assertEquals("pubDate", res.at("/collection/operands/1/key").asText());
assertEquals("2014", res.at("/collection/operands/1/value").asText());
- assertEquals("type:date",
- res.at("/collection/operands/1/type").asText());
- assertEquals("match:eq",
- res.at("/collection/operands/1/match").asText());
+ assertEquals("type:date", res.at("/collection/operands/1/type")
+ .asText());
+ assertEquals("match:eq", res.at("/collection/operands/1/match")
+ .asText());
}
+
@Test
- public void testThreeDisjuncts()
- throws JsonProcessingException, IOException {
+ public void testThreeDisjuncts () throws JsonProcessingException,
+ IOException {
collection = "textClass=Sport | pubDate in 2014 | corpusId=WPD";
qs.setQuery(query, ql);
qs.setCollection(collection);
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass",
- res.at("/collection/operands/0/key").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq",
- res.at("/collection/operands/0/match").asText());
- assertEquals("koral:docGroup",
- res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:or",
- res.at("/collection/operands/1/operation").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:or", res.at("/collection/operands/1/operation")
+ .asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("pubDate",
- res.at("/collection/operands/1/operands/0/key").asText());
- assertEquals("2014",
- res.at("/collection/operands/1/operands/0/value").asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key")
+ .asText());
+ assertEquals("2014", res.at("/collection/operands/1/operands/0/value")
+ .asText());
assertEquals("type:date",
res.at("/collection/operands/1/operands/0/type").asText());
assertEquals("match:eq",
res.at("/collection/operands/1/operands/0/match").asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("corpusId",
- res.at("/collection/operands/1/operands/1/key").asText());
- assertEquals("WPD",
- res.at("/collection/operands/1/operands/1/value").asText());
+ assertEquals("corpusId", res
+ .at("/collection/operands/1/operands/1/key").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/1/value")
+ .asText());
assertEquals("match:eq",
res.at("/collection/operands/1/operands/1/match").asText());
}
+
@Test
- public void testMixed() throws JsonProcessingException, IOException {
+ public void testMixed () throws JsonProcessingException, IOException {
collection = "textClass=Sport | (pubDate in 2014 & corpusId=WPD)";
qs.setQuery(query, ql);
qs.setCollection(collection);
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass",
- res.at("/collection/operands/0/key").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq",
- res.at("/collection/operands/0/match").asText());
- assertEquals("koral:docGroup",
- res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:and",
- res.at("/collection/operands/1/operation").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/1/operation").asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("pubDate",
- res.at("/collection/operands/1/operands/0/key").asText());
- assertEquals("2014",
- res.at("/collection/operands/1/operands/0/value").asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key")
+ .asText());
+ assertEquals("2014", res.at("/collection/operands/1/operands/0/value")
+ .asText());
assertEquals("type:date",
res.at("/collection/operands/1/operands/0/type").asText());
assertEquals("match:eq",
res.at("/collection/operands/1/operands/0/match").asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("corpusId",
- res.at("/collection/operands/1/operands/1/key").asText());
- assertEquals("WPD",
- res.at("/collection/operands/1/operands/1/value").asText());
+ assertEquals("corpusId", res
+ .at("/collection/operands/1/operands/1/key").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/1/value")
+ .asText());
assertEquals("match:eq",
res.at("/collection/operands/1/operands/1/match").asText());
@@ -315,33 +319,32 @@
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass",
- res.at("/collection/operands/0/key").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq",
- res.at("/collection/operands/0/match").asText());
- assertEquals("koral:docGroup",
- res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:and",
- res.at("/collection/operands/1/operation").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/1/operation").asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("pubDate",
- res.at("/collection/operands/1/operands/0/key").asText());
- assertEquals("2014",
- res.at("/collection/operands/1/operands/0/value").asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key")
+ .asText());
+ assertEquals("2014", res.at("/collection/operands/1/operands/0/value")
+ .asText());
assertEquals("type:date",
res.at("/collection/operands/1/operands/0/type").asText());
assertEquals("match:eq",
res.at("/collection/operands/1/operands/0/match").asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("corpusId",
- res.at("/collection/operands/1/operands/1/key").asText());
- assertEquals("WPD",
- res.at("/collection/operands/1/operands/1/value").asText());
+ assertEquals("corpusId", res
+ .at("/collection/operands/1/operands/1/key").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/1/value")
+ .asText());
assertEquals("match:eq",
res.at("/collection/operands/1/operands/1/match").asText());
@@ -351,16 +354,16 @@
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("koral:docGroup",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("operation:or",
- res.at("/collection/operands/0/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("operation:or", res.at("/collection/operands/0/operation")
+ .asText());
assertEquals("koral:doc",
res.at("/collection/operands/0/operands/0/@type").asText());
assertEquals("koral:doc",
res.at("/collection/operands/0/operands/1/@type").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/1/@type").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+ .asText());
collection = "(textClass=Sport & pubDate in 2014) & corpusId=WPD";
qs.setQuery(query, ql);
@@ -368,16 +371,16 @@
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("koral:docGroup",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("operation:and",
- res.at("/collection/operands/0/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/0/operation").asText());
assertEquals("koral:doc",
res.at("/collection/operands/0/operands/0/@type").asText());
assertEquals("koral:doc",
res.at("/collection/operands/0/operands/1/@type").asText());
- assertEquals("koral:doc",
- res.at("/collection/operands/1/@type").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+ .asText());
collection = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White)";
qs.setQuery(query, ql);
@@ -385,30 +388,30 @@
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:docGroup",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("operation:and",
- res.at("/collection/operands/0/operation").asText());
- assertEquals("koral:docGroup",
- res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:and",
- res.at("/collection/operands/1/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/0/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/1/operation").asText());
assertEquals("koral:doc",
res.at("/collection/operands/0/operands/0/@type").asText());
- assertEquals("Sport",
- res.at("/collection/operands/0/operands/0/value").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/operands/0/value")
+ .asText());
assertEquals("koral:doc",
res.at("/collection/operands/0/operands/1/@type").asText());
assertEquals("ausland",
res.at("/collection/operands/0/operands/1/value").asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("WPD",
- res.at("/collection/operands/1/operands/0/value").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/0/value")
+ .asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("White",
- res.at("/collection/operands/1/operands/1/value").asText());
+ assertEquals("White", res.at("/collection/operands/1/operands/1/value")
+ .asText());
collection = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White & pubDate in 2000)";
qs.setQuery(query, ql);
@@ -416,26 +419,26 @@
res = mapper.readTree(qs.toJSON());
assertEquals("koral:docGroup", res.at("/collection/@type").asText());
assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:docGroup",
- res.at("/collection/operands/0/@type").asText());
- assertEquals("operation:and",
- res.at("/collection/operands/0/operation").asText());
- assertEquals("koral:docGroup",
- res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:and",
- res.at("/collection/operands/1/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/0/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/1/operation").asText());
assertEquals("koral:doc",
res.at("/collection/operands/0/operands/0/@type").asText());
- assertEquals("Sport",
- res.at("/collection/operands/0/operands/0/value").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/operands/0/value")
+ .asText());
assertEquals("koral:doc",
res.at("/collection/operands/0/operands/1/@type").asText());
assertEquals("ausland",
res.at("/collection/operands/0/operands/1/value").asText());
assertEquals("koral:doc",
res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("WPD",
- res.at("/collection/operands/1/operands/0/value").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/0/value")
+ .asText());
assertEquals("koral:docGroup",
res.at("/collection/operands/1/operands/1/@type").asText());
assertEquals("operation:and",
@@ -448,8 +451,9 @@
.asText());
}
+
@Test
- public void testDateYear() throws JsonProcessingException, IOException {
+ public void testDateYear () throws JsonProcessingException, IOException {
collection = "pubDate in 2000";
qs.setQuery(query, ql);
qs.setCollection(collection);
@@ -491,8 +495,9 @@
assertEquals("match:leq", res.at("/collection/match").asText());
}
+
@Test
- public void testDateMonthDay() throws JsonProcessingException, IOException {
+ public void testDateMonthDay () throws JsonProcessingException, IOException {
collection = "pubDate in 2000-02";
qs.setQuery(query, ql);
qs.setCollection(collection);
@@ -534,8 +539,9 @@
assertEquals("match:leq", res.at("/collection/match").asText());
}
+
@Test
- public void testDateValidate() {
+ public void testDateValidate () {
String fake_date = "fireStorm2014";
String fake_date_2 = "2014-12Date";
String date = "2015";
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
index 802ba9e..9db30b9 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
@@ -305,11 +305,17 @@
@Test
public void testOPORAND () throws JsonProcessingException, IOException {
+
+ // Query
query = "(Sonne oder Mond) und scheint";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
assertEquals("koral:group", res.at("/query/@type").asText());
assertEquals("operation:sequence", res.at("/query/operation").asText());
+
+ assertEquals(false, res.at("/query/inOrder").isMissingNode());
+ assertEquals(false, res.at("/query/inOrder").asBoolean());
+
assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
.asText());
assertEquals("t", res.at("/query/distances/0/key").asText());
@@ -318,6 +324,10 @@
assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
assertEquals("operation:disjunction",
res.at("/query/operands/0/operation").asText());
+
+ assertEquals(false, res.at("/query/operands/0/inOrder").isMissingNode());
+ assertEquals(false, res.at("/query/operands/0/inOrder").asBoolean());
+
assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
.asText());
assertEquals("Mond", res.at("/query/operands/0/operands/1/wrap/key")
@@ -325,10 +335,15 @@
assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
assertEquals("scheint", res.at("/query/operands/1/wrap/key").asText());
+ // Query
query = "scheint und (Sonne oder Mond)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
assertEquals("koral:group", res.at("/query/@type").asText());
+
+ assertEquals(false, res.at("/query/inOrder").isMissingNode());
+ assertEquals(false, res.at("/query/inOrder").asBoolean());
+
assertEquals("operation:sequence", res.at("/query/operation").asText());
assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
.asText());
@@ -340,16 +355,25 @@
assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
assertEquals("operation:disjunction",
res.at("/query/operands/1/operation").asText());
+
+ assertEquals(false, res.at("/query/operands/1/inOrder").isMissingNode());
+ assertEquals(false, res.at("/query/operands/1/inOrder").asBoolean());
+
assertEquals("Sonne", res.at("/query/operands/1/operands/0/wrap/key")
.asText());
assertEquals("Mond", res.at("/query/operands/1/operands/1/wrap/key")
.asText());
+ // Query
query = "Regen und scheint und (Sonne oder Mond)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
assertEquals("koral:group", res.at("/query/@type").asText());
assertEquals("operation:sequence", res.at("/query/operation").asText());
+
+ assertEquals(false, res.at("/query/inOrder").isMissingNode());
+ assertEquals(false, res.at("/query/inOrder").asBoolean());
+
assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
.asText());
assertEquals("t", res.at("/query/distances/0/key").asText());
@@ -357,8 +381,14 @@
assertEquals(0, res.at("/query/distances/0/max").asInt());
assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
assertEquals("Regen", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
+
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/1/operation").asText());
+
+ assertEquals(false, res.at("/query/operands/1/inOrder").isMissingNode());
+ assertEquals(false, res.at("/query/operands/1/inOrder").asBoolean());
+
assertEquals("cosmas:distance",
res.at("/query/operands/1/distances/0/@type").asText());
assertEquals("t", res.at("/query/operands/1/distances/0/key").asText());
@@ -368,6 +398,12 @@
.asText());
assertEquals("koral:group", res
.at("/query/operands/1/operands/1/@type").asText());
+
+ assertEquals(false, res.at("/query/operands/1/operands/1/inOrder")
+ .isMissingNode());
+ assertEquals(false, res.at("/query/operands/1/operands/1/inOrder")
+ .asBoolean());
+
assertEquals("operation:disjunction",
res.at("/query/operands/1/operands/1/operation").asText());
assertEquals("Sonne",
@@ -728,8 +764,9 @@
assertEquals("koral:span",
res.at("/query/operands/0/operands/0/operands/0/@type")
.asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/wrap/key")
- .asText());
+ assertEquals("s",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
assertEquals("koral:group", res
.at("/query/operands/0/operands/1/@type").asText());
assertEquals("operation:class",
@@ -1401,7 +1438,8 @@
.asText());
assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
.asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key").asText());
+ assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
query = "#BED(der Mann , +pe)";
qs.setQuery(query, "cosmas2");
@@ -1425,8 +1463,9 @@
assertEquals("koral:span",
res.at("/query/operands/0/operands/0/operands/0/@type")
.asText());
- assertEquals("p", res.at("/query/operands/0/operands/0/operands/0/wrap/key")
- .asText());
+ assertEquals("p",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
assertEquals("koral:reference",
res.at("/query/operands/0/operands/1/@type").asText());
assertEquals("operation:focus",
@@ -1478,8 +1517,9 @@
assertEquals("koral:span",
res.at("/query/operands/0/operands/0/operands/0/@type")
.asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/wrap/key")
- .asText());
+ assertEquals("s",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
assertEquals("koral:group",
res.at("/query/operands/0/operands/0/operands/1/@type")
.asText());
@@ -1513,8 +1553,9 @@
assertEquals("koral:span",
res.at("/query/operands/0/operands/1/operands/0/@type")
.asText());
- assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/wrap/key")
- .asText());
+ assertEquals("p",
+ res.at("/query/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
assertEquals("koral:group",
res.at("/query/operands/0/operands/1/operands/1/@type")
.asText());
@@ -1567,7 +1608,8 @@
.asText());
assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
.asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key").asText());
+ assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
query = "der:sa,-pa";
qs.setQuery(query, "cosmas2");
@@ -1589,8 +1631,9 @@
assertEquals("koral:span",
res.at("/query/operands/0/operands/0/operands/0/@type")
.asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/wrap/key")
- .asText());
+ assertEquals("s",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
assertEquals("koral:group",
res.at("/query/operands/0/operands/0/operands/1/@type")
.asText());
@@ -1615,8 +1658,9 @@
assertEquals("koral:span",
res.at("/query/operands/0/operands/1/operands/0/@type")
.asText());
- assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/wrap/key")
- .asText());
+ assertEquals("p",
+ res.at("/query/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
assertEquals("koral:group",
res.at("/query/operands/0/operands/1/operands/1/@type")
.asText());
@@ -1651,8 +1695,9 @@
assertEquals("koral:span",
res.at("/query/operands/0/operands/0/operands/0/@type")
.asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/wrap/key")
- .asText());
+ assertEquals("s",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
assertEquals("koral:group",
res.at("/query/operands/0/operands/0/operands/1/@type")
.asText());
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/EmptyResultsTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/EmptyResultsTest.java
index 58d775b..264ca67 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/EmptyResultsTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/EmptyResultsTest.java
@@ -15,8 +15,9 @@
private static ObjectMapper mapper = new ObjectMapper();
+
@Test
- public void testEmptyQueryObject() {
+ public void testEmptyQueryObject () {
QuerySerializer s = new QuerySerializer();
s.setQuery("prox/unit=word/distance<=5", "cql");
JsonNode node = mapper.valueToTree(s.build());
@@ -24,8 +25,9 @@
assertEquals(node.has("collection"), false);
}
+
@Test
- public void testEmptyCollectionObject() {
+ public void testEmptyCollectionObject () {
QuerySerializer s = new QuerySerializer();
s.setQuery("[base=Wort]", "poliqarp");
@@ -34,8 +36,9 @@
assertEquals(node.has("collection"), false);
}
+
@Test
- public void testEmptyMetaObject() {
+ public void testEmptyMetaObject () {
QuerySerializer s = new QuerySerializer();
s.setQuery("[base=Wort]", "poliqarp");
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
index 7e3c9f3..221c0bc 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
@@ -148,7 +148,7 @@
query = "z.B./x";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- System.out.println("QUERY IS "+ res);
+ System.out.println("QUERY IS " + res);
assertEquals("koral:token", res.at("/query/@type").asText());
assertEquals("koral:term", res.at("/query/wrap/@type").asText());
assertEquals(".*?z\\.B\\..*?", res.at("/query/wrap/key").asText());
@@ -160,7 +160,7 @@
query = "\"a\\.\"";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- System.out.println("QUERY IS "+ res);
+ System.out.println("QUERY IS " + res);
assertEquals("koral:token", res.at("/query/@type").asText());
assertEquals("koral:term", res.at("/query/wrap/@type").asText());
assertEquals("type:regex", res.at("/query/wrap/type").asText());
@@ -1703,8 +1703,10 @@
assertEquals("VVFIN", res.at("/query/operands/1/wrap/key").asText());
}
+
@Test
- public void testSpanSerialization () throws JsonProcessingException, IOException {
+ public void testSpanSerialization () throws JsonProcessingException,
+ IOException {
// Both constructs should be serialized identically
query = "contains(<s>, der)";