Search in sources :

Example 1 with QueryNode

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

the class GraphHelper method createQueryData.

/**
 * This is a helper function to make it easier to create a correct query data object
 * from a {@link MatchGroup} for a {@link AnnisDao#graph(annis.ql.parser.QueryData)  } query.
 *
 * @param matchGroup
 * @return
 */
public static QueryData createQueryData(MatchGroup matchGroup, QueryDao annisDao) {
    QueryData queryData = new QueryData();
    Set<String> corpusNames = new TreeSet<>();
    for (Match m : matchGroup.getMatches()) {
        // collect list of used corpora and created pseudo QueryNodes for each URI
        List<QueryNode> pseudoNodes = new ArrayList<>(m.getSaltIDs().size());
        for (java.net.URI u : m.getSaltIDs()) {
            pseudoNodes.add(new QueryNode());
            corpusNames.add(CommonHelper.getCorpusPath(u).get(0));
        }
        queryData.addAlternative(pseudoNodes);
    }
    List<Long> corpusIDs = annisDao.mapCorpusNamesToIds(new LinkedList<>(corpusNames));
    queryData.setCorpusList(corpusIDs);
    queryData.addExtension(matchGroup);
    return queryData;
}
Also used : QueryData(annis.ql.parser.QueryData) ArrayList(java.util.ArrayList) Match(annis.service.objects.Match) TreeSet(java.util.TreeSet) QueryNode(annis.model.QueryNode)

Example 2 with QueryNode

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

the class ComponentSearchRelationNormalizer method replicateFromJoinSource.

private void replicateFromJoinSource(Join join, QueryNode sourceNode, List<QueryNode> nodes, AtomicLong maxID) {
    Preconditions.checkState(sourceNode.removeOutgoingJoin(join), "The join was not attached to the source node.");
    QueryNode newNode = new QueryNode(maxID.incrementAndGet(), sourceNode, false);
    newNode.setVariable("x" + newNode.getId() + "(" + sourceNode.getVariable() + ")");
    newNode.addOutgoingJoin(join);
    newNode.setArtificial(true);
    Identical identJoin = new Identical(newNode);
    sourceNode.addOutgoingJoin(identJoin);
    nodes.add(newNode);
}
Also used : Identical(annis.sqlgen.model.Identical) QueryNode(annis.model.QueryNode)

Example 3 with QueryNode

use of annis.model.QueryNode 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 4 with QueryNode

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

the class ComponentSearchRelationNormalizer method transform.

@Override
public QueryData transform(QueryData data) {
    String originalAQL = data.toAQL();
    AtomicLong maxID = new AtomicLong();
    for (List<QueryNode> alternative : data.getAlternatives()) {
        for (QueryNode n : alternative) {
            maxID.set(Math.max(maxID.get(), n.getId()));
        }
    }
    for (List<QueryNode> alternative : data.getAlternatives()) {
        int disasterCounter = 0;
        while (checkForViolation(alternative, maxID)) {
            // repeat
            disasterCounter++;
            Preconditions.checkArgument(disasterCounter < 5000, "Possible endless loop in component search relation normalization for query " + originalAQL);
        }
        data.setMaxWidth(Math.max(data.getMaxWidth(), alternative.size()));
    }
    return data;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryNode(annis.model.QueryNode)

Example 5 with QueryNode

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

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