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