80 likes | 427 Views
Jena (Apache). olivier.corby@inria.fr. Jena. HP, Apache http://jena.apache.org/ RDF Triple Store In memory or in database Fuseki SPARQL endpoint. Load. Model model = ModelFactory.createDefaultModel (); InputStream in = FileManager.get (). open(" data.ttl ");
E N D
Jena (Apache) olivier.corby@inria.fr
Jena • HP, Apache • http://jena.apache.org/ • RDF Triple Store • In memory or in database • Fuseki SPARQL endpoint
Load Model model = ModelFactory.createDefaultModel(); InputStreamin = FileManager.get().open("data.ttl"); model.read(in, null, "TTL");
Query String queryString = "select * where { ?x ?p ?y }"; Queryquery = QueryFactory.create(queryString); QueryExecutionqe = QueryExecutionFactory.create(query, model); ResultSetresults = qe.execSelect(); ResultSetFormatter.output(results, ResultsFormat.FMT_RS_XML);
Result for (; results.hasNext();) { QuerySolutionsol = results.next(); Literallit = sol.getLiteral("y"); System.out.println("y: " + lit.getString()); }
Update String q = "prefixfoaf: <http://foaf.org/> " + "create graph foaf:g1 ;" + "insert data {graph foaf:g1 {" + <John> foaf:knows <Jim>, <James>}}"; Model model = ModelFactory.createDefaultModel(); Datasetds = DatasetFactory.create(model); UpdateAction.parseExecute(q, ds) ;