use of annis.model.QueryNode in project ANNIS by korpling.
the class GraphHelper method createQueryData.
/**
* This is a helper function to make it easier to create a correct query data object
* from a {@link MatchGroup} for a {@link AnnisDao#graph(annis.ql.parser.QueryData) } query.
*
* @param matchGroup
* @return
*/
public static QueryData createQueryData(MatchGroup matchGroup, QueryDao annisDao) {
QueryData queryData = new QueryData();
Set<String> corpusNames = new TreeSet<>();
for (Match m : matchGroup.getMatches()) {
// collect list of used corpora and created pseudo QueryNodes for each URI
List<QueryNode> pseudoNodes = new ArrayList<>(m.getSaltIDs().size());
for (java.net.URI u : m.getSaltIDs()) {
pseudoNodes.add(new QueryNode());
corpusNames.add(CommonHelper.getCorpusPath(u).get(0));
}
queryData.addAlternative(pseudoNodes);
}
List<Long> corpusIDs = annisDao.mapCorpusNamesToIds(new LinkedList<>(corpusNames));
queryData.setCorpusList(corpusIDs);
queryData.addExtension(matchGroup);
return queryData;
}
use of annis.model.QueryNode in project ANNIS by korpling.
the class ComponentSearchRelationNormalizer method replicateFromJoinSource.
private void replicateFromJoinSource(Join join, QueryNode sourceNode, List<QueryNode> nodes, AtomicLong maxID) {
Preconditions.checkState(sourceNode.removeOutgoingJoin(join), "The join was not attached to the source node.");
QueryNode newNode = new QueryNode(maxID.incrementAndGet(), sourceNode, false);
newNode.setVariable("x" + newNode.getId() + "(" + sourceNode.getVariable() + ")");
newNode.addOutgoingJoin(join);
newNode.setArtificial(true);
Identical identJoin = new Identical(newNode);
sourceNode.addOutgoingJoin(identJoin);
nodes.add(newNode);
}
use of annis.model.QueryNode in project ANNIS by korpling.
the class ComponentSearchRelationNormalizer method checkForViolation.
private boolean checkForViolation(List<QueryNode> nodes, AtomicLong maxID) {
Multimap<QueryNode, Join> joins = createJoinMap(nodes);
LinkedList<QueryNode> nodeCopy = new LinkedList<>(nodes);
for (QueryNode n : nodeCopy) {
if (joins.get(n).size() > 1) {
Iterator<Join> itJoinsForNode = joins.get(n).iterator();
Join joinToSplit = itJoinsForNode.next();
if (joinToSplit.getTarget().getId() == n.getId()) {
replicateFromJoinTarget(joinToSplit, n, nodes, maxID);
} else {
replicateFromJoinSource(joinToSplit, n, nodes, maxID);
}
return true;
}
}
return false;
}
use of annis.model.QueryNode in project ANNIS by korpling.
the class ComponentSearchRelationNormalizer method transform.
@Override
public QueryData transform(QueryData data) {
String originalAQL = data.toAQL();
AtomicLong maxID = new AtomicLong();
for (List<QueryNode> alternative : data.getAlternatives()) {
for (QueryNode n : alternative) {
maxID.set(Math.max(maxID.get(), n.getId()));
}
}
for (List<QueryNode> alternative : data.getAlternatives()) {
int disasterCounter = 0;
while (checkForViolation(alternative, maxID)) {
// repeat
disasterCounter++;
Preconditions.checkArgument(disasterCounter < 5000, "Possible endless loop in component search relation normalization for query " + originalAQL);
}
data.setMaxWidth(Math.max(data.getMaxWidth(), alternative.size()));
}
return data;
}
use of annis.model.QueryNode 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);
}
}
}
Aggregations