Search in sources :

Example 1 with Join

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

the class ComponentSearchRelationNormalizer method checkForViolation.

private boolean checkForViolation(List<QueryNode> nodes, AtomicLong maxID) {
    Multimap<QueryNode, Join> joins = createJoinMap(nodes);
    LinkedList<QueryNode> nodeCopy = new LinkedList<>(nodes);
    for (QueryNode n : nodeCopy) {
        if (joins.get(n).size() > 1) {
            Iterator<Join> itJoinsForNode = joins.get(n).iterator();
            Join joinToSplit = itJoinsForNode.next();
            if (joinToSplit.getTarget().getId() == n.getId()) {
                replicateFromJoinTarget(joinToSplit, n, nodes, maxID);
            } else {
                replicateFromJoinSource(joinToSplit, n, nodes, maxID);
            }
            return true;
        }
    }
    return false;
}
Also used : QueryNode(annis.model.QueryNode) Join(annis.model.Join) LinkedList(java.util.LinkedList)

Example 2 with Join

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

the class JoinListener method enterDirectDominance.

@Override
public void enterDirectDominance(AqlParser.DirectDominanceContext ctx) {
    QueryNode left = relationChain.get(relationIdx);
    QueryNode right = relationChain.get(relationIdx + 1);
    String layer = getLayerName(ctx.NAMED_DOMINANCE());
    Join j;
    if (ctx.LEFT_CHILD() != null) {
        j = new LeftDominance(right, layer);
    } else if (ctx.RIGHT_CHILD() != null) {
        j = new RightDominance(right, layer);
    } else {
        j = new Dominance(right, layer, 1);
    }
    left.addOutgoingJoin(addParsedLocation(ctx, j));
    if (ctx.anno != null) {
        LinkedList<QueryAnnotation> annotations = fromRelationAnnotation(ctx.anno);
        for (QueryAnnotation a : annotations) {
            j.addEdgeAnnotation(a);
        }
    }
}
Also used : QueryNode(annis.model.QueryNode) QueryAnnotation(annis.model.QueryAnnotation) Join(annis.model.Join) RightDominance(annis.sqlgen.model.RightDominance) Dominance(annis.sqlgen.model.Dominance) LeftDominance(annis.sqlgen.model.LeftDominance) RightDominance(annis.sqlgen.model.RightDominance) LeftDominance(annis.sqlgen.model.LeftDominance)

Example 3 with Join

use of annis.model.Join 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)

Example 4 with Join

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

the class TransitivePrecedenceOptimizer method propagateNodePrecedence.

private void propagateNodePrecedence(QueryNode initialNode, QueryNode currentNode, Set<Long> visitedNodes, Map<Long, Set<Precedence>> outJoins, Range range, String segmentation) {
    visitedNodes.add(currentNode.getId());
    Map<QueryNode, Range> nextNodes = new HashMap<>();
    // iterator over all outgoing precedence joins
    List<Join> originalJoins = new LinkedList<>(currentNode.getOutgoingJoins());
    for (Join join : originalJoins) {
        if (join instanceof Precedence) {
            Precedence p = (Precedence) join;
            if ((segmentation == null && p.getSegmentationName() == null) || (segmentation != null && segmentation.equals(p.getSegmentationName()))) {
                Range newRange;
                if (range == null) {
                    // create a new range at initial node
                    newRange = new Range(p.getMinDistance(), p.getMaxDistance());
                } else {
                    // calculate the new range depending on old one
                    if (currentNode.isToken() == false || (range.getMin() == 0 && range.getMax() == 0) || (p.getMinDistance() == 0 && p.getMaxDistance() == 0)) {
                        // use unlimited range since
                        // a) the node could also be a
                        // span covering more than one token,
                        // b) the original constraint is an unlimited range
                        newRange = new Range(0, 0);
                    } else {
                        // add the new precendence values to the old one
                        newRange = new Range(range.getMin() + p.getMinDistance(), range.getMax() + p.getMaxDistance());
                    }
                }
                // put the target node in the list of nodes to check if not visited yet
                if (!visitedNodes.contains(p.getTarget().getId())) {
                    nextNodes.put(p.getTarget(), newRange);
                    Precedence newJoin = new Precedence(p.getTarget(), newRange.getMin(), newRange.getMax());
                    Set<Precedence> existingJoins = outJoins.get(initialNode.getId());
                    // only add if this join is not already included
                    // (which is always true for the initial node)
                    // and the join is more restrictive than any previous one
                    boolean moreRestrictive = true;
                    for (Precedence oldJoin : existingJoins) {
                        if (oldJoin.getTarget() == newJoin.getTarget()) {
                            if (!joinMoreRestrictive(oldJoin, newJoin)) {
                                moreRestrictive = false;
                                break;
                            }
                        }
                    }
                    if (moreRestrictive) {
                        // add newly created discovered transitive precedence
                        initialNode.addOutgoingJoin(newJoin);
                        existingJoins.add(newJoin);
                    }
                }
            // end if not visited yet
            }
        // end if segmentation matches
        }
    // end if is precedence join
    }
    for (Map.Entry<QueryNode, Range> e : nextNodes.entrySet()) {
        // call us recursivly but remember the range
        propagateNodePrecedence(initialNode, e.getKey(), visitedNodes, outJoins, e.getValue(), segmentation);
    }
}
Also used : HashMap(java.util.HashMap) QueryNode(annis.model.QueryNode) Join(annis.model.Join) Range(annis.model.QueryNode.Range) Precedence(annis.sqlgen.model.Precedence) Map(java.util.Map) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 5 with Join

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

