Search in sources :

Example 76 with Property

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");
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 77 with Property

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;
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Literal(org.apache.jena.rdf.model.Literal) InfModel(org.apache.jena.rdf.model.InfModel) Model(org.apache.jena.rdf.model.Model) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource) RDFDatatype(org.apache.jena.datatypes.RDFDatatype) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 78 with Property

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);
    }
}
Also used : FactoryException(org.opengis.util.FactoryException) Statement(org.apache.jena.rdf.model.Statement) Literal(org.apache.jena.rdf.model.Literal) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) TransformException(org.opengis.referencing.operation.TransformException) RDFDatatype(org.apache.jena.datatypes.RDFDatatype) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) Property(org.apache.jena.rdf.model.Property)

Example 79 with Property

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) });
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) OntModel(org.apache.jena.ontology.OntModel) InfModel(org.apache.jena.rdf.model.InfModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 80 with Property

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);
}
Also used : OntModel(org.apache.jena.ontology.OntModel) InfModel(org.apache.jena.rdf.model.InfModel) Model(org.apache.jena.rdf.model.Model) Property(org.apache.jena.rdf.model.Property)

Aggregations

Property (org.apache.jena.rdf.model.Property)90 Resource (org.apache.jena.rdf.model.Resource)59 Model (org.apache.jena.rdf.model.Model)46 RDFNode (org.apache.jena.rdf.model.RDFNode)19 Test (org.junit.Test)18 Statement (org.apache.jena.rdf.model.Statement)17 ArrayList (java.util.ArrayList)14 StmtIterator (org.apache.jena.rdf.model.StmtIterator)14 Literal (org.apache.jena.rdf.model.Literal)11 Iterator (java.util.Iterator)6 Node (org.apache.jena.graph.Node)6 Triple (org.apache.jena.graph.Triple)6 QueryExecution (org.apache.jena.query.QueryExecution)6 OntModel (org.apache.jena.ontology.OntModel)5 Dataset (org.apache.jena.query.Dataset)5 Query (org.apache.jena.query.Query)4 InfModel (org.apache.jena.rdf.model.InfModel)4 Store (org.apache.jena.sdb.Store)4 IOException (java.io.IOException)3 LEGATO (legato.LEGATO)3