Search in sources :

Example 6 with ValueConstant

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;
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) Value(org.openrdf.model.Value)

Example 7 with ValueConstant

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);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) BNodeGenerator(org.openrdf.query.algebra.BNodeGenerator) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) Value(org.openrdf.model.Value) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) HashSet(java.util.HashSet)

Example 8 with ValueConstant

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;
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant)

Example 9 with ValueConstant

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());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) SingletonSet(org.openrdf.query.algebra.SingletonSet) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 10 with ValueConstant

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());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) SingletonSet(org.openrdf.query.algebra.SingletonSet) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Aggregations

ValueConstant (org.openrdf.query.algebra.ValueConstant)17 Var (org.openrdf.query.algebra.Var)14 Test (org.junit.Test)9 ExtensionElem (org.openrdf.query.algebra.ExtensionElem)8 ValueExpr (org.openrdf.query.algebra.ValueExpr)8 StatementPattern (org.openrdf.query.algebra.StatementPattern)6 Value (org.openrdf.model.Value)5 Extension (org.openrdf.query.algebra.Extension)5 FunctionCall (org.openrdf.query.algebra.FunctionCall)4 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)4 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)4 Join (org.openrdf.query.algebra.Join)3 MultiProjection (org.openrdf.query.algebra.MultiProjection)3 SingletonSet (org.openrdf.query.algebra.SingletonSet)3 HashSet (java.util.HashSet)2 Literal (org.openrdf.model.Literal)2 Not (org.openrdf.query.algebra.Not)2 Projection (org.openrdf.query.algebra.Projection)2 QueryRoot (org.openrdf.query.algebra.QueryRoot)2 BasicDBObject (com.mongodb.BasicDBObject)1