the class SubcorpusConstraintWhereClause method commonWhereConditions.

// VR: inline
@Deprecated
public List<String> commonWhereConditions(List<QueryNode> nodes, List<Long> corpusList, List<Long> documents) {
    LinkedList<String> conditions = new LinkedList<>();
    // annotations can always only be inside a subcorpus/document
    QueryNode[] copyNodes = nodes.toArray(new QueryNode[nodes.size()]);
    for (int left = 0; left < copyNodes.length; left++) {
        for (int right = 0; right < copyNodes.length; right++) {
            if (left != right) {
                // only add constraint if the two nodes are not already connected by their component or node id
                boolean needsCorpusRef = false;
                for (Join j : copyNodes[left].getOutgoingJoins()) {
                    if (j.getTarget() != null && j.getTarget().getId() == copyNodes[right].getId()) {
                        if ((j instanceof RankTableJoin || j instanceof Identical)) {
                            // we definitly don't have to apply this join
                            needsCorpusRef = false;
                            break;
                        } else {
                            // there is at least one actual join between this nodes, assume we
                            // need a corpus_ref join for now
                            needsCorpusRef = true;
                        }
                    }
                }
                if (needsCorpusRef) {
                    conditions.add(join("=", tables(copyNodes[left]).aliasedColumn(NODE_TABLE, "corpus_ref"), tables(copyNodes[right]).aliasedColumn(NODE_TABLE, "corpus_ref")));
                }
            }
        // end if left != right
        }
    // end right loop
    }
    return conditions;
}
Also used : Identical(annis.sqlgen.model.Identical) QueryNode(annis.model.QueryNode) Join(annis.model.Join) RankTableJoin(annis.sqlgen.model.RankTableJoin) RankTableJoin(annis.sqlgen.model.RankTableJoin) LinkedList(java.util.LinkedList)

Aggregations

Join (annis.model.Join)13 QueryNode (annis.model.QueryNode)12 QueryAnnotation (annis.model.QueryAnnotation)4 Dominance (annis.sqlgen.model.Dominance)4 Precedence (annis.sqlgen.model.Precedence)4 LinkedList (java.util.LinkedList)4 LeftDominance (annis.sqlgen.model.LeftDominance)3 PointingRelation (annis.sqlgen.model.PointingRelation)3 RightDominance (annis.sqlgen.model.RightDominance)3 HashSet (java.util.HashSet)3 Identical (annis.sqlgen.model.Identical)2 Inclusion (annis.sqlgen.model.Inclusion)2 LeftAlignment (annis.sqlgen.model.LeftAlignment)2 LeftOverlap (annis.sqlgen.model.LeftOverlap)2 NonBindingJoin (annis.sqlgen.model.NonBindingJoin)2 Overlap (annis.sqlgen.model.Overlap)2 RightAlignment (annis.sqlgen.model.RightAlignment)2 RightOverlap (annis.sqlgen.model.RightOverlap)2 SameSpan (annis.sqlgen.model.SameSpan)2 HashMap (java.util.HashMap)2