use of org.eclipse.rdf4j.query.algebra.StatementPattern in project rdf4j by eclipse.
the class BaseTupleExprRenderer method toStatementPattern.
/**
* Turn a ProjectionElemList for a construct query projection (three elements aliased as 'subject',
* 'predicate' and 'object' in that order) into a StatementPattern.
*
* @param theList
* the elem list to render
* @return the elem list for a construct projection as a statement pattern
* @throws Exception
* if there is an exception while rendering
*/
public StatementPattern toStatementPattern(ProjectionElemList theList) throws Exception {
ProjectionElem aSubj = theList.getElements().get(0);
ProjectionElem aPred = theList.getElements().get(1);
ProjectionElem aObj = theList.getElements().get(2);
return new StatementPattern(mExtensions.containsKey(aSubj.getSourceName()) ? new Var(scrubVarName(aSubj.getSourceName()), asValue(mExtensions.get(aSubj.getSourceName()))) : new Var(scrubVarName(aSubj.getSourceName())), mExtensions.containsKey(aPred.getSourceName()) ? new Var(scrubVarName(aPred.getSourceName()), asValue(mExtensions.get(aPred.getSourceName()))) : new Var(scrubVarName(aPred.getSourceName())), mExtensions.containsKey(aObj.getSourceName()) ? new Var(scrubVarName(aObj.getSourceName()), asValue(mExtensions.get(aObj.getSourceName()))) : new Var(scrubVarName(aObj.getSourceName())));
}
use of org.eclipse.rdf4j.query.algebra.StatementPattern in project rdf4j by eclipse.
the class ConstructorBuilder method getConstructVars.
/**
* 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;
}
use of org.eclipse.rdf4j.query.algebra.StatementPattern in project rdf4j by eclipse.
the class AbstractQueryBuilder method multiProjection.
private UnaryTupleOperator multiProjection() {
MultiProjection aProjection = new MultiProjection();
Extension aExt = null;
for (StatementPattern aPattern : mProjectionPatterns) {
ProjectionElemList aList = new ProjectionElemList();
aList.addElement(new ProjectionElem(aPattern.getSubjectVar().getName(), "subject"));
aList.addElement(new ProjectionElem(aPattern.getPredicateVar().getName(), "predicate"));
aList.addElement(new ProjectionElem(aPattern.getObjectVar().getName(), "object"));
if (aPattern.getSubjectVar().hasValue()) {
if (aExt == null) {
aExt = new Extension();
}
aExt.addElements(new ExtensionElem(new ValueConstant(aPattern.getSubjectVar().getValue()), aPattern.getSubjectVar().getName()));
}
if (aPattern.getPredicateVar().hasValue()) {
if (aExt == null) {
aExt = new Extension();
}
aExt.addElements(new ExtensionElem(new ValueConstant(aPattern.getPredicateVar().getValue()), aPattern.getPredicateVar().getName()));
}
if (aPattern.getObjectVar().hasValue()) {
if (aExt == null) {
aExt = new Extension();
}
aExt.addElements(new ExtensionElem(new ValueConstant(aPattern.getObjectVar().getValue()), aPattern.getObjectVar().getName()));
}
aProjection.addProjection(aList);
}
if (aExt != null) {
aProjection.setArg(aExt);
}
return aProjection;
}
use of org.eclipse.rdf4j.query.algebra.StatementPattern in project rdf4j by eclipse.
the class GroupBuilder method atoms.
public GroupBuilder<T, E> atoms(Set<StatementPattern> thePatterns) {
for (StatementPattern aPattern : thePatterns) {
aPattern.setContextVar(mContext);
aPattern.setScope(mScope);
}
mGroup.addAll(thePatterns);
return this;
}
use of org.eclipse.rdf4j.query.algebra.StatementPattern in project rdf4j by eclipse.
the class TupleExprBuilder method createTupleExprForNegatedPropertySet.
private TupleExpr createTupleExprForNegatedPropertySet(NegatedPropertySet nps, int index) {
Var subjVar = nps.getSubjectVar();
Var predVar = createAnonVar();
ValueExpr filterCondition = null;
ValueExpr filterConditionInverse = null;
// build (inverted) filter conditions for each negated path element.
for (PropertySetElem elem : nps.getPropertySetElems()) {
ValueConstant predicate = elem.getPredicate();
if (elem.isInverse()) {
Compare compare = new Compare(predVar, predicate, CompareOp.NE);
if (filterConditionInverse == null) {
filterConditionInverse = compare;
} else {
filterConditionInverse = new And(compare, filterConditionInverse);
}
} else {
Compare compare = new Compare(predVar, predicate, CompareOp.NE);
if (filterCondition == null) {
filterCondition = compare;
} else {
filterCondition = new And(compare, filterCondition);
}
}
}
TupleExpr patternMatch = null;
// one item)
if (filterCondition != null) {
for (ValueExpr objVar : nps.getObjectList()) {
if (patternMatch == null) {
patternMatch = new StatementPattern(nps.getScope(), subjVar, predVar, (Var) objVar, nps.getContextVar());
} else {
patternMatch = new Join(new StatementPattern(nps.getScope(), subjVar, predVar, (Var) objVar, nps.getContextVar()), patternMatch);
}
}
}
TupleExpr patternMatchInverse = null;
// one item):
if (filterConditionInverse != null) {
for (ValueExpr objVar : nps.getObjectList()) {
if (patternMatchInverse == null) {
patternMatchInverse = new StatementPattern(nps.getScope(), (Var) objVar, predVar, subjVar, nps.getContextVar());
} else {
patternMatchInverse = new Join(new StatementPattern(nps.getScope(), (Var) objVar, predVar, subjVar, nps.getContextVar()), patternMatchInverse);
}
}
}
TupleExpr completeMatch = null;
if (patternMatch != null) {
completeMatch = new Filter(patternMatch, filterCondition);
}
if (patternMatchInverse != null) {
if (completeMatch == null) {
completeMatch = new Filter(patternMatchInverse, filterConditionInverse);
} else {
completeMatch = new Union(new Filter(patternMatchInverse, filterConditionInverse), completeMatch);
}
}
return completeMatch;
}
Aggregations