focus redefined as reference
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
index 5610d1c..0a9f5d8 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractSyntaxTree.java
@@ -95,13 +95,19 @@
return group;
}
- protected LinkedHashMap<String, Object> makeFocus(int classRef) {
+ protected LinkedHashMap<String, Object> makeReference(ArrayList<Integer> classRefs) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
- group.put("@type", "korap:focus");
- group.put("classRef", classRef);
+ group.put("@type", "korap:reference");
+ group.put("classRef", classRefs);
return group;
}
+ protected LinkedHashMap<String, Object> makeReference(int classRef) {
+ ArrayList<Integer> classRefs = new ArrayList<Integer>();
+ classRefs.add(classRef);
+ return makeReference(classRefs);
+ }
+
protected void addOperandsToGroup(LinkedHashMap<String, Object> group) {
ArrayList<Object> operands = new ArrayList<Object>();
group.put("operands", operands);
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 b002eaf..2512d90 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
@@ -8,6 +8,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.NoSuchElementException;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.BailErrorStrategy;
@@ -260,6 +261,7 @@
}
if (nodeCat.equals("n_ary_linguistic_term")) {
+ System.err.println(operandStack);
relationCounter++;
// get operator and determine type of group (sequence/treeRelation/relation/...)
// It's possible in Annis QL to concatenate operators, so there may be several operators under one n_ary_linguistic_term node.
@@ -287,45 +289,62 @@
ArrayList<Object> operands = (ArrayList<Object>) group.get("operands");
// Wrap in focus object in case other relations are following
if (i < node.getChildCount()-2) {
- group = wrapInFocus(group);
+ group = wrapInReference(group);
}
// Retrieve operands.
String ref1 = null;
String ref2 = null;
LinkedHashMap<String, Object> operand1 = null;
LinkedHashMap<String, Object> operand2 = null;
+ // Operand 1
if (!getNodeCat(operandTree1.getChild(0)).equals("variableExpr")) {
ref1 = operandTree1.getChild(0).toStringTree(parser).substring(1);
+ System.err.println("Operand 1: #"+ref1);
operand1 = variableReferences.get(ref1);
if (nodeReferencesTotal.get(ref1) > 1) {
if (nodeReferencesProcessed.get(ref1) == 0) {
operand1 = wrapInClass(operand1);
- group = wrapInFocus(group);
- classCounter++;
+// group = wrapInFocus(group);
+// classCounter++;
nodeReferencesProcessed.put(ref1, nodeReferencesProcessed.get(ref1)+1);
- } else if (nodeReferencesProcessed.get(ref1)>0) {
- operand1 = null;
+ } else if (nodeReferencesProcessed.get(ref1)>0 && nodeReferencesTotal.get(ref1)>1) {
+ try {
+ operand1 = wrapInReference(operandStack.pop());
+ classCounter++;
+ } catch (NoSuchElementException e) {
+// operand1 = null;
+ operand1 = makeReference(classCounter);
+ }
}
}
}
+ System.err.println("Operand 1 done");
+ // Operand 2
if (!getNodeCat(operandTree2.getChild(0)).equals("variableExpr")) {
ref2 = operandTree2.getChild(0).toStringTree(parser).substring(1);
+ System.err.println("Operand 2: #"+ref2);
operand2 = variableReferences.get(ref2);
if (nodeReferencesTotal.get(ref2) > 1) {
if (nodeReferencesProcessed.get(ref2)==0) {
operand2 = wrapInClass(operand2);
- group = wrapInFocus(group);
- classCounter++;
+// group = wrapInFocus(group);
+// classCounter++;
nodeReferencesProcessed.put(ref2, nodeReferencesProcessed.get(ref2)+1);
} else if (nodeReferencesProcessed.get(ref2)>0 && nodeReferencesTotal.get(ref2)>1) {
- operand2 = null;
+ try {
+ operand2 = wrapInReference(operandStack.pop());
+ classCounter++;
+ } catch (NoSuchElementException e) {
+// operand2 = null;
+ operand2 = makeReference(classCounter);
+ }
}
}
}
+ System.err.println("Operand 2 done");
// Inject operands.
// -> Case distinction:
if (node.getChildCount()==3) {
- System.err.println("foo");
// Things are easy when there's just one operator (thus 3 children incl. operands)...
if (operand1 != null) operands.add(operand1);
if (operand2 != null) operands.add(operand2);
@@ -358,7 +377,7 @@
putIntoSuperObject(group);
if (!operandStack.isEmpty()) {
operands.add(0, operandStack.pop());
- operandStack.clear();
+// operandStack.clear();
}
objectStack.push(group);
stackedObjects++;
@@ -366,6 +385,7 @@
operandStack.push(group);
}
}
+ System.err.println(operandStack);
}
if (nodeCat.equals("variableExpr")) {
@@ -445,23 +465,19 @@
openNodeCats.pop();
}
-
- @SuppressWarnings("unchecked")
- private LinkedHashMap<String, Object> wrapInFocus(
- LinkedHashMap<String, Object> group) {
- LinkedHashMap<String, Object> focusGroup = makeGroup("focus");
- ((ArrayList<Object>) focusGroup.get("operands")).add(group);
- ArrayList<Integer> classRefs = new ArrayList<Integer>();
- classRefs.add(classCounter);
- focusGroup.put("classRef", classRefs);
- return focusGroup;
+ private LinkedHashMap<String, Object> wrapInReference(LinkedHashMap<String, Object> group) {
+ LinkedHashMap<String, Object> refGroup = makeReference(classCounter);
+ ArrayList<Object> operands = new ArrayList<Object>();
+ operands.add(group);
+ refGroup.put("operands", operands);
+ return refGroup;
}
@SuppressWarnings("unchecked")
- private LinkedHashMap<String, Object> wrapInClass(LinkedHashMap<String, Object> object) {
- LinkedHashMap<String, Object> group = makeClass(classCounter);
- ((ArrayList<Object>) group.get("operands")).add(object);
- return group;
+ private LinkedHashMap<String, Object> wrapInClass(LinkedHashMap<String, Object> group) {
+ LinkedHashMap<String, Object> classGroup = makeClass(classCounter);
+ ((ArrayList<Object>) classGroup.get("operands")).add(group);
+ return classGroup;
}
/**
@@ -782,8 +798,10 @@
// "cat=/NP/ > node",
// "/Mann/",
// "node > tok=\"foo\"",
- "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\"",
- "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3"
+// "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\"",
+// "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3",
+// "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3",
+ "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3"
};
AqlTree.verbose=true;
for (String q : queries) {