Search in sources :

Example 1 with QueryAnnotation

use of annis.model.QueryAnnotation 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 2 with QueryAnnotation

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

the class QueryNodeListener method enterMetaTermExpr.

@Override
public void enterMetaTermExpr(AqlParser.MetaTermExprContext ctx) {
    // TODO: we have to disallow OR expressions with metadata, how can we
    // achvieve that?
    String namespace = ctx.id.namespace == null ? null : ctx.id.namespace.getText();
    String name = ctx.id.name.getText();
    String value = textFromSpec(ctx.txt);
    QueryNode.TextMatching textMatching = textMatchingFromSpec(ctx.txt, ctx.NEQ() != null);
    QueryAnnotation anno = new QueryAnnotation(namespace, name, value, textMatching);
    metaData.add(anno);
}
Also used : QueryNode(annis.model.QueryNode) QueryAnnotation(annis.model.QueryAnnotation)

Example 3 with QueryAnnotation

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

the class AnnotationExistenceValidator method transform.

@Override
public QueryData transform(QueryData data) {
    List<Long> corpusList = data.getCorpusList();
    if (queryDao != null && (corpusList != null) && !corpusList.isEmpty()) {
        // get first corpus name
        // List<AnnisCorpus> mycorpora = queryDao.listCorpora();
        // String firstcorpusname =  mycorpora.get(0).getName();
        Set<String> result = new TreeSet<>();
        /*get a list of all annotations in a similar way that TigerQueryBuilder gets it through 
       QueryServiceImpl in queryDao.listAnnotations()*/
        List<AnnisAttribute> atts = queryDao.listAnnotations(corpusList, false, true);
        // among them, get only node annotations
        for (AnnisAttribute a : atts) {
            if (a.getType() == AnnisAttribute.Type.node) {
                List<String> splitted = Splitter.on(":").limit(2).omitEmptyStrings().trimResults().splitToList(a.getName());
                result.add(splitted.get(splitted.size() - 1));
            // result is a set of strings of available annotations
            }
        }
        List<AqlParseError> errors = new LinkedList<>();
        for (List<QueryNode> alternative : data.getAlternatives()) {
            for (QueryNode n : alternative) {
                Set<QueryAnnotation> m = n.getNodeAnnotations();
                // always get the first one
                if (!m.isEmpty()) {
                    // name is the node name string, ready to check if name is in the list of
                    // available names
                    String name = m.iterator().next().getName();
                    if (!result.contains(name)) {
                        errors.add(new AqlParseError(n, "\"" + name + "\"" + " is not a valid annotation name in selected corpora "));
                    }
                }
            }
        }
        if (!errors.isEmpty()) {
            throw new AnnisQLSemanticsException("Invalid annotation names detected.", errors);
        }
    }
    return data;
}
Also used : QueryAnnotation(annis.model.QueryAnnotation) AnnisAttribute(annis.service.objects.AnnisAttribute) AqlParseError(annis.model.AqlParseError) AnnisQLSemanticsException(annis.exceptions.AnnisQLSemanticsException) LinkedList(java.util.LinkedList) TreeSet(java.util.TreeSet) QueryNode(annis.model.QueryNode)

Example 4 with QueryAnnotation

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

the class AnnotationConditionProvider method haveSameNodeAnnotationDefinitions.

private boolean haveSameNodeAnnotationDefinitions(Set<QueryAnnotation> sourceAnnos, Set<QueryAnnotation> targetAnnos) {
    if (sourceAnnos != null && targetAnnos != null && sourceAnnos.size() == 1 && targetAnnos.size() == 1) {
        QueryAnnotation anno1 = sourceAnnos.iterator().next();
        QueryAnnotation anno2 = targetAnnos.iterator().next();
        if (Objects.equal(anno1.getNamespace(), anno2.getNamespace()) && Objects.equal(anno1.getName(), anno2.getName())) {
            return true;
        }
    }
    return false;
}
Also used : QueryAnnotation(annis.model.QueryAnnotation)

Example 5 with QueryAnnotation

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

the class TestDefaultWhereClauseGenerator method whereClauseForNodeEdgeAnnotationNot.

@Test
public void whereClauseForNodeEdgeAnnotationNot() {
    Dominance j = new Dominance(node23);
    j.addEdgeAnnotation(new QueryAnnotation("namespace2", "name2", "value2", TextMatching.EXACT_NOT_EQUAL));
    j.addEdgeAnnotation(new QueryAnnotation("namespace3", "name3", "value3", TextMatching.REGEXP_NOT_EQUAL));
    node42.addOutgoingJoin(j);
    checkWhereConditions("_rank_annotation23_1.qannotext NOT LIKE 'namespace2:name2:value2'", "_rank_annotation23_1.qannotext LIKE 'namespace2:name2:%'", "_rank_annotation23_2.qannotext !~ '^(namespace3:name3:(value3))$'", "_rank_annotation23_2.qannotext LIKE 'namespace3:name3:%'");
}
Also used : QueryAnnotation(annis.model.QueryAnnotation) RightDominance(annis.sqlgen.model.RightDominance) Dominance(annis.sqlgen.model.Dominance) LeftDominance(annis.sqlgen.model.LeftDominance) Test(org.junit.Test)

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