Search in sources :

Example 1 with PointingRelation

use of annis.sqlgen.model.PointingRelation in project ANNIS by korpling.

the class JoinListener method enterIndirectPointing.

@Override
public void enterIndirectPointing(AqlParser.IndirectPointingContext ctx) {
    QueryNode left = relationChain.get(relationIdx);
    QueryNode right = relationChain.get(relationIdx + 1);
    String label = getLayerName(ctx.POINTING(), 2);
    left.addOutgoingJoin(addParsedLocation(ctx, new PointingRelation(right, label)));
}
Also used : PointingRelation(annis.sqlgen.model.PointingRelation) QueryNode(annis.model.QueryNode)

Example 2 with PointingRelation

use of annis.sqlgen.model.PointingRelation in project ANNIS by korpling.

the class JoinListener method enterRangePointing.

@Override
public void enterRangePointing(AqlParser.RangePointingContext ctx) {
    QueryNode left = relationChain.get(relationIdx);
    QueryNode right = relationChain.get(relationIdx + 1);
    String label = getLayerName(ctx.POINTING(), 2);
    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");
    }
    left.addOutgoingJoin(addParsedLocation(ctx, new PointingRelation(right, label, range.getMin(), range.getMax())));
}
Also used : PointingRelation(annis.sqlgen.model.PointingRelation) QueryNode(annis.model.QueryNode) AnnisQLSemanticsException(annis.exceptions.AnnisQLSemanticsException)

Example 3 with PointingRelation

use of annis.sqlgen.model.PointingRelation in project ANNIS by korpling.

the class TestDefaultWhereClauseGenerator method shouldGenerateWhereConditionsForDirectPointingRelation.

/**
 * WHERE conditions for direct pointing relation (->).
 */
@Theory
public void shouldGenerateWhereConditionsForDirectPointingRelation(String componentPredicate) {
    // given
    String componentName = uniqueString();
    node23.addOutgoingJoin(new PointingRelation(node42, componentName, 1));
    // then
    checkEdgeConditions(componentPredicate, "p", componentName, false, join("=", "_rank23.id", "_rank42.parent"));
}
Also used : PointingRelation(annis.sqlgen.model.PointingRelation) TestUtils.uniqueString(annis.test.TestUtils.uniqueString) SqlConstraints.sqlString(annis.sqlgen.SqlConstraints.sqlString) Theory(org.junit.experimental.theories.Theory)

Example 4 with PointingRelation

use of annis.sqlgen.model.PointingRelation in project ANNIS by korpling.

the class TestDefaultWhereClauseGenerator method shouldGenerateWhereConditionsForIndirectPointingRelation.

/**
 * WHERE conditions for indirect pointing relation (->*).
 */
@Theory
public void shouldGenerateWhereConditionsForIndirectPointingRelation(String componentPredicate) {
    // given
    String componentName = uniqueString();
    node23.addOutgoingJoin(new PointingRelation(node42, componentName));
    // then
    checkEdgeConditions(componentPredicate, "p", componentName, true, join("<", "_rank23.pre", "_rank42.pre"), join("<", "_rank42.pre", "_rank23.post"));
}
Also used : PointingRelation(annis.sqlgen.model.PointingRelation) TestUtils.uniqueString(annis.test.TestUtils.uniqueString) SqlConstraints.sqlString(annis.sqlgen.SqlConstraints.sqlString) Theory(org.junit.experimental.theories.Theory)

Example 5 with PointingRelation

use of annis.sqlgen.model.PointingRelation in project ANNIS by korpling.

the class AbstractWhereClauseGenerator method whereConditions.

