use of org.apache.jena.rdf.model.Property in project jena by apache.
the class ExTDB6 method main.
public static void main(String[] args) throws Exception {
// / turn off the "No BGP optimizer warning"
TDB.setOptimizerWarningFlag(false);
final String DATASET_DIR_NAME = "data0";
final Dataset data0 = TDBFactory.createDataset(DATASET_DIR_NAME);
// show the currently registered names
for (Iterator<String> it = data0.listNames(); it.hasNext(); ) {
out.println("NAME=" + it.next());
}
out.println("getting named model...");
// / this is the OWL portion
final Model model = data0.getNamedModel(MY_NS);
out.println("Model := " + model);
out.println("getting graph...");
// / this is the DATA in that MODEL
final Graph graph = model.getGraph();
out.println("Graph := " + graph);
if (graph.isEmpty()) {
final Resource product1 = model.createResource(MY_NS + "product/1");
final Property hasName = model.createProperty(MY_NS, "#hasName");
final Statement stmt = model.createStatement(product1, hasName, model.createLiteral("Beach Ball", "en"));
out.println("Statement = " + stmt);
model.add(stmt);
// just for fun
out.println("Triple := " + stmt.asTriple().toString());
} else {
out.println("Graph is not Empty; it has " + graph.size() + " Statements");
long t0, t1;
t0 = System.currentTimeMillis();
final Query q = QueryFactory.create("PREFIX exns: <" + MY_NS + "#>\n" + "PREFIX exprod: <" + MY_NS + "product/>\n" + " SELECT * " + // +" WHERE { exprod:1 exns:hasName ?name }"
" WHERE { ?res ?pred ?obj }");
out.println("Query := " + q);
t1 = System.currentTimeMillis();
out.println("QueryFactory.TIME=" + (t1 - t0));
t0 = System.currentTimeMillis();
try (QueryExecution qExec = QueryExecutionFactory.create(q, model)) {
t1 = System.currentTimeMillis();
out.println("QueryExecutionFactory.TIME=" + (t1 - t0));
t0 = System.currentTimeMillis();
ResultSet rs = qExec.execSelect();
t1 = System.currentTimeMillis();
out.println("executeSelect.TIME=" + (t1 - t0));
while (rs.hasNext()) {
QuerySolution sol = rs.next();
out.println("Solution := " + sol);
for (Iterator<String> names = sol.varNames(); names.hasNext(); ) {
final String name = names.next();
out.println("\t" + name + " := " + sol.get(name));
}
}
}
}
out.println("closing graph");
graph.close();
out.println("closing model");
model.close();
// out.println("closing DataSetGraph");
// dsg.close();
out.println("closing DataSet");
data0.close();
}
use of org.apache.jena.rdf.model.Property in project opentheso by miledrousset.
the class SynchroSparql method run.
@Override
public void run() {
System.out.println("dans le run saprtql");
String url = sparqlStruct.getAdresseServeur().replaceAll("http", "jdbc:virtuoso").trim() + ":1111";
VirtGraph graph = new VirtGraph(sparqlStruct.getGraph(), url, sparqlStruct.getNom_d_utilisateur(), sparqlStruct.getMot_de_passe());
String str = "CLEAR GRAPH <" + sparqlStruct.getGraph() + ">";
VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(str, graph);
vur.exec();
Model m = ModelFactory.createDefaultModel();
DownloadBean db = new DownloadBean();
db.setConnect(conn);
StreamedContent file = db.thesoToFile(sparqlStruct.getThesaurus(), liste_lang, liste_group, 0);
try {
m.read(file.getStream(), null);
} catch (Exception e) {
// graph.close();
}
StmtIterator iter = m.listStatements();
while (iter.hasNext()) {
Statement stmt = iter.nextStatement();
Resource subject = stmt.getSubject();
Property predicate = stmt.getPredicate();
RDFNode object = stmt.getObject();
Triple tri = new Triple(subject.asNode(), predicate.asNode(), object.asNode());
graph.add(tri);
}
graph.close();
}
use of org.apache.jena.rdf.model.Property in project webofneeds by researchstudio-sat.
the class ConnectFromNodeReviewSocketImpl method process.
@Override
public void process(final Exchange exchange) {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
Optional<Connection> con = connectionRepository.findOneBySocketURIAndTargetSocketURI(wonMessage.getRecipientSocketURIRequired(), wonMessage.getSenderSocketURIRequired());
try {
Map<Property, String> reviewData = WonRdfUtils.MessageUtils.getReviewContent(wonMessage);
if (reviewData != null) {
addReviewToAtom(reviewData, con.get().getConnectionURI());
} else {
logger.debug("No review data found in message: {}", wonMessage);
}
} catch (IllegalArgumentException e) {
logger.debug("{}: for {}", e, wonMessage);
}
}
use of org.apache.jena.rdf.model.Property in project webofneeds by researchstudio-sat.
the class JenaBnodeInDatasetTest method assertSameSubjBnode.
private void assertSameSubjBnode(Dataset dataset, final String ns, final String g1, final String g2, final String pred1, final String pred2) {
Model model1 = dataset.getNamedModel(ns + g1);
Model model2 = dataset.getNamedModel(ns + g2);
Property prop1 = model1.createProperty(ns, pred1);
ResIterator iter1 = model1.listResourcesWithProperty(prop1, null);
Property prop2 = model2.createProperty(ns, pred2);
ResIterator iter2 = model2.listResourcesWithProperty(prop2, null);
Resource r1 = iter1.next();
Resource r2 = iter2.next();
Assert.assertTrue(r1 != null && r1.equals(r2));
}
use of org.apache.jena.rdf.model.Property in project webofneeds by researchstudio-sat.
the class DefaultAtomModelWrapper method getLocationCoordinate.
/**
* Tries to retrieve the coordinates of the location stored in the contentNode
* within the given locationProperty
*
* @param contentNode contentNode in which the locationProperty is searched for
* @param locationProperty e.g SCHEMA.LOCATION or SCHEMA.JOBLOCATION is not
* present in the contentNode
* @return Coordinate if found otherwise null
*/
private Coordinate getLocationCoordinate(Resource contentNode, Property locationProperty) {
Model atomModel = getAtomModel();
Property geoProperty = atomModel.createProperty("http://schema.org/", "geo");
Property longitudeProperty = atomModel.createProperty("http://schema.org/", "longitude");
Property latitudeProperty = atomModel.createProperty("http://schema.org/", "latitude");
RDFNode locationNode = RdfUtils.findOnePropertyFromResource(atomModel, contentNode, locationProperty);
RDFNode geoNode = (locationNode != null && locationNode.isResource()) ? RdfUtils.findOnePropertyFromResource(atomModel, locationNode.asResource(), geoProperty) : null;
RDFNode lat = (geoNode != null && geoNode.isResource()) ? RdfUtils.findOnePropertyFromResource(atomModel, geoNode.asResource(), latitudeProperty) : null;
RDFNode lon = (geoNode != null && geoNode.isResource()) ? RdfUtils.findOnePropertyFromResource(atomModel, 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);
}
Aggregations