private Set<Var> getProjectionVars(Collection<StatementPattern> statementPatterns) { Set<Var> vars = new LinkedHashSet<>(statementPatterns.size() * 2); for (StatementPattern sp : statementPatterns) { vars.add(sp.getSubjectVar()); vars.add(sp.getPredicateVar()); vars.add(sp.getObjectVar()); if (sp.getContextVar() != null) { vars.add(sp.getContextVar()); } } return vars; } }
/** * @return SubjectPattern representation of this ConstructProjection * containing the {@link ConstructProjection#getSubjectSourceName}, * {@link ConstructProjection#getPredicateSourceName}, * {@link ConstructProjection#getObjectSourceName} */ public StatementPattern getStatementPatternRepresentation() { return new StatementPattern(subjVar, predVar, objVar); }
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); } } }
/** * Creates a statement pattern that matches a subject-, predicate-, object- and context variable against * statements from the specified context scope. */ public StatementPattern(Scope scope, Var subjVar, Var predVar, Var objVar, Var conVar) { setScope(scope); setSubjectVar(subjVar); setPredicateVar(predVar); setObjectVar(objVar); setContextVar(conVar); }
/** * Gets the set of variables that are relevant for the constructor. This method accumulates all subject, * predicate and object variables from the supplied statement patterns, but ignores any context variables. */ private Set<Var> getConstructVars(Collection<StatementPattern> statementPatterns) { Set<Var> vars = new LinkedHashSet<Var>(statementPatterns.size() * 2); for (StatementPattern sp : statementPatterns) { vars.add(sp.getSubjectVar()); vars.add(sp.getPredicateVar()); vars.add(sp.getObjectVar()); } return vars; }
@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; } }
@Override protected void meetSP(final StatementPattern node) throws Exception { final StatementPattern sp = node.clone(); final Var predVar = sp.getPredicateVar(); final IRI pred = (IRI) predVar.getValue(); final String predNamespace = pred.getNamespace(); final Var objVar = sp.getObjectVar(); final Var cntxtVar = sp.getContextVar(); if (objVar != null && !RDF.NAMESPACE.equals(predNamespace) && !SESAME.NAMESPACE.equals(predNamespace) && !RDFS.NAMESPACE.equals(predNamespace) && !EXPANDED.equals(cntxtVar)) { final IRI transPropIri = (IRI) predVar.getValue(); if (inferenceEngine.isTransitiveProperty(transPropIri)) { node.replaceWith(new TransitivePropertySP(sp.getSubjectVar(), sp.getPredicateVar(), sp.getObjectVar(), sp.getContextVar())); } } } }
StatementPattern sp = new StatementPattern(); Map<RyaIRI, Var> properties = new HashMap<>(); final RyaIRI predicate = new RyaIRI(pattern.getPredicateVar().getValue().toString()); Var objVar = pattern.getObjectVar(); properties.put(predicate, objVar); continue; sp.setContextVar(pattern.getContextVar()); sp.setSubjectVar(pattern.getObjectVar()); sp.setPredicateVar(pattern.getObjectVar()); sp.setObjectVar(pattern.getObjectVar());
/** * Validate that this is a non-trivial rule. A trivial rule consists of * a statement pattern whose subject, predicate, and object are all * variables (therefore it would match every statement). * @return true if the rule is valid (non-trivial) */ void validate() throws QueryRulesetException { if (!(statement.getSubjectVar().isConstant() || statement.getPredicateVar().isConstant() || statement.getObjectVar().isConstant())) { throw new QueryRulesetException("Statement pattern with no constants would match every statement:\n" + statement.toString()); } }
@Override public void meet(StatementPattern node) throws QueryRulesetException { final Var predVar = node.getPredicateVar(); // If this is a transitive property node, just match all statements with that property if (node instanceof TransitivePropertySP && predVar.hasValue()) { node = new StatementPattern(new Var("transitiveSubject"), predVar, new Var("transitiveObject"), node.getContextVar()); // And make sure to grab the transitivity statement itself transitive.add(predVar.getValue()); } rules.add(new CopyRule(node)); }
private void updateVarMap(HashMultimap<String, StatementPattern> varMap, Set<StatementPattern> bin) { for (StatementPattern sp : bin) { varMap.remove(sp.getSubjectVar().getName(), sp); varMap.remove(sp.getObjectVar().getName(), sp); } removeInvalidBins(varMap, false); }
public Var getContextVar() { return geoStatement.getContextVar(); }
/** * 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()); }
/** * Override this if you are able to determine the cardinality based not only on the objectVar itself * but also the other vars (e.g. the predicate value might determine an object subset). */ protected double getObjectCardinality(StatementPattern sp) { return getObjectCardinality(sp.getObjectVar()); }
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(); }
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; }
public GroupBuilder<T, E> atoms(Set<StatementPattern> thePatterns) { for (StatementPattern aPattern : thePatterns) { aPattern.setContextVar(mContext); aPattern.setScope(mScope); } mGroup.addAll(thePatterns); return this; }
public GroupBuilder<T, E> setContext(Value theContextValue) { mContext = valueToVar(theContextValue); for (StatementPattern aPattern : mGroup.getPatterns()) { aPattern.setContextVar(mContext); } return this; }
/** * Gets the set of variables that are relevant for the constructor. This method accumulates all subject, * predicate and object variables from the supplied statement patterns, but ignores any context variables. */ private Set<Var> getConstructVars(Collection<StatementPattern> statementPatterns) { Set<Var> vars = new LinkedHashSet<Var>(statementPatterns.size() * 2); for (StatementPattern sp : statementPatterns) { vars.add(sp.getSubjectVar()); vars.add(sp.getPredicateVar()); vars.add(sp.getObjectVar()); } return vars; }
@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; } }