Changed label format in dominance.

Change-Id: Ie724196192c7850a1f01291467fb484752e6d52e
diff --git a/src/main/antlr/annis/AqlParser.g4 b/src/main/antlr/annis/AqlParser.g4
index bd0d8d6..6ef84fe 100644
--- a/src/main/antlr/annis/AqlParser.g4
+++ b/src/main/antlr/annis/AqlParser.g4
@@ -58,7 +58,7 @@
 ;
 
 edgeAnno
-:	((foundry '/')? layer eqOperator)? textSpec
+:	((foundry '/')? (layer COLON)? key eqOperator)? textSpec
 ;
 
 edgeSpec
@@ -76,16 +76,18 @@
 | PRECEDENCE (layer COMMA?)? rangeSpec #RangePrecedence
 ;
 
+// EM: it seems that dominance does not have qName
 dominance
 : DOMINANCE (qName)? (LEFT_CHILD | RIGHT_CHILD)? (anno=edgeSpec)? # DirectDominance
 | DOMINANCE (qName)? STAR # IndirectDominance
 | DOMINANCE (qName)? rangeSpec? # RangeDominance
 ;
 
+// EM: qName is edgeAnno
 pointing
-: POINTING edgeAnno (anno=edgeSpec)? # DirectPointing
-| POINTING edgeAnno (anno=edgeSpec)? STAR # IndirectPointing
-| POINTING edgeAnno (anno=edgeSpec)? COMMA? rangeSpec # RangePointing
+: POINTING (qName | edgeAnno) (anno=edgeSpec)? # DirectPointing
+| POINTING (qName | edgeAnno) (anno=edgeSpec)? STAR # IndirectPointing
+| POINTING (qName | edgeAnno) (anno=edgeSpec)? COMMA? rangeSpec # RangePointing
 
 //: POINTING qName (anno=edgeSpec)? # DirectPointing
 //| POINTING qName (anno=edgeSpec)? STAR # IndirectPointing
@@ -147,6 +149,9 @@
 layer
 : ID;
 
+key
+: ID;
+
 label
 : ID;
 
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java
index 5757625..c193300 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java
@@ -709,7 +709,7 @@
                     group = KoralObjectGenerator.makeGroup(KoralOperation.RELATION);
                     Map<String, Object> relation = new HashMap<String, Object>();
                     putAllButGroupType(relation, operatorGroup);
-                    group.put("relation", relation);
+                    group.put("relType", relation);
                 }
                 else if (groupType.equals("sequence")) {
                     group = KoralObjectGenerator.makeGroup(KoralOperation.SEQUENCE);
@@ -875,10 +875,9 @@
                 String edgeSpecType = (String) edgeSpec.get("@type");
                 if (edgeSpecType.equals("koral:termGroup")) {
                     ((ArrayList<Object>) edgeSpec.get("operands")).add(term);
-                    term = edgeSpec;
+//                    term = edgeSpec;
                 }
-                else {
-                    term = edgeSpec;
+//                else {
 //                    term = KoralObjectGenerator.makeTermGroup(KoralTermGroupRelation.AND);
 //                    ArrayList<Object> termGroupOperands = (ArrayList<Object>) term
 //                            .get("operands");
@@ -887,8 +886,11 @@
 //                            .makeTerm();
 //                    constTerm.put("layer", "c");
 //                    termGroupOperands.add(constTerm);
-                }
-                relation.put("label", term);
+//                }
+                term = edgeSpec;
+                Map<String, Object> relType = KoralObjectGenerator.makeRelation();
+                relType.put("wrap", term);
+                relation.put("relType", relType);
             }
             if (star != null)
                 relation.put("boundary",
@@ -900,22 +902,28 @@
             relation = KoralObjectGenerator.makeRelation();
             relation.put("groupType", "relation");
             ParseTree qName = getFirstChildWithCat(operatorNode, "qName");
-            ParseTree edgeSpec = getFirstChildWithCat(operatorNode, "edgeSpec");
+            ParseTree edgeSpec = getFirstChildWithCat(operatorNode, "edgeAnno");
             ParseTree star = getFirstChildWithCat(operatorNode, "*");
             ParseTree rangeSpec = getFirstChildWithCat(operatorNode,
                     "rangeSpec");
             Map<String, Object> term = KoralObjectGenerator
                     .makeTerm();
-            if (qName != null)
+            if (qName != null){
                 term.putAll(parseQNameNode(qName));
-            if (edgeSpec != null)
+                relation.put("wrap", term);
+            }
+            if (edgeSpec != null){
                 term.putAll(parseEdgeSpec(edgeSpec));
+                Map<String, Object> relType = KoralObjectGenerator.makeRelation();
+                relType.put("wrap", term);
+                relation.put("relType", relType);
+            }
             if (star != null)
                 relation.put("boundary",
                         KoralObjectGenerator.makeBoundary(0, null));
             if (rangeSpec != null)
                 relation.put("boundary", boundaryFromRangeSpec(rangeSpec));
-            relation.put("wrap", term);
+            
         }
         else if (operator.equals("precedence")) {
             relation = new HashMap<String, Object>();
@@ -1013,11 +1021,11 @@
         }
     }
 
