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);
}
}
}
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);
}
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;
}
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;
}
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:%'");
}
Aggregations