Search in sources :

Example 1 with Substitute

use of org.apache.jena.sparql.core.Substitute in project jena by apache.

the class SolverRX4 method match.

// RDF term matcher - may recurse and call matchTriple is a triple term is in the pattern.
private static boolean match(BindingBuilder bb, Node nData, Node nPattern) {
    if (nPattern == null)
        return true;
    if (nData == Node.ANY)
        return true;
    // Deep substitute. This happens anyway as we walk structures.
    // nPattern = Substitute.substitute(nPattern, input);
    // Shallow substitute
    nPattern = Var.lookup(v -> bb.get(v), nPattern);
    // nPattern.isConcrete() : either nPattern is an RDF term or is <<>> with no variables.
    if (nPattern.isConcrete()) {
        // Term comparison.
        return sameTermAs(nData, nPattern);
    }
    // Easy case - nPattern is a variable.
    if (Var.isVar(nPattern)) {
        Var var = Var.alloc(nPattern);
        bb.add(var, nData);
        return true;
    }
    // nPattern is <<>> with variables. Is the data a <<>>?
    if (!nData.isNodeTriple())
        return false;
    // nData is <<>>, nPattern is <<>>
    // Unpack, match components.
    Triple tPattern = nPattern.getTriple();
    Triple tData = nData.getTriple();
    return SolverRX3.bindTriple(bb, tData, tPattern);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Iterator(java.util.Iterator) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Predicate(java.util.function.Predicate) SolverLib.nodeTopLevel(org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel) Triple(org.apache.jena.graph.Triple) SolverLib.tripleHasEmbTripleWithVars(org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Graph(org.apache.jena.graph.Graph) SolverLib.sameTermAs(org.apache.jena.sparql.engine.main.solver.SolverLib.sameTermAs) Substitute(org.apache.jena.sparql.core.Substitute) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) Quad(org.apache.jena.sparql.core.Quad) Iter(org.apache.jena.atlas.iterator.Iter) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Triple(org.apache.jena.graph.Triple) Var(org.apache.jena.sparql.core.Var)

Example 2 with Substitute

use of org.apache.jena.sparql.core.Substitute in project jena by apache.

the class SolverRX3 method match.

// RDF term matcher - may recurse and call matchTriple is a triple term is in the pattern.
private static boolean match(BindingBuilder bb, Node nData, Node nPattern) {
    if (nPattern == null)
        return true;
    if (nData == Node.ANY)
        return true;
    // Deep substitute. This happens anyway as we walk structures.
    // nPattern = Substitute.substitute(nPattern, input);
    // Shallow substitute
    nPattern = Var.lookup(v -> bb.get(v), nPattern);
    // nPattern.isConcrete() : either nPattern is an RDF term or is <<>> with no variables.
    if (nPattern.isConcrete()) {
        // Term comparison.
        return sameTermAs(nData, nPattern);
    }
    // Easy case - nPattern is a variable.
    if (Var.isVar(nPattern)) {
        Var var = Var.alloc(nPattern);
        bb.add(var, nData);
        return true;
    }
    // nPattern is <<>> with variables. Is the data a <<>>?
    if (!nData.isNodeTriple())
        return false;
    // nData is <<>>, nPattern is <<>>
    // Unpack, match components.
    Triple tPattern = nPattern.getTriple();
    Triple tData = nData.getTriple();
    return bindTriple(bb, tData, tPattern);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Iterator(java.util.Iterator) SolverLib.nodeTopLevel(org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel) Triple(org.apache.jena.graph.Triple) SolverLib.tripleHasEmbTripleWithVars(org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Graph(org.apache.jena.graph.Graph) Objects(java.util.Objects) SolverLib.sameTermAs(org.apache.jena.sparql.engine.main.solver.SolverLib.sameTermAs) Substitute(org.apache.jena.sparql.core.Substitute) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) ExtendedIterator(org.apache.jena.util.iterator.ExtendedIterator) Iter(org.apache.jena.atlas.iterator.Iter) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Triple(org.apache.jena.graph.Triple) Var(org.apache.jena.sparql.core.Var)

Aggregations

Iterator (java.util.Iterator)2 Iter (org.apache.jena.atlas.iterator.Iter)2 Graph (org.apache.jena.graph.Graph)2 Node (org.apache.jena.graph.Node)2 Triple (org.apache.jena.graph.Triple)2 Substitute (org.apache.jena.sparql.core.Substitute)2 Var (org.apache.jena.sparql.core.Var)2 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2 BindingBuilder (org.apache.jena.sparql.engine.binding.BindingBuilder)2 SolverLib.nodeTopLevel (org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel)2 SolverLib.sameTermAs (org.apache.jena.sparql.engine.main.solver.SolverLib.sameTermAs)2 SolverLib.tripleHasEmbTripleWithVars (org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars)2 Objects (java.util.Objects)1 Predicate (java.util.function.Predicate)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 Quad (org.apache.jena.sparql.core.Quad)1 ExtendedIterator (org.apache.jena.util.iterator.ExtendedIterator)1