use of org.eclipse.rdf4j.query.algebra.ValueConstant in project rdf4j by eclipse.
the class QueryModelBuilder method visit.
@Override
public ValueConstant visit(ASTLiteral litNode, Object data) throws VisitorException {
IRI datatype = null;
// Get datatype URI from child URI node, if present
ASTValueExpr dtNode = litNode.getDatatypeNode();
if (dtNode instanceof ASTURI) {
datatype = valueFactory.createIRI(((ASTURI) dtNode).getValue());
} else if (dtNode != null) {
throw new IllegalArgumentException("Unexpected datatype type: " + dtNode.getClass());
}
Literal literal;
if (datatype != null) {
literal = valueFactory.createLiteral(litNode.getLabel(), datatype);
} else if (litNode.hasLang()) {
literal = valueFactory.createLiteral(litNode.getLabel(), litNode.getLang());
} else {
literal = valueFactory.createLiteral(litNode.getLabel());
}
return new ValueConstant(literal);
}
use of org.eclipse.rdf4j.query.algebra.ValueConstant in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public ValueExpr visit(ASTNotIn node, Object data) throws VisitorException {
ValueExpr result = null;
ValueExpr leftArg = (ValueExpr) data;
int listItemCount = node.jjtGetNumChildren();
if (listItemCount == 0) {
result = new ValueConstant(BooleanLiteral.TRUE);
} else if (listItemCount == 1) {
ValueExpr arg = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, null);
result = new Compare(leftArg, arg, CompareOp.NE);
} else {
// create a set of conjunctive comparisons to represent the NOT IN
// operator: X NOT IN (a, b, c) -> X != a && X != b && X != c.
And and = new And();
And currentAnd = and;
for (int i = 0; i < listItemCount - 1; i++) {
ValueExpr arg = (ValueExpr) node.jjtGetChild(i).jjtAccept(this, null);
currentAnd.setLeftArg(new Compare(leftArg, arg, CompareOp.NE));
if (i == listItemCount - 2) {
// second-to-last item
arg = (ValueExpr) node.jjtGetChild(i + 1).jjtAccept(this, null);
currentAnd.setRightArg(new Compare(leftArg, arg, CompareOp.NE));
} else {
And newAnd = new And();
currentAnd.setRightArg(newAnd);
currentAnd = newAnd;
}
}
result = and;
}
return result;
}
use of org.eclipse.rdf4j.query.algebra.ValueConstant in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public TupleExpr visit(ASTConstruct node, Object data) throws VisitorException {
TupleExpr result = (TupleExpr) data;
// Collect construct triples
graphPattern = new GraphPattern();
super.visit(node, null);
TupleExpr constructExpr = graphPattern.buildTupleExpr();
// Retrieve all StatementPatterns from the construct expression
List<StatementPattern> statementPatterns = StatementPatternCollector.process(constructExpr);
if (constructExpr instanceof Filter) {
// sameTerm filters in construct (this can happen when there's a
// cyclic
// path defined, see SES-1685 and SES-2104)
// we remove the sameTerm filters by simply replacing all mapped
// variable occurrences
Set<SameTerm> sameTermConstraints = getSameTermConstraints((Filter) constructExpr);
statementPatterns = replaceSameTermVars(statementPatterns, sameTermConstraints);
}
Set<Var> constructVars = getConstructVars(statementPatterns);
VarCollector whereClauseVarCollector = new VarCollector();
result.visit(whereClauseVarCollector);
// Create BNodeGenerators for all anonymous variables
// NB: preserve order for a deterministic output
Map<Var, ExtensionElem> extElemMap = new LinkedHashMap<Var, ExtensionElem>();
for (Var var : constructVars) {
if (var.isAnonymous() && !extElemMap.containsKey(var)) {
ValueExpr valueExpr;
if (var.hasValue()) {
valueExpr = new ValueConstant(var.getValue());
} else {
valueExpr = new BNodeGenerator();
}
extElemMap.put(var, new ExtensionElem(valueExpr, var.getName()));
} else if (!whereClauseVarCollector.collectedVars.contains(var)) {
// non-anon var in construct clause not present in where clause
if (!extElemMap.containsKey(var)) {
// assign non-anonymous vars not present in where clause as
// extension elements. This is necessary to make external
// binding
// assingnment possible (see SES-996)
extElemMap.put(var, new ExtensionElem(var, var.getName()));
}
}
}
if (!extElemMap.isEmpty()) {
result = new Extension(result, extElemMap.values());
}
// Create a Projection for each StatementPattern in the constructor
List<ProjectionElemList> projList = new ArrayList<ProjectionElemList>();
for (StatementPattern sp : statementPatterns) {
ProjectionElemList projElemList = new ProjectionElemList();
projElemList.addElement(new ProjectionElem(sp.getSubjectVar().getName(), "subject"));
projElemList.addElement(new ProjectionElem(sp.getPredicateVar().getName(), "predicate"));
projElemList.addElement(new ProjectionElem(sp.getObjectVar().getName(), "object"));
if (sp.getContextVar() != null) {
projElemList.addElement(new ProjectionElem(sp.getContextVar().getName(), "context"));
}
projList.add(projElemList);
}
if (projList.size() == 1) {
result = new Projection(result, projList.get(0));
} else if (projList.size() > 1) {
result = new MultiProjection(result, projList);
} else {
// Empty constructor
result = new EmptySet();
}
return new Reduced(result);
}
use of org.eclipse.rdf4j.query.algebra.ValueConstant in project rdf4j by eclipse.
the class UpdateExprBuilder method visit.
@Override
public Copy visit(ASTCopy node, Object data) throws VisitorException {
Copy copy = new Copy();
copy.setSilent(node.isSilent());
ASTGraphOrDefault sourceNode = (ASTGraphOrDefault) node.jjtGetChild(0);
if (sourceNode.jjtGetNumChildren() > 0) {
ValueConstant sourceGraph = (ValueConstant) sourceNode.jjtGetChild(0).jjtAccept(this, data);
copy.setSourceGraph(sourceGraph);
}
ASTGraphOrDefault destinationNode = (ASTGraphOrDefault) node.jjtGetChild(1);
if (destinationNode.jjtGetNumChildren() > 0) {
ValueConstant destinationGraph = (ValueConstant) destinationNode.jjtGetChild(0).jjtAccept(this, data);
copy.setDestinationGraph(destinationGraph);
}
return copy;
}
use of org.eclipse.rdf4j.query.algebra.ValueConstant in project rdf4j by eclipse.
the class UpdateExprBuilder method visit.
@Override
public Create visit(ASTCreate node, Object data) throws VisitorException {
ValueConstant graph = (ValueConstant) node.jjtGetChild(0).jjtAccept(this, data);
Create create = new Create(graph);
create.setSilent(node.isSilent());
return create;
}
Aggregations