Search in sources :

Example 16 with QueryAnnotation

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

the class JoinListener method enterDirectPointing.

@Override
public void enterDirectPointing(AqlParser.DirectPointingContext ctx) {
    QueryNode left = relationChain.get(relationIdx);
    QueryNode right = relationChain.get(relationIdx + 1);
    String label = getLayerName(ctx.POINTING(), 2);
    Join j = new PointingRelation(right, label, 1);
    if (ctx.anno != null) {
        LinkedList<QueryAnnotation> annotations = fromRelationAnnotation(ctx.anno);
        for (QueryAnnotation a : annotations) {
            j.addEdgeAnnotation(a);
        }
    }
    left.addOutgoingJoin(addParsedLocation(ctx, j));
}
Also used : PointingRelation(annis.sqlgen.model.PointingRelation) QueryNode(annis.model.QueryNode) QueryAnnotation(annis.model.QueryAnnotation) Join(annis.model.Join)

Example 17 with QueryAnnotation

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

the class JoinListener method fromRelationAnnotation.

private LinkedList<QueryAnnotation> fromRelationAnnotation(AqlParser.EdgeSpecContext ctx) {
    LinkedList<QueryAnnotation> annos = new LinkedList<>();
    for (AqlParser.EdgeAnnoContext annoCtx : ctx.edgeAnno()) {
        String namespace = annoCtx.qName().namespace == null ? null : annoCtx.qName().namespace.getText();
        String name = annoCtx.qName().name.getText();
        String value = QueryNodeListener.textFromSpec(annoCtx.value);
        QueryNode.TextMatching matching = QueryNodeListener.textMatchingFromSpec(annoCtx.value, annoCtx.NEQ() != null);
        annos.add(new QueryAnnotation(namespace, name, value, matching));
    }
    return annos;
}
Also used : QueryAnnotation(annis.model.QueryAnnotation) QueryNode(annis.model.QueryNode) AqlParser(annis.ql.AqlParser) LinkedList(java.util.LinkedList)

Example 18 with QueryAnnotation

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

the class QueryNodeListener method enterAnnoOnlyExpr.

@Override
public void enterAnnoOnlyExpr(AqlParser.AnnoOnlyExprContext ctx) {
    QueryNode target = newNode(ctx);
    String namespace = ctx.qName().namespace == null ? null : ctx.qName().namespace.getText();
    QueryAnnotation anno = new QueryAnnotation(namespace, ctx.qName().name.getText());
    target.addNodeAnnotation(anno);
}
Also used : QueryNode(annis.model.QueryNode) QueryAnnotation(annis.model.QueryAnnotation)

Example 19 with QueryAnnotation

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

the class QueryNodeListener method enterAnnoEqTextExpr.

@Override
public void enterAnnoEqTextExpr(AqlParser.AnnoEqTextExprContext ctx) {
    QueryNode target = newNode(ctx);
    String namespace = ctx.qName().namespace == null ? null : ctx.qName().namespace.getText();
    String name = ctx.qName().name.getText();
    String value = textFromSpec(ctx.txt);
    QueryNode.TextMatching matching = textMatchingFromSpec(ctx.txt, ctx.NEQ() != null);
    QueryAnnotation anno = new QueryAnnotation(namespace, name, value, matching);
    target.addNodeAnnotation(anno);
}
Also used : QueryNode(annis.model.QueryNode) QueryAnnotation(annis.model.QueryAnnotation)

Example 20 with QueryAnnotation

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

the class FrequencyQueryPanel method createAutomaticEntriesForQuery.

private void createAutomaticEntriesForQuery(String query) {
    if (query == null || query.isEmpty()) {
        return;
    }
    try {
        state.getFrequencyTableDefinition().removeAllItems();
        lblErrorOrMsg.setVisible(false);
        counter = 0;
        List<QueryNode> nodes = parseQuery(query);
        Collections.sort(nodes, new Comparator<QueryNode>() {

            @Override
            public int compare(QueryNode o1, QueryNode o2) {
                if (o1.getVariable() == null) {
                    return o2 == null ? 0 : -1;
                }
                return o1.getVariable().compareTo(o2.getVariable());
            }
        });
        // calculate the nodes that are part of every alternative
        Multimap<String, Integer> alternativesOfVariable = LinkedHashMultimap.create();
        int maxAlternative = 0;
        for (QueryNode n : nodes) {
            if (n.getAlternativeNumber() != null) {
                maxAlternative = Math.max(n.getAlternativeNumber(), maxAlternative);
                alternativesOfVariable.put(n.getVariable(), n.getAlternativeNumber());
            }
        }
        Set<String> allowedVariables = new LinkedHashSet<>();
        for (QueryNode n : nodes) {
            // we assume that the alternative numbering is continuous and without gaps
            if (alternativesOfVariable.get(n.getVariable()).size() == (maxAlternative + 1)) {
                allowedVariables.add(n.getVariable());
            }
        }
        if (maxAlternative > 0 && allowedVariables.isEmpty()) {
            lblErrorOrMsg.setVisible(true);
        }
        Set<UserGeneratedFrequencyEntry> generatedEntries = new HashSet<>();
        for (QueryNode n : nodes) {
            if (!n.isArtificial() && allowedVariables.contains(n.getVariable())) {
                if (n.getNodeAnnotations().isEmpty()) {
                    UserGeneratedFrequencyEntry entry = new UserGeneratedFrequencyEntry();
                    entry.setAnnotation("tok");
                    entry.setComment("automatically created from " + n.toAQLNodeFragment());
                    entry.setNr(n.getVariable());
                    if (!generatedEntries.contains(entry)) {
                        int id = counter++;
                        state.getFrequencyTableDefinition().addItem(id, entry);
                        generatedEntries.add(entry);
                    }
                } else {
                    QueryAnnotation firstAnno = n.getNodeAnnotations().iterator().next();
                    UserGeneratedFrequencyEntry entry = new UserGeneratedFrequencyEntry();
                    entry.setAnnotation(firstAnno.getName());
                    entry.setComment("automatically created from " + n.toAQLNodeFragment());
                    entry.setNr(n.getVariable());
                    if (!generatedEntries.contains(entry)) {
                        int id = counter++;
                        state.getFrequencyTableDefinition().addItem(id, entry);
                        generatedEntries.add(entry);
                    }
                }
            }
        }
    } catch (UniformInterfaceException ex) {
    // non-valid query, ignore
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) QueryAnnotation(annis.model.QueryAnnotation) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) QueryNode(annis.model.QueryNode) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

QueryAnnotation (annis.model.QueryAnnotation)20 QueryNode (annis.model.QueryNode)9 Test (org.junit.Test)7 Dominance (annis.sqlgen.model.Dominance)5 LeftDominance (annis.sqlgen.model.LeftDominance)5 RightDominance (annis.sqlgen.model.RightDominance)5 Join (annis.model.Join)4 PointingRelation (annis.sqlgen.model.PointingRelation)2 Precedence (annis.sqlgen.model.Precedence)2 TestUtils.uniqueString (annis.test.TestUtils.uniqueString)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 AnnisQLSemanticsException (annis.exceptions.AnnisQLSemanticsException)1 AqlParseError (annis.model.AqlParseError)1 AqlParser (annis.ql.AqlParser)1 AnnisAttribute (annis.service.objects.AnnisAttribute)1 SqlConstraints.numberJoin (annis.sqlgen.SqlConstraints.numberJoin)1 SqlConstraints.sqlString (annis.sqlgen.SqlConstraints.sqlString)1 CommonAncestor (annis.sqlgen.model.CommonAncestor)1