use of annis.model.QueryAnnotation in project ANNIS by korpling.
the class TestAbstractFromClauseGenerator method setupTableAliases.
// set up table access strategy to return the requested table alias
// simulate that count copies of the table (alias) are required
private Map<String, String> setupTableAliases(QueryNode node, String table, String tableAlias, int count) {
HashMap<String, String> tableAliases = new HashMap<>();
tableAliases.put(table, tableAlias);
if (count > 0) {
tableAliases.put(TableAccessStrategy.NODE_ANNOTATION_TABLE, tableAlias);
}
for (int i = 0; i < count; i++) {
// this will add new entries for the source tables
node.addNodeAnnotation(new QueryAnnotation("dummy", "dummy" + i));
}
tableAccessStrategy.setTableAliases(tableAliases);
tableAccessStrategy.setNode(node);
Bag tables = new HashBag();
tables.add(tableAlias, count);
given(tableAccessStrategy.computeSourceTables()).willReturn(tables);
return tableAliases;
}
use of annis.model.QueryAnnotation in project ANNIS by korpling.
the class TestDefaultWhereClauseGenerator method whereClauseForNodeAnnotation.
// WHERE condition for node annotation
@Test
public void whereClauseForNodeAnnotation() {
node23.addNodeAnnotation(new QueryAnnotation("namespace1", "name1"));
node23.addNodeAnnotation(new QueryAnnotation("namespace2", "name2", "value2", TextMatching.EXACT_EQUAL));
node23.addNodeAnnotation(new QueryAnnotation("namespace3", "name3", "value3", TextMatching.REGEXP_EQUAL));
checkWhereConditions("_annotation23_1.qannotext LIKE 'namespace1:name1:%'", "_annotation23_2.qannotext LIKE 'namespace2:name2:value2'", "_annotation23_3.qannotext ~ '^(namespace3:name3:(value3))$'");
}
use of annis.model.QueryAnnotation in project ANNIS by korpling.
the class TestDefaultWhereClauseGenerator method whereClauseForNodeEdgeAnnotation.
// WHERE condition for node annotation
@Test
public void whereClauseForNodeEdgeAnnotation() {
Dominance j = new Dominance(node23);
j.addEdgeAnnotation(new QueryAnnotation("namespace1", "name1"));
j.addEdgeAnnotation(new QueryAnnotation("namespace2", "name2", "value2", TextMatching.EXACT_EQUAL));
j.addEdgeAnnotation(new QueryAnnotation("namespace3", "name3", "value3", TextMatching.REGEXP_EQUAL));
node42.addOutgoingJoin(j);
checkWhereConditions("_rank_annotation23_1.qannotext LIKE 'namespace1:name1:%'", "_rank_annotation23_2.qannotext LIKE 'namespace2:name2:value2'", "_rank_annotation23_3.qannotext ~ '^(namespace3:name3:(value3))$'");
}
use of annis.model.QueryAnnotation in project ANNIS by korpling.
the class SubQueryCorpusSelectionStrategy method buildSubQuery.
public String buildSubQuery(List<Long> corpusList, List<QueryAnnotation> metaData) {
StringBuffer sb = new StringBuffer();
sb.append("SELECT DISTINCT c1.id FROM corpus AS c1");
if (!corpusList.isEmpty()) {
sb.append(", ");
sb.append("corpus AS c2");
}
for (int i = 1; i <= metaData.size(); ++i) {
sb.append(", ");
sb.append("corpus_annotation AS corpus_annotation");
sb.append(i);
}
if (hasCorpusSelection(corpusList, metaData))
sb.append(" WHERE ");
List<String> conditions = new ArrayList<>();
if (!corpusList.isEmpty()) {
conditions.add("c1.pre >= c2.pre");
conditions.add("c1.post <= c2.post");
conditions.add("c2.id IN ( :corpusList )".replace(":corpusList", StringUtils.join(corpusList, ", ")));
}
for (int i = 1; i <= metaData.size(); ++i) {
QueryAnnotation annotation = metaData.get(i - 1);
if (annotation.getNamespace() != null)
conditions.add("corpus_annotation" + i + ".namespace = '" + annotation.getNamespace() + "'");
conditions.add("corpus_annotation" + i + ".name = '" + annotation.getName() + "'");
if (annotation.getValue() != null) {
String value = annotation.getValue();
if (annotation.getTextMatching() == QueryNode.TextMatching.REGEXP_EQUAL || annotation.getTextMatching() == QueryNode.TextMatching.REGEXP_NOT_EQUAL) {
value = "^" + value + "$";
}
conditions.add("corpus_annotation" + i + ".value " + annotation.getTextMatching().sqlOperator() + " '" + value + "'");
}
conditions.add("corpus_annotation" + i + ".corpus_ref = c1.id");
}
sb.append(StringUtils.join(conditions, " AND "));
return sb.toString();
}
use of annis.model.QueryAnnotation 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);
}
Aggregations