Search in sources :

Example 6 with Property

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

the class AbstractCompressedWholeFileQuadInputFormatTests method writeGoodTuples.

private void writeGoodTuples(OutputStream output, int num) {
    Dataset ds = DatasetFactory.createGeneral();
    Model m = ModelFactory.createDefaultModel();
    Resource currSubj = m.createResource("http://example.org/subjects/0");
    Property predicate = m.createProperty("http://example.org/predicate");
    for (int i = 0; i < num; i++) {
        if (i % 100 == 0) {
            ds.addNamedModel("http://example.org/graphs/" + (i / 100), m);
            m = ModelFactory.createDefaultModel();
        }
        if (i % 10 == 0) {
            currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
        }
        m.add(currSubj, predicate, m.createTypedLiteral(i));
    }
    if (!m.isEmpty()) {
        ds.addNamedModel("http://example.org/graphs/extra", m);
    }
    this.writeTuples(ds, output);
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 7 with Property

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

the class AbstractCompressedWholeFileTripleInputFormatTests method generateMixedTuples.

@Override
protected final void generateMixedTuples(OutputStream output, int num) throws IOException {
    // Write good data
    Model m = ModelFactory.createDefaultModel();
    Resource currSubj = m.createResource("http://example.org/subjects/0");
    Property predicate = m.createProperty("http://example.org/predicate");
    for (int i = 0; i < num / 2; i++) {
        if (i % 10 == 0) {
            currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
        }
        m.add(currSubj, predicate, m.createTypedLiteral(i));
    }
    this.writeTuples(m, output);
    // Write junk data
    byte[] junk = "junk data\n".getBytes(utf8);
    for (int i = 0; i < num / 2; i++) {
        output.write(junk);
    }
    output.flush();
    output.close();
}
Also used : Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 8 with Property

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

the class TestJsonLDWriter method simpleModel.

private Model simpleModel(String ns) {
    Model m = ModelFactory.createDefaultModel();
    Resource s = m.createResource(ns + "s");
    Property p = m.createProperty(ns + "p");
    Resource o = m.createResource(ns + "o");
    m.add(s, p, o);
    return m;
}
Also used : Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 9 with Property

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

the class DefaultNeedModelWrapper method getLocationCoordinate.

public Coordinate getLocationCoordinate(Resource contentNode) {
    Model needModel = getNeedModel();
    Property geoProperty = needModel.createProperty("http://schema.org/", "geo");
    Property longitudeProperty = needModel.createProperty("http://schema.org/", "longitude");
    Property latitudeProperty = needModel.createProperty("http://schema.org/", "latitude");
    RDFNode locationNode = RdfUtils.findOnePropertyFromResource(needModel, contentNode, WON.HAS_LOCATION);
    RDFNode geoNode = (locationNode != null && locationNode.isResource()) ? RdfUtils.findOnePropertyFromResource(needModel, locationNode.asResource(), geoProperty) : null;
    RDFNode lat = (geoNode != null && geoNode.isResource()) ? RdfUtils.findOnePropertyFromResource(needModel, geoNode.asResource(), latitudeProperty) : null;
    RDFNode lon = (geoNode != null && geoNode.isResource()) ? RdfUtils.findOnePropertyFromResource(needModel, geoNode.asResource(), longitudeProperty) : null;
    if (lat == null || lon == null) {
        return null;
    }
    Float latitude = Float.valueOf(lat.asLiteral().getString());
    Float longitude = Float.valueOf(lon.asLiteral().getString());
    return new Coordinate(latitude, longitude);
}
Also used : Coordinate(won.protocol.model.Coordinate) Model(org.apache.jena.rdf.model.Model) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 10 with Property

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

the class LinkedDataServiceImpl method addConnectionMetadata.

private void addConnectionMetadata(final Dataset content, URI atomURI, URI containerURI) {
    Model model = content.getNamedModel(createDataGraphUriFromUri(containerURI));
    List<Object[]> connectionCountsPerState = atomRepository.getCountsPerConnectionState(atomURI);
    Resource containerResource = model.getResource(containerURI.toString());
    for (Object[] countForState : connectionCountsPerState) {
        ConnectionState stateName = (ConnectionState) countForState[0];
        Long count = (Long) countForState[1];
        Property countProperty = getRdfPropertyForState(stateName);
        if (countProperty == null) {
            logger.warn("did not recognize connection state " + stateName);
            continue;
        }
        containerResource.addProperty(countProperty, Integer.toString(count.intValue()), XSDDatatype.XSDint);
    }
}
Also used : Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Aggregations

Property (org.apache.jena.rdf.model.Property)89 Resource (org.apache.jena.rdf.model.Resource)58 Model (org.apache.jena.rdf.model.Model)45 RDFNode (org.apache.jena.rdf.model.RDFNode)18 Test (org.junit.Test)18 Statement (org.apache.jena.rdf.model.Statement)17 StmtIterator (org.apache.jena.rdf.model.StmtIterator)14 ArrayList (java.util.ArrayList)13 Literal (org.apache.jena.rdf.model.Literal)11 Node (org.apache.jena.graph.Node)6 Triple (org.apache.jena.graph.Triple)6 Iterator (java.util.Iterator)5 OntModel (org.apache.jena.ontology.OntModel)5 Dataset (org.apache.jena.query.Dataset)5 QueryExecution (org.apache.jena.query.QueryExecution)5 InfModel (org.apache.jena.rdf.model.InfModel)4 Store (org.apache.jena.sdb.Store)4 HashSet (java.util.HashSet)3 LEGATO (legato.LEGATO)3 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)3