Search in sources :

Example 6 with ResIterator

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

the class TurtleBlankNodeOutputTests method checkTuples.

@Override
protected void checkTuples(File f, long expected) {
    super.checkTuples(f, expected);
    Model m = RDFDataMgr.loadModel("file://" + f.getAbsolutePath(), this.getRdfLanguage());
    ResIterator iter = m.listSubjects();
    Set<Node> subjects = new HashSet<Node>();
    while (iter.hasNext()) {
        Resource res = iter.next();
        Assert.assertTrue(res.isAnon());
        subjects.add(res.asNode());
    }
    // Should only be one subject unless the data was empty in which case
    // there will be zero subjects
    Assert.assertEquals(expected == 0 ? 0 : 1, subjects.size());
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) HashSet(java.util.HashSet)

Example 7 with ResIterator

use of org.apache.jena.rdf.model.ResIterator in project webofneeds by researchstudio-sat.

the class JenaBnodeInDatasetTest method assertSameSubjBnode.

private void assertSameSubjBnode(Dataset dataset, final String ns, final String g1, final String g2, final String pred1, final String pred2) {
    Model model1 = dataset.getNamedModel(ns + g1);
    Model model2 = dataset.getNamedModel(ns + g2);
    Property prop1 = model1.createProperty(ns, pred1);
    ResIterator iter1 = model1.listResourcesWithProperty(prop1, null);
    Property prop2 = model2.createProperty(ns, pred2);
    ResIterator iter2 = model2.listResourcesWithProperty(prop2, null);
    Resource r1 = iter1.next();
    Resource r2 = iter2.next();
    Assert.assertTrue(r1 != null && r1.equals(r2));
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 8 with ResIterator

use of org.apache.jena.rdf.model.ResIterator in project webofneeds by researchstudio-sat.

the class AgreementProtocolState method getPendingCancellationProposalUris.

public Set<URI> getPendingCancellationProposalUris() {
    Model cancellations = pendingProposals.getDefaultModel();
    if (cancellations == null) {
        return Collections.EMPTY_SET;
    }
    Set ret = new HashSet<URI>();
    ResIterator it = cancellations.listSubjectsWithProperty(WONAGR.PROPOSES_TO_CANCEL);
    while (it.hasNext()) {
        String uri = it.next().asResource().getURI();
        ret.add(URI.create(uri));
    }
    return ret;
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) HashSet(java.util.HashSet) Set(java.util.Set) Model(org.apache.jena.rdf.model.Model) HashSet(java.util.HashSet)

Example 9 with ResIterator

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

the class JenaBasedReader method fromRdf.

public RmlMappingDocument fromRdf(Model data, Function<RdfResource, Optional<DataSource>> dataSourceFactory) {
    ResIterator tripleMaps = data.listSubjectsWithProperty(data.createProperty(NS_RR + "subjectMap"));
    MappingDocumentBuilder resultBuilder = rmlMappingDocument();
    try {
        while (tripleMaps.hasNext()) {
            Resource resource = tripleMaps.nextResource();
            buildTripleMap(JenaResource.fromModel(data, resource), resultBuilder.withTripleMap(resource.getURI()));
        }
    } finally {
        tripleMaps.close();
    }
    return resultBuilder.build(dataSourceFactory);
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) RdfResource(nl.knaw.huygens.timbuctoo.rml.rdfshim.RdfResource) Resource(org.apache.jena.rdf.model.Resource) MappingDocumentBuilder(nl.knaw.huygens.timbuctoo.rml.rmldata.builders.MappingDocumentBuilder)

Example 10 with ResIterator

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

the class SpatialIndex method getGeoPredicateIndexItems.

/**
 * @param model
 * @param srsURI
 * @return Geo predicate objects prepared for adding to SpatialIndex.
 */
private static Collection<SpatialIndexItem> getGeoPredicateIndexItems(Model model, String srsURI) throws SpatialIndexException {
    List<SpatialIndexItem> items = new ArrayList<>();
    ResIterator resIt = model.listResourcesWithProperty(SpatialExtension.GEO_LAT_PROP);
    while (resIt.hasNext()) {
        Resource feature = resIt.nextResource();
        Literal lat = feature.getRequiredProperty(SpatialExtension.GEO_LAT_PROP).getLiteral();
        Literal lon = feature.getProperty(SpatialExtension.GEO_LON_PROP).getLiteral();
        if (lon == null) {
            LOGGER.warn("Geo predicates: latitude found but not longitude. " + feature);
            continue;
        }
        Literal latLonPoint = ConvertLatLon.toLiteral(lat.getFloat(), lon.getFloat());
        GeometryWrapper geometryWrapper = GeometryWrapper.extract(latLonPoint);
        try {
            // Ensure all entries in the target SRS URI.
            GeometryWrapper transformedGeometryWrapper = geometryWrapper.convertSRS(srsURI);
            Envelope envelope = transformedGeometryWrapper.getEnvelope();
            SpatialIndexItem item = new SpatialIndexItem(envelope, feature);
            items.add(item);
        } catch (FactoryException | MismatchedDimensionException | TransformException ex) {
            throw new SpatialIndexException("Transformation Exception: " + geometryWrapper.getLexicalForm() + ". " + ex.getMessage());
        }
    }
    return items;
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) FactoryException(org.opengis.util.FactoryException) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) TransformException(org.opengis.referencing.operation.TransformException) Envelope(org.locationtech.jts.geom.Envelope) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) Literal(org.apache.jena.rdf.model.Literal)

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