use of org.openrdf.query.algebra.ValueConstant in project incubator-rya by apache.
the class EventQueryNode2IT method extractArguments.
private Value[] extractArguments(final String matchName, final FunctionCall call) {
final Value[] args = new Value[call.getArgs().size() - 1];
int argI = 0;
for (int i = 0; i != call.getArgs().size(); ++i) {
final ValueExpr arg = call.getArgs().get(i);
if (argI == i && arg instanceof Var && matchName.equals(((Var) arg).getName())) {
continue;
}
if (arg instanceof ValueConstant) {
args[argI] = ((ValueConstant) arg).getValue();
} else if (arg instanceof Var && ((Var) arg).hasValue()) {
args[argI] = ((Var) arg).getValue();
} else {
throw new IllegalArgumentException("Query error: Found " + arg + ", expected a Literal, BNode or URI");
}
++argI;
}
return args;
}
use of org.openrdf.query.algebra.ValueConstant in project incubator-rya by apache.
the class ConstructConsequentVisitor method recordConsequent.
private void recordConsequent(ProjectionElemList variables, List<ExtensionElem> extensionElements) {
Map<String, Value> bindings = new ConcurrentHashMap<>();
Map<String, Value> values = new ConcurrentHashMap<>();
Set<String> queryBnodes = new HashSet<>();
Set<String> projectedBnodes = new HashSet<>();
for (ExtensionElem ee : extensionElements) {
if (ee.getExpr() instanceof ValueConstant) {
bindings.put(ee.getName(), ((ValueConstant) ee.getExpr()).getValue());
} else if (ee.getExpr() instanceof BNodeGenerator) {
queryBnodes.add(ee.getName());
}
}
for (ProjectionElem var : variables.getElements()) {
String sourceName = var.getSourceName();
String targetName = var.getTargetName();
Value constValue = bindings.get(sourceName);
if (constValue != null) {
values.put(targetName, constValue);
} else if (queryBnodes.contains(sourceName)) {
projectedBnodes.add(targetName);
}
}
Var subjVar = new Var(SUBJECT_VAR_NAME, values.get(SUBJECT_VAR_NAME));
Var predVar = new Var(PREDICATE_VAR_NAME, values.get(PREDICATE_VAR_NAME));
Var objVar = new Var(OBJECT_VAR_NAME, values.get(OBJECT_VAR_NAME));
subjVar.setAnonymous(projectedBnodes.contains(SUBJECT_VAR_NAME));
predVar.setAnonymous(projectedBnodes.contains(PREDICATE_VAR_NAME));
objVar.setAnonymous(projectedBnodes.contains(OBJECT_VAR_NAME));
StatementPattern sp = new StatementPattern(subjVar, predVar, objVar);
consequentStatementPatterns.add(sp);
}
use of org.openrdf.query.algebra.ValueConstant in project incubator-rya by apache.
the class GeoParseUtils method extractArguments.
/**
* Extracts the arguments used in a {@link FunctionCall}.
* @param matchName - The variable name to match to arguments used in the {@link FunctionCall}.
* @param call - The {@link FunctionCall} to match against.
* @return - The {@link Value}s matched.
*/
public static Object[] extractArguments(final String matchName, final FunctionCall call) {
final Object[] args = new Object[call.getArgs().size() - 1];
int argI = 0;
for (int i = 0; i != call.getArgs().size(); ++i) {
final ValueExpr arg = call.getArgs().get(i);
if (argI == i && arg instanceof Var && matchName.equals(((Var) arg).getName())) {
continue;
}
if (arg instanceof ValueConstant) {
args[argI] = ((ValueConstant) arg).getValue();
} else if (arg instanceof Var && ((Var) arg).hasValue()) {
args[argI] = ((Var) arg).getValue();
} else {
args[argI] = arg;
}
++argI;
}
return args;
}
use of org.openrdf.query.algebra.ValueConstant in project incubator-rya by apache.
the class ConstructConsequentVisitorTest method testConcreteSP.
@Test
public void testConcreteSP() {
Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new ValueConstant(FOAF.PERSON), "x"), new ExtensionElem(new ValueConstant(RDF.TYPE), "y"), new ExtensionElem(new ValueConstant(OWL.CLASS), "z"));
Projection projection = new Projection(extension, new ProjectionElemList(new ProjectionElem("x", "subject"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
projection.visit(visitor);
Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(FOAF.PERSON), p(RDF.TYPE), o(OWL.CLASS)));
Assert.assertEquals(expected, visitor.getConsequents());
}
use of org.openrdf.query.algebra.ValueConstant in project incubator-rya by apache.
the class ConstructConsequentVisitorTest method testMissingVariables.
@Test
public void testMissingVariables() {
Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new ValueConstant(FOAF.PERSON), "x"), new ExtensionElem(new ValueConstant(RDF.TYPE), "y"));
Projection projection = new Projection(extension, new ProjectionElemList(new ProjectionElem("x", "s"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
projection.visit(visitor);
Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(RDF.TYPE), o(null)));
Assert.assertEquals(expected, visitor.getConsequents());
}
Aggregations