Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

Adding graphs to an in-memory dataset

$
0
0
How do I add a named graph to an in-memory Dataset? This code works with TDB, but the in-memory implementation throws:

Exception in thread "main" com.hp.hpl.jena.shared.JenaException: No such graph: ns:Event1
at com.hp.hpl.jena.sparql.core.DatasetGraphCollection.add(DatasetGraphCollection.java:41)
[java] at oracle.social.discovery.rdf.jena.QueryMemoryGraph.addData(QueryMemoryGraph.java:94)
[java] at oracle.social.discovery.rdf.jena.QueryMemoryGraph.main(QueryMemoryGraph.java:33)

Here's the code:

String inputFileName = "foo-ontology.ttl";
Model model = ModelFactory.createDefaultModel();
InputStream in = FileManager.get().open( inputFileName );
model.read(in, "", "TTL");
DatasetGraph dsg = DatasetGraphFactory.create(model.getGraph());
……

Node g1 = Node.createURI("ns:Event1");
Triple e1 = new Triple(Node.createURI("w:Mike"), Node.createURI("w:follows"), Node.createURI("w:Dave"));
dsg.add(new Quad(g1, e1));

I'm using apache-jena-2.10.0

Viewing all articles
Browse latest Browse all 5648

Trending Articles