Search in sources :

Example 11 with ResIterator

use of org.apache.jena.rdf.model.ResIterator in project jena by apache.

the class GeoSPARQLOperations method applySubPropertyDefaultGeometry.

/**
 * Every subProperty of hasGeometry is made a subProperty of
 * hasDefaultGeometry.<br>
 * Assumption that each Feature has a single hasGeometry property.<br>
 * Requires RDFS inferencing to propagate through the data.
 *
 * @param model
 */
public static final void applySubPropertyDefaultGeometry(Model model) {
    try {
        ResIterator resIt = model.listResourcesWithProperty(RDFS.subPropertyOf, Geo.HAS_GEOMETRY_PROP);
        while (resIt.hasNext()) {
            Resource res = resIt.nextResource();
            res.addProperty(RDFS.subPropertyOf, Geo.HAS_DEFAULT_GEOMETRY_PROP);
        }
    } catch (Exception ex) {
        LOGGER.error("Inserting GeoSPARQL predicates error: {}", ex.getMessage());
    }
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) Resource(org.apache.jena.rdf.model.Resource) TransformException(org.opengis.referencing.operation.TransformException) DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) FactoryException(org.opengis.util.FactoryException) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) IOException(java.io.IOException)

Example 12 with ResIterator

use of org.apache.jena.rdf.model.ResIterator in project jena by apache.

the class TestReasoners method doTestTransitiveReduction.

/**
 * Test that a transitive reduction is complete.
 * Assumes test graph has no cycles (other than the trivial
 * identity ones).
 */
public void doTestTransitiveReduction(Model model, Property dp) {
    InfModel im = ModelFactory.createInfModel(ReasonerRegistry.getTransitiveReasoner(), model);
    for (ResIterator i = im.listSubjects(); i.hasNext(); ) {
        Resource base = i.nextResource();
        List<RDFNode> directLinks = new ArrayList<>();
        for (NodeIterator j = im.listObjectsOfProperty(base, dp); j.hasNext(); ) {
            directLinks.add(j.next());
        }
        for (int n = 0; n < directLinks.size(); n++) {
            Resource d1 = (Resource) directLinks.get(n);
            for (int m = n + 1; m < directLinks.size(); m++) {
                Resource d2 = (Resource) directLinks.get(m);
                if (im.contains(d1, dp, d2) && !base.equals(d1) && !base.equals(d2)) {
                    assertTrue("Triangle discovered in transitive reduction", false);
                }
            }
        }
    }
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) ResIterator(org.apache.jena.rdf.model.ResIterator) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) InfModel(org.apache.jena.rdf.model.InfModel) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

ResIterator (org.apache.jena.rdf.model.ResIterator)12 Resource (org.apache.jena.rdf.model.Resource)10 Model (org.apache.jena.rdf.model.Model)7 HashSet (java.util.HashSet)3 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)3 MismatchedDimensionException (org.opengis.geometry.MismatchedDimensionException)3 TransformException (org.opengis.referencing.operation.TransformException)3 FactoryException (org.opengis.util.FactoryException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Node (org.apache.jena.graph.Node)2 InfModel (org.apache.jena.rdf.model.InfModel)2 Literal (org.apache.jena.rdf.model.Literal)2 Property (org.apache.jena.rdf.model.Property)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 Statement (org.apache.jena.rdf.model.Statement)2 URL (java.net.URL)1 Set (java.util.Set)1 RdfResource (nl.knaw.huygens.timbuctoo.rml.rdfshim.RdfResource)1 MappingDocumentBuilder (nl.knaw.huygens.timbuctoo.rml.rmldata.builders.MappingDocumentBuilder)1