use of annis.sqlgen.model.Precedence in project ANNIS by korpling.
the class TransitivePrecedenceOptimizerTest method testDontUseRangedPrecendenceOnSpans.
@Test
public void testDontUseRangedPrecendenceOnSpans() {
assumeTrue(postProcessorExists);
System.out.println("dontUseRangedPrecendenceOnSpans");
// query to extend
String aql = "node & node & node & #1 . #2 & #2 . #3";
// optimizer is applied on the fly by the query anaylsis (as injected by Spring)
QueryData data = parser.parse(aql, new LinkedList<Long>());
assertEquals(1, data.getAlternatives().size());
List<QueryNode> nodes = data.getAlternatives().get(0);
assertEquals(2, nodes.get(0).getOutgoingJoins().size());
Join j0 = nodes.get(0).getOutgoingJoins().get(0);
Join j1 = nodes.get(0).getOutgoingJoins().get(1);
assertTrue(j0 instanceof Precedence);
assertTrue(j1 instanceof Precedence);
Precedence p0 = (Precedence) j0;
Precedence p1 = (Precedence) j1;
assertEquals(1, p0.getMinDistance());
assertEquals(1, p0.getMaxDistance());
assertEquals(0, p1.getMinDistance());
assertEquals(0, p1.getMaxDistance());
}
use of annis.sqlgen.model.Precedence in project ANNIS by korpling.
the class AbstractWhereClauseGenerator method whereConditions.
@Override
public Set<String> whereConditions(QueryData queryData, List<QueryNode> alternative, String indent) {
List<String> conditions = new ArrayList<>();
for (QueryNode node : alternative) {
// node constraints
if (node.getSpannedText() != null) {
addSpanConditions(conditions, queryData, node);
}
if (node.isToken()) {
addIsTokenConditions(conditions, queryData, node);
}
if (node.isRoot()) {
addIsRootConditions(conditions, queryData, node);
}
if (node.getArity() != null) {
addNodeArityConditions(conditions, queryData, node);
}
if (node.getTokenArity() != null) {
addTokenArityConditions(conditions, queryData, node);
}
// node joins
for (Join join : node.getOutgoingJoins()) {
QueryNode target = join.getTarget();
if (join instanceof SameSpan) {
addSameSpanConditions(conditions, node, target, (SameSpan) join, queryData);
} else if (join instanceof Identical) {
addIdenticalConditions(conditions, node, target, (Identical) join, queryData);
} else if (join instanceof LeftAlignment) {
addLeftAlignmentConditions(conditions, node, target, (LeftAlignment) join, queryData);
} else if (join instanceof RightAlignment) {
addRightAlignmentConditions(conditions, node, target, (RightAlignment) join, queryData);
} else if (join instanceof Inclusion) {
addInclusionConditions(conditions, node, target, (Inclusion) join, queryData);
} else if (join instanceof Overlap) {
addOverlapConditions(conditions, node, target, (Overlap) join, queryData);
} else if (join instanceof LeftOverlap) {
addLeftOverlapConditions(conditions, target, node, (LeftOverlap) join, queryData);
} else if (join instanceof RightOverlap) {
addRightOverlapConditions(conditions, target, node, (RightOverlap) join, queryData);
} else if (join instanceof Precedence) {
addPrecedenceConditions(conditions, node, target, (Precedence) join, queryData);
} else if (join instanceof Near) {
addNearConditions(conditions, node, target, (Near) join, queryData);
} else if (join instanceof Sibling) {
addSiblingConditions(conditions, node, target, (Sibling) join, queryData);
} else if (join instanceof CommonAncestor) {
addCommonAncestorConditions(conditions, node, target, (CommonAncestor) join, queryData);
} else if (join instanceof LeftDominance) {
addLeftDominanceConditions(conditions, node, target, (LeftDominance) join, queryData);
} else if (join instanceof RightDominance) {
addRightDominanceConditions(conditions, node, target, (RightDominance) join, queryData);
} else if (join instanceof Dominance) {
addDominanceConditions(conditions, node, target, (Dominance) join, queryData);
} else if (join instanceof PointingRelation) {
addPointingRelationConditions(conditions, node, target, (PointingRelation) join, queryData);
} else if (join instanceof EqualValue) {
addEqualValueConditions(conditions, node, target, (EqualValue) join, queryData);
} else if (join instanceof NotEqualValue) {
addNotEqualValueConditions(conditions, node, target, (NotEqualValue) join, queryData);
}
}
// node annotations
int i = 0;
for (QueryAnnotation annotation : node.getNodeAnnotations()) {
++i;
addAnnotationConditions(conditions, node, i, annotation, NODE_ANNOTATION_TABLE, queryData);
}
// relation annotations
int j = 0;
for (QueryAnnotation annotation : node.getEdgeAnnotations()) {
++j;
addAnnotationConditions(conditions, node, j, annotation, EDGE_ANNOTATION_TABLE, queryData);
}
}
return new HashSet<>(conditions);
}
use of annis.sqlgen.model.Precedence in project ANNIS by korpling.
the class TransitivePrecedenceOptimizer method createInitialJoinMap.
private Map<Long, Set<Precedence>> createInitialJoinMap(List<QueryNode> alternative) {
Map<Long, Set<Precedence>> result = new HashMap<>();
for (QueryNode node : alternative) {
Set<Precedence> joinList = new HashSet<>();
for (Join j : node.getOutgoingJoins()) {
if (j instanceof Precedence) {
joinList.add((Precedence) j);
}
}
result.put(node.getId(), joinList);
}
return result;
}
Aggregations