use of annis.sqlgen.model.RankTableJoin in project ANNIS by korpling.
the class DefaultWhereClauseGenerator method addSingleRelationCondition.
@Override
protected void addSingleRelationCondition(QueryNode node, QueryNode target, List<String> conditions, Join join, final String relationType) {
RankTableJoin rankTableJoin = (RankTableJoin) join;
String componentName = rankTableJoin.getName();
int min = rankTableJoin.getMinDistance();
int max = rankTableJoin.getMaxDistance();
// direct
if (min == 1 && max == 1) {
addComponentPredicates(conditions, node, target, componentName, relationType, false);
conditions.add(join("=", tables(node).aliasedColumn(RANK_TABLE, "id"), tables(target).aliasedColumn(RANK_TABLE, "parent")));
// indirect"
} else {
addComponentPredicates(conditions, node, target, componentName, relationType, true);
conditions.add(join("<", tables(node).aliasedColumn(RANK_TABLE, "pre"), tables(target).aliasedColumn(RANK_TABLE, "pre")));
conditions.add(join("<", tables(target).aliasedColumn(RANK_TABLE, "pre"), tables(node).aliasedColumn(RANK_TABLE, "post")));
// exact
if (min > 0 && min == max) {
conditions.add(numberJoin("=", tables(node).aliasedColumn(RANK_TABLE, "level"), tables(target).aliasedColumn(RANK_TABLE, "level"), -min));
// range
} else if (min > 0 && min < max) {
conditions.add(between(tables(node).aliasedColumn(RANK_TABLE, "level"), tables(target).aliasedColumn(RANK_TABLE, "level"), -min, -max));
}
}
}
use of annis.sqlgen.model.RankTableJoin in project ANNIS by korpling.
the class DefaultWhereClauseGenerator method addLeftOrRightDominance.
// FIXME: why not in addSingleRelationConditions() ?
protected void addLeftOrRightDominance(List<String> conditions, QueryNode node, QueryNode target, QueryData queryData, RankTableJoin join, String aggregationFunction, String tokenBoarder) {
RankTableJoin rankTableJoin = (RankTableJoin) join;
String componentName = rankTableJoin.getName();
// the parent and rank_id are already unique, so don't add extra join on component_id
addComponentPredicates(conditions, node, target, componentName, "d", false);
conditions.add(join("=", tables(node).aliasedColumn(RANK_TABLE, "id"), tables(target).aliasedColumn(RANK_TABLE, "parent")));
List<Long> corpusList = queryData.getCorpusList();
String innerSelect = "SELECT " + aggregationFunction + "(lrsub." + tokenBoarder + ") FROM ";
innerSelect += SelectedFactsFromClauseGenerator.inheritedFactTables(corpusList, "") + " AS lrsub ";
innerSelect += "WHERE parent=" + tables(node).aliasedColumn(RANK_TABLE, "id") + " AND component_id = " + tables(node).aliasedColumn(RANK_TABLE, "component_id") + " AND corpus_ref=" + tables(target).aliasedColumn(NODE_TABLE, "corpus_ref") + " AND lrsub.toplevel_corpus IN(" + (corpusList == null || corpusList.isEmpty() ? "NULL" : StringUtils.join(corpusList, ",")) + ")";
conditions.add(in(tables(target).aliasedColumn(NODE_TABLE, tokenBoarder), innerSelect));
}
use of annis.sqlgen.model.RankTableJoin in project ANNIS by korpling.
the class SubcorpusConstraintWhereClause method commonWhereConditions.
// VR: inline
@Deprecated
public List<String> commonWhereConditions(List<QueryNode> nodes, List<Long> corpusList, List<Long> documents) {
LinkedList<String> conditions = new LinkedList<>();
// annotations can always only be inside a subcorpus/document
QueryNode[] copyNodes = nodes.toArray(new QueryNode[nodes.size()]);
for (int left = 0; left < copyNodes.length; left++) {
for (int right = 0; right < copyNodes.length; right++) {
if (left != right) {
// only add constraint if the two nodes are not already connected by their component or node id
boolean needsCorpusRef = false;
for (Join j : copyNodes[left].getOutgoingJoins()) {
if (j.getTarget() != null && j.getTarget().getId() == copyNodes[right].getId()) {
if ((j instanceof RankTableJoin || j instanceof Identical)) {
// we definitly don't have to apply this join
needsCorpusRef = false;
break;
} else {
// there is at least one actual join between this nodes, assume we
// need a corpus_ref join for now
needsCorpusRef = true;
}
}
}
if (needsCorpusRef) {
conditions.add(join("=", tables(copyNodes[left]).aliasedColumn(NODE_TABLE, "corpus_ref"), tables(copyNodes[right]).aliasedColumn(NODE_TABLE, "corpus_ref")));
}
}
// end if left != right
}
// end right loop
}
return conditions;
}
use of annis.sqlgen.model.RankTableJoin in project ANNIS by korpling.
the class TestQueryNode method addRelationRankTable.
@Test
public void addRelationRankTable() {
// sanity check
assertThat(node.isPartOfEdge(), is(false));
// add a join that uses the rank table
QueryNode target = new QueryNode(1);
RankTableJoin rankTableJoin = new RankTableJoin(target, "foo", 0, 0) {
};
node.addOutgoingJoin(rankTableJoin);
// assert both node and target know about the edge
assertThat(node.isPartOfEdge(), is(true));
assertThat(target.isPartOfEdge(), is(true));
}
Aggregations