use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class GeoSPARQLOperations method convertSRSDatatype.
private static Model convertSRSDatatype(Model inputModel, String outputSrsURI, GeometryDatatype outputDatatype) {
if (outputSrsURI == null) {
outputSrsURI = GeoSPARQLOperations.findModeSRS(inputModel);
}
if (outputDatatype == null || !GeometryDatatype.check(outputDatatype)) {
LOGGER.warn("Output datatype {} is not a recognised for Geometry Literal. Defaulting to {}.", outputDatatype, WKTDatatype.URI);
outputDatatype = WKTDatatype.INSTANCE;
}
// Iterate through all statements: toNodeValue geometry literals and just add the rest.
Model outputModel = ModelFactory.createDefaultModel();
outputModel.setNsPrefixes(inputModel.getNsPrefixMap());
Iterator<Statement> statementIt = inputModel.listStatements();
while (statementIt.hasNext()) {
Statement statement = statementIt.next();
RDFNode object = statement.getObject();
if (object.isLiteral()) {
handleLiteral(statement, outputModel, outputSrsURI, outputDatatype);
} else {
// Not a statement of interest so store for output.
outputModel.add(statement);
}
}
return outputModel;
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class SpatialIndex method getGeometryLiteralIndexItems.
/**
* @param model
* @param srsURI
* @return GeometryLiteral items prepared for adding to SpatialIndex.
* @throws SpatialIndexException
*/
private static Collection<SpatialIndexItem> getGeometryLiteralIndexItems(Model model, String srsURI) throws SpatialIndexException {
List<SpatialIndexItem> items = new ArrayList<>();
StmtIterator stmtIt = model.listStatements(null, Geo.HAS_GEOMETRY_PROP, (Resource) null);
while (stmtIt.hasNext()) {
Statement stmt = stmtIt.nextStatement();
Resource feature = stmt.getSubject();
Resource geometry = stmt.getResource();
ExtendedIterator<RDFNode> nodeIter = model.listObjectsOfProperty(geometry, Geo.HAS_SERIALIZATION_PROP);
if (!nodeIter.hasNext()) {
NodeIterator wktNodeIter = model.listObjectsOfProperty(geometry, Geo.AS_WKT_PROP);
NodeIterator gmlNodeIter = model.listObjectsOfProperty(geometry, Geo.AS_GML_PROP);
nodeIter = wktNodeIter.andThen(gmlNodeIter);
}
while (nodeIter.hasNext()) {
Literal geometryLiteral = nodeIter.next().asLiteral();
GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometryLiteral);
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: " + geometryLiteral + ". " + ex.getMessage());
}
}
}
return items;
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class SecurityExample method main.
/**
* @param args
*/
public static void main(String[] args) {
String[] names = { "alice", "bob", "chuck", "darla" };
RDFNode msgType = ResourceFactory.createResource("http://example.com/msg");
Property pTo = ResourceFactory.createProperty("http://example.com/to");
Property pFrom = ResourceFactory.createProperty("http://example.com/from");
Property pSubj = ResourceFactory.createProperty("http://example.com/subj");
Model model = ModelFactory.createDefaultModel();
URL url = SecurityExample.class.getClassLoader().getResource("org/apache/jena/security/example/example.ttl");
model.read(url.toExternalForm());
ResIterator ri = model.listSubjectsWithProperty(RDF.type, msgType);
System.out.println("All the messages");
while (ri.hasNext()) {
Resource msg = ri.next();
Statement to = msg.getProperty(pTo);
Statement from = msg.getProperty(pFrom);
Statement subj = msg.getProperty(pSubj);
System.out.println(String.format("%s to: %s from: %s subj: %s", msg, to.getObject(), from.getObject(), subj.getObject()));
}
System.out.println();
ExampleEvaluator evaluator = new ExampleEvaluator(model);
model = Factory.getInstance(evaluator, "http://example.com/SecuredModel", model);
for (String userName : names) {
evaluator.setPrincipal(userName);
System.out.println("Messages " + userName + " can manipulate");
ri = model.listSubjectsWithProperty(RDF.type, msgType);
while (ri.hasNext()) {
Resource msg = ri.next();
Statement to = msg.getProperty(pTo);
Statement from = msg.getProperty(pFrom);
Statement subj = msg.getProperty(pSubj);
System.out.println(String.format("%s to: %s from: %s subj: %s", msg, to.getObject(), from.getObject(), subj.getObject()));
}
ri.close();
for (String name : names) {
System.out.println(String.format("%s messages to %s", model.listSubjectsWithProperty(pTo, name).toList().size(), name));
}
System.out.println();
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class SecuredModelTest method testRDFNodeInModel.
@Test
public void testRDFNodeInModel() {
// test uri
final RDFNode rdfNode = ResourceFactory.createResource("http://exmple.com/testInModel");
final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
Assert.assertEquals("Should have placed RDFNode in secured securedModel", securedModel, rdfNode2.getModel());
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class SecuredModelTest method testAnonymousInModel.
@Test
public void testAnonymousInModel() {
// test anonymous
final RDFNode rdfNode = ResourceFactory.createResource();
final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
Assert.assertEquals("Should have placed RDFNode in secured securedModel", securedModel, rdfNode2.getModel());
}
Aggregations