@Override
public Set<String> whereConditions(QueryData queryData, List<QueryNode> alternative, String indent) {
    List<String> conditions = new ArrayList<>();
    for (QueryNode node : alternative) {
        // node constraints
        if (node.getSpannedText() != null) {
            addSpanConditions(conditions, queryData, node);
        }
        if (node.isToken()) {
            addIsTokenConditions(conditions, queryData, node);
        }
        if (node.isRoot()) {
            addIsRootConditions(conditions, queryData, node);
        }
        if (node.getArity() != null) {
            addNodeArityConditions(conditions, queryData, node);
        }
        if (node.getTokenArity() != null) {
            addTokenArityConditions(conditions, queryData, node);
        }
        // node joins
        for (Join join : node.getOutgoingJoins()) {
            QueryNode target = join.getTarget();
            if (join instanceof SameSpan) {
                addSameSpanConditions(conditions, node, target, (SameSpan) join, queryData);
            } else if (join instanceof Identical) {
                addIdenticalConditions(conditions, node, target, (Identical) join, queryData);
            } else if (join instanceof LeftAlignment) {
                addLeftAlignmentConditions(conditions, node, target, (LeftAlignment) join, queryData);
            } else if (join instanceof RightAlignment) {
                addRightAlignmentConditions(conditions, node, target, (RightAlignment) join, queryData);
            } else if (join instanceof Inclusion) {
                addInclusionConditions(conditions, node, target, (Inclusion) join, queryData);
            } else if (join instanceof Overlap) {
                addOverlapConditions(conditions, node, target, (Overlap) join, queryData);
            } else if (join instanceof LeftOverlap) {
                addLeftOverlapConditions(conditions, target, node, (LeftOverlap) join, queryData);
            } else if (join instanceof RightOverlap) {
                addRightOverlapConditions(conditions, target, node, (RightOverlap) join, queryData);
            } else if (join instanceof Precedence) {
                addPrecedenceConditions(conditions, node, target, (Precedence) join, queryData);
            } else if (join instanceof Near) {
                addNearConditions(conditions, node, target, (Near) join, queryData);
            } else if (join instanceof Sibling) {
                addSiblingConditions(conditions, node, target, (Sibling) join, queryData);
            } else if (join instanceof CommonAncestor) {
                addCommonAncestorConditions(conditions, node, target, (CommonAncestor) join, queryData);
            } else if (join instanceof LeftDominance) {
                addLeftDominanceConditions(conditions, node, target, (LeftDominance) join, queryData);
            } else if (join instanceof RightDominance) {
                addRightDominanceConditions(conditions, node, target, (RightDominance) join, queryData);
            } else if (join instanceof Dominance) {
                addDominanceConditions(conditions, node, target, (Dominance) join, queryData);
            } else if (join instanceof PointingRelation) {
                addPointingRelationConditions(conditions, node, target, (PointingRelation) join, queryData);
            } else if (join instanceof EqualValue) {
                addEqualValueConditions(conditions, node, target, (EqualValue) join, queryData);
            } else if (join instanceof NotEqualValue) {
                addNotEqualValueConditions(conditions, node, target, (NotEqualValue) join, queryData);
            }
        }
        // node annotations
        int i = 0;
        for (QueryAnnotation annotation : node.getNodeAnnotations()) {
            ++i;
            addAnnotationConditions(conditions, node, i, annotation, NODE_ANNOTATION_TABLE, queryData);
        }
        // relation annotations
        int j = 0;
        for (QueryAnnotation annotation : node.getEdgeAnnotations()) {
            ++j;
            addAnnotationConditions(conditions, node, j, annotation, EDGE_ANNOTATION_TABLE, queryData);
        }
    }
    return new HashSet<>(conditions);
}
Also used : Identical(annis.sqlgen.model.Identical) Inclusion(annis.sqlgen.model.Inclusion) SameSpan(annis.sqlgen.model.SameSpan) RightAlignment(annis.sqlgen.model.RightAlignment) ArrayList(java.util.ArrayList) LeftAlignment(annis.sqlgen.model.LeftAlignment) RightOverlap(annis.sqlgen.model.RightOverlap) Overlap(annis.sqlgen.model.Overlap) LeftOverlap(annis.sqlgen.model.LeftOverlap) Sibling(annis.sqlgen.model.Sibling) CommonAncestor(annis.sqlgen.model.CommonAncestor) NotEqualValue(annis.sqlgen.model.NotEqualValue) HashSet(java.util.HashSet) PointingRelation(annis.sqlgen.model.PointingRelation) EqualValue(annis.sqlgen.model.EqualValue) NotEqualValue(annis.sqlgen.model.NotEqualValue) QueryAnnotation(annis.model.QueryAnnotation) RightOverlap(annis.sqlgen.model.RightOverlap) Join(annis.model.Join) RightDominance(annis.sqlgen.model.RightDominance) Dominance(annis.sqlgen.model.Dominance) LeftDominance(annis.sqlgen.model.LeftDominance) RightDominance(annis.sqlgen.model.RightDominance) Near(annis.sqlgen.model.Near) LeftDominance(annis.sqlgen.model.LeftDominance) QueryNode(annis.model.QueryNode) LeftOverlap(annis.sqlgen.model.LeftOverlap) Precedence(annis.sqlgen.model.Precedence)

Aggregations

PointingRelation (annis.sqlgen.model.PointingRelation)7 QueryNode (annis.model.QueryNode)5 Join (annis.model.Join)3 QueryAnnotation (annis.model.QueryAnnotation)2 SqlConstraints.sqlString (annis.sqlgen.SqlConstraints.sqlString)2 Dominance (annis.sqlgen.model.Dominance)2 TestUtils.uniqueString (annis.test.TestUtils.uniqueString)2 Theory (org.junit.experimental.theories.Theory)2 AnnisQLSemanticsException (annis.exceptions.AnnisQLSemanticsException)1 CommonAncestor (annis.sqlgen.model.CommonAncestor)1 EqualValue (annis.sqlgen.model.EqualValue)1 Identical (annis.sqlgen.model.Identical)1 Inclusion (annis.sqlgen.model.Inclusion)1 LeftAlignment (annis.sqlgen.model.LeftAlignment)1 LeftDominance (annis.sqlgen.model.LeftDominance)1 LeftOverlap (annis.sqlgen.model.LeftOverlap)1 Near (annis.sqlgen.model.Near)1 NotEqualValue (annis.sqlgen.model.NotEqualValue)1 Overlap (annis.sqlgen.model.Overlap)1 Precedence (annis.sqlgen.model.Precedence)1