Skip to content

Commit

Permalink
AQL: don't allow non-binding operators "==" and "!=" directly between…
Browse files Browse the repository at this point in the history
… node definitions.

This removes an ambiquity for the "!=" token. E.g.

tok!="the"

could be interpreted as "All token which don't have "the" as value" or as

tok & "the" & #1 != #2

The latter one is semantically invalid (no binding) so the ambiquity is solved by not allowing the AQL operator "!=" and "==" in short AQL definitions.

This fixes #494.
  • Loading branch information
thomaskrause committed Feb 15, 2016
1 parent 3198712 commit 6efd4ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
11 changes: 8 additions & 3 deletions annis-service/src/main/antlr4/annis/ql/AqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ notequalvalue
: NEQ
;


operator
: precedence
| near
Expand All @@ -119,13 +120,17 @@ operator
| commonparent
| commonancestor
| identity
| equalvalue
| notequalvalue
;

/* Addtional operators that are do not bind two variables. */
nonbinding_operator
: equalvalue
| notequalvalue
;

n_ary_linguistic_term
: refOrNode (operator refOrNode)+ # Relation
: refOrNode (operator refOrNode)+ # BindingRelation
| REF (nonbinding_operator REF)+ # NonBindingRelation
;


Expand Down
24 changes: 22 additions & 2 deletions annis-service/src/main/java/annis/ql/parser/JoinListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ public void exitOperator(AqlParser.OperatorContext ctx)
relationIdx++;
}


@Override
public void enterRelation(AqlParser.RelationContext ctx)
public void enterBindingRelation(AqlParser.BindingRelationContext ctx)
{
int numOfReferences = ctx.refOrNode().size();
relationIdx = 0;
Expand All @@ -145,6 +144,27 @@ public void enterRelation(AqlParser.RelationContext ctx)
relationChain.add(i, n);
}
}

@Override
public void enterNonBindingRelation(AqlParser.NonBindingRelationContext ctx)
{
int numOfReferences = ctx.REF().size();
relationIdx = 0;
relationChain.clear();
relationChain.ensureCapacity(numOfReferences);

for(int i=0; i < numOfReferences; i++)
{
QueryNode n = nodeByRef(ctx.REF(i).getSymbol());
if(n == null)
{
throw new AnnisQLSemanticsException(
AnnisParserAntlr.getLocation(ctx.getStart(), ctx.getStop()),
"invalid reference to '" + ctx.REF(i).getText() + "'");
}
relationChain.add(i, n);
}
}

@Override
public void enterRootTerm(AqlParser.RootTermContext ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
<value><![CDATA[node _ident_ node _ident_ pos="NN"]]></value>
<value><![CDATA[pos . lemma . pos & #1 == #2]]></value>
<value><![CDATA[pos . lemma . pos & #1 != #2]]></value>
<!-- <value><![CDATA[ZH1Diff="INS" . tok!=""]]></value> -->
<!-- issue #494 -->
<value><![CDATA[ZH1Diff="INS" . tok!=""]]></value>
<!-- corner cases of OR -->
<value><![CDATA["das" | "die" | "der"]]></value>
<value><![CDATA["das" | ("die" & pos="NN" & #2 . #3) | "der"]]></value>
Expand Down

0 comments on commit 6efd4ae

Please sign in to comment.