public StatementBindingSetCursor( Iteration<? extends Statement, ? extends QueryEvaluationException> iter, StatementPattern sp, BindingSet bindings) { super(iter); subjVar = sp.getSubjectVar(); predVar = sp.getPredicateVar(); objVar = sp.getObjectVar(); conVar = sp.getContextVar(); this.bindings = bindings; }
/** * @return SubjectPattern representation of this ConstructProjection * containing the {@link ConstructProjection#subjectSourceVar}, * {@link ConstructProjection#predicateSourceVar}, * {@link ConstructProjection#objectSourceVar} */ public StatementPattern getStatementPatternRepresentation() { return new StatementPattern(subjVar, predVar, objVar); }
@Override public void meet(StatementPattern sp) { sp.replaceWith(new AggregationPipelineQueryNode(inputCollection, sp)); }
public void meet(StatementPattern node) { subjects.add(node.getSubjectVar()); objects.add(node.getObjectVar()); } });
@Override public StatementPattern clone() { StatementPattern clone = (StatementPattern)super.clone(); clone.setSubjectVar(getSubjectVar().clone()); clone.setPredicateVar(getPredicateVar().clone()); clone.setObjectVar(getObjectVar().clone()); if (getContextVar() != null) { clone.setContextVar(getContextVar().clone()); } return clone; } }
String renderPattern(StatementPattern thePattern) throws Exception { return renderValueExpr(thePattern.getSubjectVar()) + " " + renderValueExpr(thePattern.getPredicateVar()) + " " + "" + renderValueExpr(thePattern.getObjectVar()) + ".\n"; } }
@Override public void meet(StatementPattern sp) { URI propertyName = (URI) sp.getPredicateVar().getValue(); if(propertyName != null && index.isGeoField(SearchFields.getPropertyField(propertyName)) && !sp.getObjectVar().hasValue()) { String objectVarName = sp.getObjectVar().getName(); DistanceQuerySpec spec = specs.remove(objectVarName); if(spec != null && isChildOf(sp, spec.getFilter())) { spec.setGeometryPattern(sp); results.add(spec); } } } });
@Override public void meet(StatementPattern node) throws RepositoryException { super.meet(node); IRI pred = (IRI)node.getPredicateVar().getValue(); if (pred != null && localSpace != null && localSpace.match(pred.stringValue())) { local(node.getSubjectVar()); } else { notLocal(); } }
/** * The variable name associated with the query score * * @return the name or null, if no score is queried in the pattern */ public String getScoreVariableName() { if (scorePattern != null) return scorePattern.getObjectVar().getName(); else return null; }
public Var getContextVar() { return geoStatement.getContextVar(); }
public void meet(StatementPattern node) { if (!Scope.DEFAULT_CONTEXTS.equals(node.getScope())) { basicPattern = false; } else if (node.getContextVar() != null) { basicPattern = false; } else { super.meet(node); } } }
private Var getTypeSubject(final Type type) { //we just need the first pattern since all the patterns in this type map are the same subject final StatementPattern pattern = typeMap.get(type).iterator().next(); return pattern.getSubjectVar(); }
/** * Override this if you are able to determine the cardinality based not * only on the predicateVar itself but also the other vars (e.g. the * subject value might determine a predicate subset). */ protected double getPredicateCardinality(StatementPattern sp) { return getPredicateCardinality(sp.getPredicateVar()); }
private CloseableIteration<BindingSet, QueryEvaluationException> createIteration() throws QueryEvaluationException { Var startVar = createAnonVar(ANON_SUBJECT_VAR); Var predicate = createAnonVar(ANON_PREDICATE_VAR); Var endVar = createAnonVar(ANON_OBJECT_VAR); StatementPattern subjects = new StatementPattern(startVar, predicate, endVar); if (contextVar != null) { subjects.setScope(Scope.NAMED_CONTEXTS); subjects.setContextVar(contextVar); } CloseableIteration<BindingSet, QueryEvaluationException> iter = evaluationStrategy.evaluate( subjects, bindings); return iter; }
/** * Transform a statement pattern to infer triples for a predicate variable. * * @param node the node to transform * @return list of nodes to visit next */ @Override public List<QueryModelNode> apply(StatementPattern node) { List<QueryModelNode> next = newNextList(); StatementPattern left = node.clone(); next.add(left); TupleExpr right = assignPredicates(predicates, node.clone(), next); node.replaceWith(new Union(left, right)); return next; }
private void removeMatchedPattern(final TupleExpr tupleExpr, final StatementPattern pattern, final TupleExprReplacer replacer) { final List<TupleExpr> indexTuples = replacer.createReplacement(pattern); if (indexTuples.size() > 1) { final VarExchangeVisitor vev = new VarExchangeVisitor(pattern); tupleExpr.visit(vev); Join join = new Join(indexTuples.remove(0), indexTuples.remove(0)); for (final TupleExpr geo : indexTuples) { join = new Join(join, geo); } pattern.replaceWith(join); } else if (indexTuples.size() == 1) { pattern.replaceWith(indexTuples.get(0)); pattern.setParentNode(null); } else { throw new IllegalStateException("Must have at least one replacement for matched StatementPattern."); } }
private Set<URI> getGraphs(StatementPattern sp) { if (dataset == null) return null; if (dataset.getDefaultGraphs().isEmpty() && dataset.getNamedGraphs().isEmpty()) return null; if (sp.getScope() == Scope.DEFAULT_CONTEXTS) return dataset.getDefaultGraphs(); return dataset.getNamedGraphs(); }
public void setGeometryPattern(StatementPattern sp) { if(sp.getSubjectVar().hasValue()) { throw new IllegalArgumentException("Subject cannot be bound: "+sp); } if(!sp.getPredicateVar().hasValue()) { throw new IllegalArgumentException("Predicate must be bound: "+sp); } if(sp.getObjectVar().hasValue()) { throw new IllegalArgumentException("Object cannot be bound: "+sp); } this.geoStatement = sp; }
private boolean isInversePath(final StatementPattern node, final Var start, final Var end) { if (node.getSubjectVar().equals(start)) { Preconditions.checkArgument(node.getObjectVar().equals(end)); return false; } else if (node.getObjectVar().equals(start)) { Preconditions.checkArgument(node.getSubjectVar().equals(end)); return true; } else { fail("Unsupported path expression. Check node: ", node); return false; } }
@Override public void meet(StatementPattern sp) { URI propertyName = (URI) sp.getPredicateVar().getValue(); if(propertyName != null && index.isGeoField(SearchFields.getPropertyField(propertyName)) && !sp.getObjectVar().hasValue()) { String objectVarName = sp.getObjectVar().getName(); GeoRelationQuerySpec spec = specs.remove(objectVarName); if(spec != null && isChildOf(sp, spec.getFilter())) { spec.setGeometryPattern(sp); results.add(spec); } } } });