Search in sources :

Example 1 with AnnisQLSemanticsException

use of annis.exceptions.AnnisQLSemanticsException in project ANNIS by korpling.

the class JoinListener method enterRangePrecedence.

@Override
public void enterRangePrecedence(AqlParser.RangePrecedenceContext ctx) {
    QueryNode left = relationChain.get(relationIdx);
    QueryNode right = relationChain.get(relationIdx + 1);
    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");
    } else {
        String segmentationName = getLayerName(ctx.NAMED_PRECEDENCE());
        left.addOutgoingJoin(addParsedLocation(ctx, new Precedence(right, range.getMin(), range.getMax(), segmentationName)));
    }
}
Also used : QueryNode(annis.model.QueryNode) AnnisQLSemanticsException(annis.exceptions.AnnisQLSemanticsException) Precedence(annis.sqlgen.model.Precedence)

Example 2 with AnnisQLSemanticsException

use of annis.exceptions.AnnisQLSemanticsException in project ANNIS by korpling.

the class JoinListener method enterNonBindingRelation.

@Override
public void enterNonBindingRelation(AqlParser.NonBindingRelationContext ctx) {
    int numOfReferences = ctx.REF().size();
    relationIdx = 0;
    relationChain.clear();
    relationChain.ensureCapacity(numOfReferences);
    for (int i = 0; i < numOfReferences; i++) {
        QueryNode n = nodeByRef(ctx.REF(i).getSymbol());
        if (n == null) {
            throw new AnnisQLSemanticsException(AnnisParserAntlr.getLocation(ctx.getStart(), ctx.getStop()), "invalid reference to '" + ctx.REF(i).getText() + "'");
        }
        relationChain.add(i, n);
    }
}
Also used : QueryNode(annis.model.QueryNode) AnnisQLSemanticsException(annis.exceptions.AnnisQLSemanticsException)

Example 3 with AnnisQLSemanticsException

use of annis.exceptions.AnnisQLSemanticsException 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 4 with AnnisQLSemanticsException

use of annis.exceptions.AnnisQLSemanticsException 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 5 with AnnisQLSemanticsException

use of annis.exceptions.AnnisQLSemanticsException in project ANNIS by korpling.

the class FrequencySqlGenerator method conditionsForEntries.

private Multimap<FrequencyTableEntry, String> conditionsForEntries(List<FrequencyTableEntry> frequencyEntries, QueryData queryData, List<QueryNode> alternative) {
    Multimap<FrequencyTableEntry, String> conditions = LinkedHashMultimap.create();
    int i = 1;
    ImmutableMap<String, QueryNode> idxNodeVariables = Maps.uniqueIndex(alternative.iterator(), new Function<QueryNode, String>() {

        @Override
        public String apply(QueryNode input) {
            return input.getVariable();
        }
    });
    for (FrequencyTableEntry e : frequencyEntries) {
        if (e.getType() == FrequencyTableEntryType.meta) {
            List<String> qName = Splitter.on(':').limit(2).omitEmptyStrings().splitToList(e.getKey());
            if (qName.size() == 2) {
                conditions.put(e, "v" + i + ".namespace = '" + escaper.escape(qName.get(0)) + "'");
                conditions.put(e, "v" + i + ".name = '" + escaper.escape(qName.get(1)) + "'");
            } else {
                conditions.put(e, "v" + i + ".name = '" + escaper.escape(qName.get(0)) + "'");
            }
            conditions.put(e, "v" + i + ".corpus_ref = solutions.corpus_ref");
        } else {
            // general partition restriction
            conditions.put(e, "v" + i + ".toplevel_corpus IN (" + StringUtils.join(queryData.getCorpusList(), ",") + ")");
            // specificly join on top level corpus
            conditions.put(e, "v" + i + ".toplevel_corpus = solutions.toplevel_corpus");
            // join on node ID
            QueryNode referencedNode = idxNodeVariables.get(e.getReferencedNode());
            if (referencedNode == null) {
                throw new AnnisQLSemanticsException("No such node \"" + e.getReferencedNode() + "\". " + "Your query contains " + alternative.size() + " node(s), make sure no node definition numbers are greater than this number");
            }
            conditions.put(e, "v" + i + ".id = solutions.id" + referencedNode.getId());
            if (e.getType() == FrequencyTableEntryType.span) {
                conditions.put(e, "v" + i + ".n_sample IS TRUE");
            } else if (e.getType() == FrequencyTableEntryType.annotation) {
                // TODO: support namespaces
                // filter by selected key
                conditions.put(e, "v" + i + ".node_annotext LIKE '" + AnnotationConditionProvider.likeEscaper.escape(e.getKey()) + ":%'");
                conditions.put(e, "v" + i + ".n_na_sample IS TRUE");
            }
        }
        i++;
    }
    return conditions;
}
Also used : QueryNode(annis.model.QueryNode) AnnisQLSemanticsException(annis.exceptions.AnnisQLSemanticsException) FrequencyTableEntry(annis.service.objects.FrequencyTableEntry)

Aggregations

AnnisQLSemanticsException (annis.exceptions.AnnisQLSemanticsException)12 QueryNode (annis.model.QueryNode)10 LinkedList (java.util.LinkedList)5 AnnisQLSyntaxException (annis.exceptions.AnnisQLSyntaxException)3 AqlParseError (annis.model.AqlParseError)3 AnnisAttribute (annis.service.objects.AnnisAttribute)3 AnnisCorpusAccessException (annis.exceptions.AnnisCorpusAccessException)2 Match (annis.service.objects.Match)2 MatchGroup (annis.service.objects.MatchGroup)2 SubgraphFilter (annis.service.objects.SubgraphFilter)2 Stopwatch (com.google.common.base.Stopwatch)2 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)2 WebResource (com.sun.jersey.api.client.WebResource)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 HashMap (java.util.HashMap)2 SaltProject (org.corpus_tools.salt.common.SaltProject)2 Join (annis.model.Join)1