-
     private Map<String, Object> parseEdgeAnno (ParseTree edgeAnnoSpec) {
         Map<String, Object> edgeAnno = KoralObjectGenerator
                 .makeTerm();
         ParseTree textSpecNode = getFirstChildWithCat(edgeAnnoSpec, "textSpec");
+        ParseTree keyNode = getFirstChildWithCat(edgeAnnoSpec, "key");
         ParseTree layerNode = getFirstChildWithCat(edgeAnnoSpec, "layer");
         ParseTree foundryNode = getFirstChildWithCat(edgeAnnoSpec, "foundry");
         ParseTree matchOperatorNode = getFirstChildWithCat(edgeAnnoSpec,
@@ -1027,7 +1035,9 @@
                     .toStringTree(parser));
         if (layerNode != null)
             edgeAnno.put("layer", layerNode.getChild(0).toStringTree(parser));
-        edgeAnno.putAll(parseTextSpec(textSpecNode));
+        if (keyNode != null)
+            edgeAnno.put("key", keyNode.getChild(0).toStringTree(parser));
+        edgeAnno.putAll(parseTextSpec(textSpecNode, "value"));
         edgeAnno.put("match", parseMatchOperator(matchOperatorNode));
         return edgeAnno;
     }
@@ -1070,16 +1080,19 @@
         return KoralObjectGenerator.makeDistance("w", min, max);
     }
 
