use of org.eclipse.rdf4j.query.algebra.ValueConstant in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public ValueConstant visit(ASTRDFLiteral node, Object data) throws VisitorException {
String label = (String) node.getLabel().jjtAccept(this, null);
String lang = node.getLang();
ASTIRI datatypeNode = node.getDatatype();
Literal literal;
if (datatypeNode != null) {
IRI datatype;
try {
datatype = valueFactory.createIRI(datatypeNode.getValue());
} catch (IllegalArgumentException e) {
// invalid URI
throw new VisitorException(e.getMessage());
}
literal = valueFactory.createLiteral(label, datatype);
} else if (lang != null) {
literal = valueFactory.createLiteral(label, lang);
} else {
literal = valueFactory.createLiteral(label);
}
return new ValueConstant(literal);
}
use of org.eclipse.rdf4j.query.algebra.ValueConstant in project rdf4j by eclipse.
the class FilterBuilder method regex.
public GroupBuilder<T, E> regex(ValueExpr theExpr, String thePattern, String theFlags) {
Regex aRegex = new Regex();
aRegex.setArg(theExpr);
aRegex.setPatternArg(new ValueConstant(SimpleValueFactory.getInstance().createLiteral(thePattern)));
if (theFlags != null) {
aRegex.setFlagsArg(new ValueConstant(SimpleValueFactory.getInstance().createLiteral(theFlags)));
}
return filter(aRegex);
}
use of org.eclipse.rdf4j.query.algebra.ValueConstant 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.ValueConstant in project rdf4j by eclipse.
the class GroupBuilder method filter.
public GroupBuilder<T, E> filter(String theVar, Compare.CompareOp theOp, Value theValue) {
Compare aComp = new Compare(new Var(theVar), new ValueConstant(theValue), theOp);
mGroup.addFilter(aComp);
return this;
}
use of org.eclipse.rdf4j.query.algebra.ValueConstant 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