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