-
     private Map<String, Object> parseTextSpec (ParseTree node) {
+        return parseTextSpec(node, "key");
+    }
+    
+    private Map<String, Object> parseTextSpec (ParseTree node, String name) {
         Map<String, Object> term = new HashMap<String, Object>();
         if (hasChild(node, "regex")) {
             term.put("type", "type:regex");
-            term.put("key", node.getChild(0).getChild(0).toStringTree(parser)
+            term.put(name, node.getChild(0).getChild(0).toStringTree(parser)
                     .replaceAll("/", ""));
         }
         else {
-            term.put("key", node.getChild(1).toStringTree(parser));
+            term.put(name, node.getChild(1).toStringTree(parser));
         }
         term.put("match", "match:eq");
         return term;
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/annis/DominanceTests.java b/src/test/java/de/ids_mannheim/korap/query/test/annis/DominanceTests.java
index ca8bce1..11d0a3b 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/annis/DominanceTests.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/annis/DominanceTests.java
@@ -173,99 +173,56 @@
         qs.setQuery(query, "annis");

         res = mapper.readTree(qs.toJSON());

         //        System.out.println(res.asText());

-        //        assertEquals("koral:relation",

-        //                res.at("/query/relation/@type").asText());

-        //        assertEquals("koral:termGroup",

-        //                res.at("/query/relation/wrap/@type").asText());

-        //        assertEquals("relation:and",

-        //                res.at("/query/relation/wrap/relation").asText());

-        //        assertEquals("c", 

-        //                res.at("/query/relation/wrap/operands/1/layer").asText());

-        //        assertEquals("func",

-        //                res.at("/query/relation/wrap/operands/0/layer").asText());

-        //        assertEquals("SB",

-        //                res.at("/query/relation/wrap/operands/0/key").asText());

+        assertEquals("operation:hierarchy",

+                res.at("/query/operation").asText());

+        assertEquals("koral:relation", res.at("/query/relType/@type").asText());

+        assertEquals("koral:term",

+                res.at("/query/relType/wrap/@type").asText());

+        assertEquals("func", res.at("/query/relType/wrap/key").asText());

+        assertEquals("SBJ", res.at("/query/relType/wrap/value").asText());

+    }

 

-        //        {

-        //            "@context": "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld",

-        //            "query": {

-        //                "operation": "operation:hierarchy",

-        //                "operands": [

-        //                    {"@type": "koral:span"},

-        //                    {

-        //                        "wrap": {

-        //                            "@type": "koral:term",

-        //                            "layer": "orth",

-        //                            "match": "match:eq",

-        //                            "key": "Mann"

-        //                        },

-        //                        "@type": "koral:token"

-        //                    }

-        //                ],

-        //                "@type": "koral:group",

-        //                "label": {

-        //                    "@type": "koral:term",

-        //                    "layer": "c",

-        //                    "match": "match:eq",

-        //                    "key": "SBJ"

-        //                }

-        //            }

-        //        }

+

+    @Test

+    public void testDominanceWithLayerAndType ()

+            throws JsonProcessingException, IOException {

+        query = "\"Mann\" & node & #2 >[c:func=\"SBJ\"] #1";

+        qs.setQuery(query, "annis");

+        res = mapper.readTree(qs.toJSON());

+        assertEquals("operation:hierarchy",

+                res.at("/query/operation").asText());

+        assertEquals("koral:relation", res.at("/query/relType/@type").asText());

+        assertEquals("koral:term",

+                res.at("/query/relType/wrap/@type").asText());

+        assertEquals("c", res.at("/query/relType/wrap/layer").asText());

+        assertEquals("func", res.at("/query/relType/wrap/key").asText());

+        assertEquals("SBJ", res.at("/query/relType/wrap/value").asText());

     }

 

 

     @Test

     public void testDominanceWithMultipleTypes ()

             throws JsonProcessingException, IOException {

-        query = "corenlp/c=\"VP\" & corenlp/c=\"NP\" & #1 >[malt/d=\"PP\" malt/d=\"PN\"] #2";

+        query = "corenlp/c=\"VP\" & corenlp/c=\"NP\" & #1 >[corenlp/c:func=\"PP\" corenlp/c:func=\"PN\"] #2";

         qs.setQuery(query, "annis");

         res = mapper.readTree(qs.toJSON());

         System.out.println(res.asText());

-

-        //      {

-        //          "@context": "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld",

-        //          "query": {

-        //              "operation": "operation:hierarchy",

-        //              "operands": [

-        //                  {

-        //                      "@type": "koral:span",

-        //                      "layer": "c",

-        //                      "foundry": "corenlp",

-        //                      "match": "match:eq",

-        //                      "key": "VP"

-        //                  },

-        //                  {

-        //                      "@type": "koral:span",

-        //                      "layer": "c",

-        //                      "foundry": "corenlp",

-        //                      "match": "match:eq",

-        //                      "key": "NP"

-        //                  }

-        //              ],

-        //              "@type": "koral:group",

-        //              "label": {

-        //                  "operands": [

-        //                      {

-        //                          "@type": "koral:term",

-        //                          "layer": "d",

-        //                          "foundry": "malt",

-        //                          "match": "match:eq",

-        //                          "key": "PP"

-        //                      },

-        //                      {

-        //                          "@type": "koral:term",

-        //                          "layer": "d",

-        //                          "foundry": "malt",

-        //                          "match": "match:eq",

-        //                          "key": "PN"

-        //                      },

-        //                      {"@type": "koral:term"}

-        //                  ],

-        //                  "@type": "koral:termGroup",

-        //                  "relation": "relation:and"

-        //              }

-        //          }

-        //      }

+        assertEquals("operation:hierarchy",

+                res.at("/query/operation").asText());

+        assertEquals("koral:relation", res.at("/query/relType/@type").asText());

+        assertEquals("koral:termGroup",

+                res.at("/query/relType/wrap/@type").asText());

+        assertEquals("relation:and",

+                res.at("/query/relType/wrap/relation").asText());

+        assertEquals("corenlp", res.at("/query/relType/wrap/operands/0/foundry").asText());

+        assertEquals("c", res.at("/query/relType/wrap/operands/0/layer").asText());

+        assertEquals("func", res.at("/query/relType/wrap/operands/0/key").asText());

+        assertEquals("PP", res.at("/query/relType/wrap/operands/0/value").asText());

+        

+        assertEquals("corenlp", res.at("/query/relType/wrap/operands/1/foundry").asText());

+        assertEquals("c", res.at("/query/relType/wrap/operands/1/layer").asText());

+        assertEquals("func", res.at("/query/relType/wrap/operands/1/key").asText());

+        assertEquals("PN", res.at("/query/relType/wrap/operands/1/value").asText());

     }

 

 

diff --git a/src/test/java/de/ids_mannheim/korap/query/test/annis/RelationTests.java b/src/test/java/de/ids_mannheim/korap/query/test/annis/RelationTests.java
index 33658d7..544f94b 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/annis/RelationTests.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/annis/RelationTests.java
@@ -18,7 +18,7 @@
     private JsonNode res;

 

     @Test

-    public void testLabelledRelationWithArbritraryNodes ()

+    public void testTypedRelationWithArbritraryNodes ()

             throws JsonProcessingException, IOException {

         query = "node & node & #1 ->malt/d=\"PP\" #2";

         qs.setQuery(query, "annis");

@@ -27,7 +27,7 @@
     }

     

     @Test

-    public void testLabelledRelation ()

+    public void testTypedRelation ()

             throws JsonProcessingException, IOException {

         query = "corenlp/c=\"VP\" & corenlp/c=\"NP\" & #1 ->malt/d=\"PP\" #2";

         qs.setQuery(query, "annis");

@@ -36,7 +36,7 @@
 

 

     @Test

-    public void testLabelledRelationWithType ()

+    public void testTypedRelationWithLabel ()

             throws JsonProcessingException, IOException {

         query = "corenlp/c=\"VP\" & corenlp/c=\"NP\" & #1 ->malt/d=\"PP\"[func=\"SB\"] #2";

         qs.setQuery(query, "annis");