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());
}
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));
}
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;
}
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);
}
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;
}
Aggregations