use of annis.model.QueryNode in project ANNIS by korpling.
the class TransitivePrecedenceOptimizer method transform.
@Override
public QueryData transform(QueryData data) {
// initialize helper variables
HashSet<Long> visitedNodes = new HashSet<>();
for (List<QueryNode> alternative : data.getAlternatives()) {
Map<Long, Set<Precedence>> outJoins = createInitialJoinMap(alternative);
for (QueryNode node : alternative) {
Set<String> segmentations = getAllSegmentations(node);
visitedNodes.clear();
// we apply the algorithm node by node
// tok == null segmentation
propagateNodePrecedence(node, node, visitedNodes, outJoins, null, null);
for (String s : segmentations) {
propagateNodePrecedence(node, node, visitedNodes, outJoins, null, s);
}
}
}
return data;
}
use of annis.model.QueryNode 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