AQL Tree update
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
index c0cebaa..8979e1c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
@@ -52,32 +52,22 @@
* Keeps track of all visited nodes in a tree
*/
List<ParseTree> visited = new ArrayList<ParseTree>();
-
/**
- * Keeps track of active fields (like 'base=foo').
+ * Keeps track of active object.
*/
- LinkedList<ArrayList<Object>> fieldStack = new LinkedList<ArrayList<Object>>();
- /**
- * Keeps track of active sequences.
- */
- LinkedList<LinkedHashMap<String,Object>> sequenceStack = new LinkedList<LinkedHashMap<String,Object>>();
- /**
- * Keeps track of active tokens.
- */
- LinkedList<LinkedHashMap<String,Object>> tokenStack = new LinkedList<LinkedHashMap<String,Object>>();
- /**
- * Keeps track of sequence/token/field groups.
- */
- LinkedList<ArrayList<Object>> groupStack = new LinkedList<ArrayList<Object>>();
- /**
- * Marks the currently active object (sequence/token/group...) in order to know where to add stuff like occurrence info etc.
- */
- LinkedHashMap<String,Object> curObject = new LinkedHashMap<String,Object>();
+ LinkedList<LinkedHashMap<String,Object>> objectStack = new LinkedList<LinkedHashMap<String,Object>>();
/**
* Marks the currently active token in order to know where to add flags (might already have been taken away from token stack).
*/
LinkedHashMap<String,Object> curToken = new LinkedHashMap<String,Object>();
+
+ private LinkedList<ArrayList<ArrayList<Object>>> distributedOperandsLists = new LinkedList<ArrayList<ArrayList<Object>>>();
+ /**
+ * Keeps track of how many objects there are to pop after every recursion of {@link #processNode(ParseTree)}
+ */
+ LinkedList<Integer> objectsToPop = new LinkedList<Integer>();
+ Integer stackedObjects = 0;
public static boolean verbose = false;
/**
@@ -135,7 +125,6 @@
processNode(tree);
}
- @SuppressWarnings("unchecked")
private void processNode(ParseTree node) {
// Top-down processing
if (visited.contains(node)) return;
@@ -144,7 +133,12 @@
String nodeCat = getNodeCat(node);
openNodeCats.push(nodeCat);
- if (verbose) System.out.println(openNodeCats);
+ stackedObjects = 0;
+
+ if (verbose) {
+ System.err.println(" "+objectStack);
+ System.out.println(openNodeCats);
+ }
/*
****************************************************************
@@ -153,10 +147,12 @@
****************************************************************
****************************************************************
*/
- if (nodeCat.equals("query")) {
+ if (nodeCat.equals("start")) {
}
+ objectsToPop.push(stackedObjects);
+
/*
****************************************************************
****************************************************************
@@ -169,26 +165,19 @@
processNode(child);
}
- // Stuff that happens when leaving a node (taking it off the stack)
- if (nodeCat.equals("cq_segments") || nodeCat.equals("sq_segments")) {
- // exclude whitespaces analysed as empty cq_segments
- if (node.getChildCount() > 0 && !getNodeCat(node.getChild(0)).equals(" ")) {
- sequenceStack.pop();
- }
+
+ /*
+ **************************************************************
+ * Stuff that happens after processing the children of a node *
+ **************************************************************
+ */
+
+
+ for (int i=0; i<objectsToPop.pop(); i++) {
+ objectStack.pop();
}
- if (nodeCat.equals("cq_disj_segments")) {
- groupStack.pop();
- }
-
- if (nodeCat.equals("cq_segment") || nodeCat.equals("sq_segment")){
- tokenStack.pop();
- }
-
- if (nodeCat.equals("conj_field")) {
- fieldStack.pop();
- }
-
+
openNodeCats.pop();
}
@@ -208,6 +197,27 @@
return nodeCat;
}
+ @SuppressWarnings("unused")
+ private void putIntoSuperObject(LinkedHashMap<String, Object> object) {
+ putIntoSuperObject(object, 0);
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ private void putIntoSuperObject(LinkedHashMap<String, Object> object, int objStackPosition) {
+ if (distributedOperandsLists.size()>0) {
+ ArrayList<ArrayList<Object>> distributedOperands = distributedOperandsLists.pop();
+ for (ArrayList<Object> operands : distributedOperands) {
+ operands.add(object);
+ }
+ } else if (objectStack.size()>objStackPosition) {
+ ArrayList<Object> topObjectOperands = (ArrayList<Object>) objectStack.get(objStackPosition).get("operands");
+ topObjectOperands.add(0, object);
+
+ } else {
+ requestMap.put("query", object);
+ }
+ }
+
private static ParserRuleContext parseAnnisQuery (String p) throws QueryException {
Lexer poliqarpLexer = new AqlLexer((CharStream)null);
ParserRuleContext tree = null;
@@ -247,7 +257,7 @@
* For testing
*/
String[] queries = new String[] {
- "node & node & #2 > #1",
+
"#1 . #2 ",
"#1 . #2 & meta::Genre=\"Sport\"",
"A _i_ B",
@@ -262,10 +272,7 @@
"#1 ->LABEL[lbl=/foo/] #2",
"#1 ->LABEL[foundry/layer=\"foo\"] #2",
"#1 ->LABEL[foundry/layer=\"foo\"] #2",
- "/[Ss]tatisch/",
- "/boo/",
- "//",
- "lalala"
+ "node & node & #2 > #1",
};
// AqlTree.verbose=true;
for (String q : queries) {