Excellent, that helped. Here's the code:
DatasetGraph dsg = DatasetGraphFactory.createMem();
Node g1 = Node.createURI("ns:Event1");
Triple e1 = new Triple(Node.createURI("w:Mike"), Node.createURI("w:follows"),
Node.createURI("w:Dave"));
Quad quad1 = new Quad(g1, e1);
dsg.add(quad1);
I think I got hung up because I was starting my DatasetGraph by loading my
ontology from file, then building it out from there.
Thanks --
On May 30, 2013, at 4:18 PM, Rob Vesse wrote:
> Per the Javadoc for DatasetGraphFactory.create(Graph):
>
> "New graphs must be explicitly added."
>
> Thus you need to call add(Node, Graph) explicitly if you wish to introduce
> quads into a graph that does not already exist.
> Alternatively I would suggest creating a DatasetGraph with
> DatasetGraphFactory.createMem() and simply adding to it as necessary I.e.
> start from an empty dataset.
>
>
> Generally I prefer to work with the Dataset abstraction and only go to the
> lower level DatasetGraph where necessary.
>
> Rob
>
>
>
> On 5/30/13 3:10 PM, "Cindy A McMullen" <[email protected]> wrote:
>
>> 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(DatasetGraphCollect
>> ion.java:41)
>> [java] at
>> oracle.social.discovery.rdf.jena.QueryMemoryGraph.addData(QueryMemoryGraph
>> .java:94)
>> [java] at
>> oracle.social.discovery.rdf.jena.QueryMemoryGraph.main(QueryMemoryGraph.ja
>> va: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
>