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)));
}
}
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);
}
}
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())));
}
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;
}
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;
}
Aggregations