Search in sources :

Example 6 with ExtendedIterator

use of org.apache.jena.util.iterator.ExtendedIterator in project jena by apache.

the class ShapesParser method accTarget.

private static void accTarget(Collection<Target> acc, Graph shapesGraph, Node shape, TargetType targetType) {
    ExtendedIterator<Triple> iter = shapesGraph.find(shape, targetType.predicate, null);
    Graph graph;
    switch(targetType) {
        // Java 14 has "->"
        case targetExtension:
            graph = shapesGraph;
            break;
        // These do not need access to the shapes graph so don't force holding on the the graph reference.
        case implicitClass:
        case targetClass:
        case targetNode:
        case targetObjectsOf:
        case targetSubjectsOf:
        default:
            graph = null;
            break;
    }
    try {
        iter.mapWith(triple -> Target.create(triple.getSubject(), targetType, triple.getObject(), graph)).forEachRemaining(target -> acc.add(target));
    } finally {
        iter.close();
    }
}
Also used : Triple(org.apache.jena.graph.Triple) java.util(java.util) Imports(org.apache.jena.shacl.Imports) JLogConstraint(org.apache.jena.shacl.engine.constraint.JLogConstraint) G(org.apache.jena.riot.other.G) Graph(org.apache.jena.graph.Graph) ShLib(org.apache.jena.shacl.lib.ShLib) RDFDataException(org.apache.jena.riot.other.RDFDataException) Severity(org.apache.jena.shacl.validation.Severity) Path(org.apache.jena.sparql.path.Path) ShLib.displayStr(org.apache.jena.shacl.lib.ShLib.displayStr) SHACL(org.apache.jena.shacl.vocabulary.SHACL) C.rdfsClass(org.apache.jena.shacl.sys.C.rdfsClass) Triple(org.apache.jena.graph.Triple) ShaclSystem(org.apache.jena.shacl.sys.ShaclSystem) Collectors(java.util.stream.Collectors) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) ShaclPaths(org.apache.jena.shacl.engine.ShaclPaths) NodeConst(org.apache.jena.sparql.graph.NodeConst) Node(org.apache.jena.graph.Node) ShaclPaths.pathToString(org.apache.jena.shacl.engine.ShaclPaths.pathToString) XSDDatatype(org.apache.jena.datatypes.xsd.XSDDatatype) Target(org.apache.jena.shacl.engine.Target) Targets(org.apache.jena.shacl.engine.Targets) Pair(org.apache.jena.atlas.lib.Pair) RDFDatatype(org.apache.jena.datatypes.RDFDatatype) TargetType(org.apache.jena.shacl.engine.TargetType) JenaException(org.apache.jena.shared.JenaException) ExtendedIterator(org.apache.jena.util.iterator.ExtendedIterator) Shapes(org.apache.jena.shacl.Shapes) Graph(org.apache.jena.graph.Graph)

Example 7 with ExtendedIterator

use of org.apache.jena.util.iterator.ExtendedIterator in project jena by apache.

the class GenericPropertyFunction method bothUnbound.

private QueryIterator bothUnbound(Binding binding, Node subject, Node predicate, Node object, ExecutionContext execCxt) {
    QueryIterConcat queryIterConcat = new QueryIterConcat(execCxt);
    Var subjectVar = Var.alloc(subject.getName());
    Graph graph = execCxt.getActiveGraph();
    // Search for both Features and Geometry in the Graph. Reliant upon consistent usage of SpatialObject (which is base class of Feature and Geometry) if present.
    ExtendedIterator<Triple> subjectTriples;
    if (graph.contains(null, RDF.type.asNode(), Geo.SPATIAL_OBJECT_NODE)) {
        subjectTriples = graph.find(null, RDF.type.asNode(), Geo.SPATIAL_OBJECT_NODE);
    } else if (graph.contains(null, RDF.type.asNode(), Geo.FEATURE_NODE) || graph.contains(null, RDF.type.asNode(), Geo.GEOMETRY_NODE)) {
        ExtendedIterator<Triple> featureTriples = graph.find(null, RDF.type.asNode(), Geo.FEATURE_NODE);
        ExtendedIterator<Triple> geometryTriples = graph.find(null, RDF.type.asNode(), Geo.GEOMETRY_NODE);
        subjectTriples = featureTriples.andThen(geometryTriples);
    } else {
        // Check for Geo Predicate Features in the Graph if no GeometryLiterals found.
        subjectTriples = graph.find(null, SpatialExtension.GEO_LAT_NODE, null);
    }
    // Bind all the Spatial Objects or Geo Predicates once as the subject and search for corresponding Objects.
    while (subjectTriples.hasNext()) {
        Triple subjectTriple = subjectTriples.next();
        Node boundSubject = subjectTriple.getSubject();
        Binding subjectBind = BindingFactory.binding(binding, subjectVar, boundSubject);
        QueryIterator queryIter = oneBound(subjectBind, boundSubject, predicate, object, execCxt);
        queryIterConcat.add(queryIter);
    }
    return queryIterConcat;
}
Also used : QueryIterConcat(org.apache.jena.sparql.engine.iterator.QueryIterConcat) Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) Graph(org.apache.jena.graph.Graph) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Var(org.apache.jena.sparql.core.Var) ExtendedIterator(org.apache.jena.util.iterator.ExtendedIterator) Node(org.apache.jena.graph.Node)

Aggregations

ExtendedIterator (org.apache.jena.util.iterator.ExtendedIterator)7 Node (org.apache.jena.graph.Node)6 Triple (org.apache.jena.graph.Triple)6 Graph (org.apache.jena.graph.Graph)5 Var (org.apache.jena.sparql.core.Var)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4 java.util (java.util)2 Iterator (java.util.Iterator)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)2 Iter (org.apache.jena.atlas.iterator.Iter)2 JenaException (org.apache.jena.shared.JenaException)2 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)2 BindingBuilder (org.apache.jena.sparql.engine.binding.BindingBuilder)2 ThreadInfo (java.lang.management.ThreadInfo)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 URI (java.net.URI)1 ExecutorService (java.util.concurrent.ExecutorService)1 Predicate (java.util.function.Predicate)1