use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class EntityIndexSetProvider method getExternalSets.
@Override
public List<EntityQueryNode> getExternalSets(final QuerySegment<EntityQueryNode> node) {
typeMap = HashMultimap.create();
subjectTypeMap = new HashMap<>();
// discover entities
final List<StatementPattern> unused = new ArrayList<>();
for (final QueryModelNode pattern : node.getOrderedNodes()) {
if (pattern instanceof StatementPattern) {
discoverEntities((StatementPattern) pattern, unused);
}
}
final List<EntityQueryNode> nodes = new ArrayList<>();
for (final Type type : typeMap.keySet()) {
// replace all nodes in the tupleExpr of the collection of statement patterns with this node.
final EntityQueryNode entity = new EntityQueryNode(type, typeMap.get(type), entityStorage);
nodes.add(entity);
}
return nodes;
}
use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class TupleExecutionPlanGenerator method getPlans.
private List<TupleExpr> getPlans(final TupleExpr te) {
final NodeCollector nc = new NodeCollector();
te.visit(nc);
final Set<QueryModelNode> nodeSet = nc.getNodeSet();
final List<Filter> filterList = nc.getFilterSet();
final Projection projection = nc.getProjection().clone();
final List<TupleExpr> queryPlans = Lists.newArrayList();
final Collection<List<QueryModelNode>> plans = Collections2.permutations(nodeSet);
for (final List<QueryModelNode> p : plans) {
if (p.size() == 0) {
throw new IllegalArgumentException("Tuple must contain at least one node!");
} else if (p.size() == 1) {
queryPlans.add(te);
} else {
queryPlans.add(buildTuple(p, filterList, projection));
}
}
return queryPlans;
}
use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class AbstractExternalSetMatcher method updateTupleAndNodes.
protected void updateTupleAndNodes() {
segmentNodeList = segment.getOrderedNodes();
final TupleExprAndNodes tupAndNodes = segment.getQuery();
tuple = tupAndNodes.getTupleExpr();
filters = tupAndNodes.getFilters();
unmatched = new HashSet<>();
final List<QueryModelNode> nodes = tupAndNodes.getNodes();
for (final QueryModelNode q : nodes) {
if (q instanceof UnaryTupleOperator || q instanceof BinaryTupleOperator) {
unmatched.add((TupleExpr) q);
} else if (q instanceof FlattenedOptional) {
final FlattenedOptional opt = (FlattenedOptional) q;
final TupleExpr rightArg = opt.getRightArg();
if (rightArg instanceof UnaryTupleOperator || rightArg instanceof BinaryTupleOperator) {
unmatched.add(rightArg);
}
}
}
}
use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class BasicRater method getConnectedComponentRating.
private double getConnectedComponentRating(List<QueryModelNode> eNodes) {
Multimap<String, Integer> commonVarBin = HashMultimap.create();
// bin QueryModelNode positions according to variable names
for (int i = 0; i < eNodes.size(); i++) {
QueryModelNode node = eNodes.get(i);
if (node instanceof TupleExpr) {
TupleExpr tup = (TupleExpr) node;
Set<String> bindingNames = tup.getAssuredBindingNames();
for (String name : bindingNames) {
if (!name.startsWith("-const-")) {
commonVarBin.put(name, i);
}
}
}
}
Set<List<Integer>> pairs = new HashSet<>();
for (String var : commonVarBin.keySet()) {
Set<Integer> pos = Sets.newHashSet(commonVarBin.get(var));
pairs.addAll(Sets.cartesianProduct(pos, pos));
}
int numComponents = countComponents(eNodes.size(), pairs);
return ((double) numComponents) / eNodes.size();
}
use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class OptionalJoinSegment method clone.
@Override
public OptionalJoinSegment<T> clone() {
List<QueryModelNode> order = new ArrayList<>();
for (QueryModelNode node : orderedNodes) {
order.add(node.clone());
}
Set<QueryModelNode> unorder = Sets.newHashSet(order);
Map<ValueExpr, Filter> map = new HashMap<>();
for (ValueExpr expr : conditionMap.keySet()) {
map.put(expr.clone(), conditionMap.get(expr).clone());
}
return new OptionalJoinSegment<T>(unorder, order, map);
}
Aggregations