use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestDatasetTDB method load3.
private static void load3(Model model) {
Resource r3 = model.createResource(base1 + "r3");
Property p1 = model.createProperty(baseNS + "p2");
model.add(r3, p1, "x1");
model.add(r3, p1, "x2");
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class GeoSPARQLOperations method convertGeometryStructure.
/**
* Convert Geometry Datatypes (WKT, GML, etc.) in Model to GeoSPARQL
* structure.<br>
* (Subject-property-GeometryLiteral) becomes (Feature-hasGeometry-Geometry)
* and (Geometry-hasSerialization-GeometryLiteral).<br>
* Original property will be removed from resulting Model.
*
* @param model
* @return Converted model.
*/
public static final Model convertGeometryStructure(Model model) {
Model outputModel = ModelFactory.createDefaultModel();
outputModel.add(model);
outputModel.setNsPrefixes(model.getNsPrefixMap());
List<Statement> additionalStatements = new ArrayList<>();
StmtIterator stmtIter = outputModel.listStatements();
while (stmtIter.hasNext()) {
Statement stmt = stmtIter.nextStatement();
RDFNode object = stmt.getObject();
if (object.isLiteral()) {
Literal literal = object.asLiteral();
RDFDatatype datatype = literal.getDatatype();
if (GeometryDatatype.check(datatype)) {
Property property = stmt.getPredicate();
if (property.equals(Geo.HAS_SERIALIZATION_PROP) || property.equals(Geo.AS_WKT_PROP) || property.equals(Geo.AS_GML_PROP)) {
// Model already contains the GeoSPARQL properties for this literal so skipping.
continue;
}
if (outputModel.contains(property, RDFS.subPropertyOf, Geo.HAS_SERIALIZATION_PROP)) {
// The property is a sub property of hasSerialization so skipping. Only RDFS inferencing needs to be applied.
continue;
}
Resource feature = stmt.getSubject();
Resource geometry = createGeometry(feature);
additionalStatements.add(ResourceFactory.createStatement(feature, Geo.HAS_GEOMETRY_PROP, geometry));
additionalStatements.add(ResourceFactory.createStatement(geometry, Geo.HAS_SERIALIZATION_PROP, literal));
stmtIter.remove();
}
}
}
outputModel.add(additionalStatements);
return outputModel;
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class GeoSPARQLOperations method handleLiteral.
private static void handleLiteral(Statement statement, Model outputModel, String outputSrsURI, GeometryDatatype outputDatatype) {
Literal literal = statement.getLiteral();
RDFDatatype datatype = literal.getDatatype();
// Check whether a supported geometry literal.
if (GeometryDatatype.check(datatype)) {
GeometryWrapper originalGeom = GeometryWrapper.extract(literal);
GeometryWrapper convertedGeom;
try {
if (outputSrsURI != null) {
convertedGeom = originalGeom.convertSRS(outputSrsURI);
} else {
convertedGeom = originalGeom;
}
} catch (FactoryException | MismatchedDimensionException | TransformException ex) {
LOGGER.error("SRS Conversion Exception: {} - Literal: {}, Output SRS URI: {}. Reusing original literal for output.", ex.getMessage(), literal, outputSrsURI);
convertedGeom = originalGeom;
}
if (outputDatatype == null) {
outputDatatype = GeometryDatatype.get(datatype);
}
Literal convertedGeometryLiteral = convertedGeom.asLiteral(outputDatatype);
// Assign the existing property unless it needs to be switched for asGML and asWKT.
Property outputProperty = statement.getPredicate();
if (outputProperty.equals(Geo.AS_GML_PROP) && outputDatatype.equals(WKTDatatype.INSTANCE)) {
outputProperty = Geo.AS_WKT_PROP;
} else if (outputProperty.equals(Geo.AS_WKT_PROP) && outputDatatype.equals(GMLDatatype.INSTANCE)) {
outputProperty = Geo.AS_GML_PROP;
}
Statement outputStatement = ResourceFactory.createStatement(statement.getSubject(), outputProperty, convertedGeometryLiteral);
outputModel.add(outputStatement);
} else {
// Not a statement of interest so store for output.
outputModel.add(statement);
}
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestReasoners method testModelFactoryRDFS.
/**
* Test the ModelFactory interface
*/
public void testModelFactoryRDFS() {
Model data = ModelFactory.createDefaultModel();
Property p = data.createProperty("urn:x-hp:ex/p");
Resource a = data.createResource("urn:x-hp:ex/a");
Resource b = data.createResource("urn:x-hp:ex/b");
Resource C = data.createResource("urn:x-hp:ex/c");
data.add(p, RDFS.range, C).add(a, p, b);
Model result = ModelFactory.createRDFSModel(data);
StmtIterator i = result.listStatements(b, RDF.type, (RDFNode) null);
TestUtil.assertIteratorValues(this, i, new Object[] { data.createStatement(b, RDF.type, RDFS.Resource), data.createStatement(b, RDF.type, C) });
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestReasoners method testTransitiveReduction.
/**
* Check a complex graph's transitive reduction.
*/
public void testTransitiveReduction() {
Model test = FileManager.getInternal().loadModelInternal("testing/reasoners/bugs/subpropertyModel.n3");
Property dp = test.getProperty(TransitiveReasoner.directSubPropertyOf.getURI());
doTestTransitiveReduction(test, dp);
}
Aggregations