Search in sources :

Example 11 with QueryNode

use of annis.model.QueryNode in project ANNIS by korpling.

the class JoinListener method enterTokenArityTerm.

@Override
public void enterTokenArityTerm(AqlParser.TokenArityTermContext ctx) {
    QueryNode target = nodeByRef(ctx.left);
    Preconditions.checkArgument(target != null, errorLHS("token-arity") + ": " + ctx.getText());
    target.setTokenArity(annisRangeFromARangeSpec(ctx.rangeSpec()));
}
Also used : QueryNode(annis.model.QueryNode)

Example 12 with QueryNode

use of annis.model.QueryNode in project ANNIS by korpling.

the class JoinListener method enterRangePrecedence.

@Override
public void enterRangePrecedence(AqlParser.RangePrecedenceContext ctx) {
    QueryNode left = relationChain.get(relationIdx);
    QueryNode right = relationChain.get(relationIdx + 1);
    QueryNode.Range range = annisRangeFromARangeSpec(ctx.rangeSpec());
    if (range.getMin() == 0 || range.getMax() == 0) {
        throw new AnnisQLSemanticsException(AnnisParserAntlr.getLocation(ctx.getStart(), ctx.getStop()), "Distance can't be 0");
    } else if (range.getMin() > range.getMax()) {
        throw new AnnisQLSemanticsException(AnnisParserAntlr.getLocation(ctx.getStart(), ctx.getStop()), "Minimal distance can't be larger than maximal distance");
    } else {
        String segmentationName = getLayerName(ctx.NAMED_PRECEDENCE());
        left.addOutgoingJoin(addParsedLocation(ctx, new Precedence(right, range.getMin(), range.getMax(), segmentationName)));
    }
}
Also used : QueryNode(annis.model.QueryNode) AnnisQLSemanticsException(annis.exceptions.AnnisQLSemanticsException) Precedence(annis.sqlgen.model.Precedence)

Example 13 with QueryNode

use of annis.model.QueryNode in project ANNIS by korpling.

the class JoinListener method enterIndirectPrecedence.

@Override
public void enterIndirectPrecedence(AqlParser.IndirectPrecedenceContext ctx) {
    QueryNode left = relationChain.get(relationIdx);
    QueryNode right = relationChain.get(relationIdx + 1);
    String segmentationName = getLayerName(ctx.NAMED_PRECEDENCE());
    if (precedenceBound > 0) {
        left.addOutgoingJoin(addParsedLocation(ctx, new Precedence(right, 1, precedenceBound, segmentationName)));
    } else {
        left.addOutgoingJoin(addParsedLocation(ctx, new Precedence(right, segmentationName)));
    }
}
Also used : QueryNode(annis.model.QueryNode) Precedence(annis.sqlgen.model.Precedence)

Example 14 with QueryNode

use of annis.model.QueryNode in project ANNIS by korpling.

the class JoinListener method enterNonBindingRelation.

@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);
    }
}
Also used : QueryNode(annis.model.QueryNode) AnnisQLSemanticsException(annis.exceptions.AnnisQLSemanticsException)

Example 15 with QueryNode

use of annis.model.QueryNode in project ANNIS by korpling.

the class JoinListener method join.

/**
 * Automatically create a join from a node and a join class.
 *
 * This will automatically get the left and right hand refs
 * and will construct a new join specified by the type using reflection.
 *
 * It will also add an parsed location to the join.
 *
 * @node
 * @type00
 */
private void join(ParserRuleContext ctx, Class<? extends Join> type) {
    QueryNode left = relationChain.get(relationIdx);
    QueryNode right = relationChain.get(relationIdx + 1);
    try {
        Constructor<? extends Join> c = type.getConstructor(QueryNode.class);
        Join newJoin = c.newInstance(right);
        left.addOutgoingJoin(addParsedLocation(ctx, newJoin));
    } catch (NoSuchMethodException ex) {
        log.error(null, ex);
    } catch (InstantiationException ex) {
        log.error(null, ex);
    } catch (IllegalAccessException ex) {
        log.error(null, ex);
    } catch (InvocationTargetException ex) {
        log.error(null, ex);
    }
}
Also used : QueryNode(annis.model.QueryNode) Join(annis.model.Join) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

QueryNode (annis.model.QueryNode)67 Join (annis.model.Join)12 LinkedList (java.util.LinkedList)11 AnnisQLSemanticsException (annis.exceptions.AnnisQLSemanticsException)10 ArrayList (java.util.ArrayList)8 QueryAnnotation (annis.model.QueryAnnotation)7 Precedence (annis.sqlgen.model.Precedence)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Dominance (annis.sqlgen.model.Dominance)5 PointingRelation (annis.sqlgen.model.PointingRelation)5 TestUtils.uniqueString (annis.test.TestUtils.uniqueString)5 TreeSet (java.util.TreeSet)5 Test (org.junit.Test)5 Identical (annis.sqlgen.model.Identical)4 LeftDominance (annis.sqlgen.model.LeftDominance)4 Near (annis.sqlgen.model.Near)4 RightDominance (annis.sqlgen.model.RightDominance)4 TestUtils.uniqueLong (annis.test.TestUtils.uniqueLong)4 QueryData (annis.ql.parser.QueryData)3