[Mulgara-general] BlankNodes
mir
manuel.innerhofer at trialox.org
Thu Jun 11 09:50:39 UTC 2009
Hi,
I've got a probelm with BlankNodes. I'd like to keep BlankNode objects
in my code so I can reuse them when adding triples. But even though I
use the same BlankNode object when inserting triples then the triples in
the graph have different blank nodes (i.e. "_node1" and "_node2"). As
you can see in the example below even using the BlankNode object in the
same ClientGraph "session" twice results in two different blank nodes in
the graph. Is there a way this can be done?
cheers,
Manuel
// creating a new model
ConnectionFactory factory = new ConnectionFactory();
Connection conn =
factory.newConnection(URI.create("local://localhost/server1"));
URI myUri = new URI("http://localhost:8282/test");
Session session = conn.getSession();
session.createModel(myUri, Session.MULGARA_GRAPH_URI);
session.close();
conn.dispose();
// adding triples into the graph
ClientGraph client = AbstractGraphFactory.createGraph(HOST, myUri);
System.out.println("number of triples " + client.getNumberOfTriples());
GraphElementFactory elementFactory = client.getElementFactory();
BlankNode blankNode = elementFactory.createResource();
Triple triple1 = elementFactory.createTriple(blankNode,
elementFactory.createResource(new URI("http://my.test/foo")),
elementFactory.createResource(new URI("http://my.test/bar")));
Triple triple2 = elementFactory.createTriple(blankNode,
elementFactory.createResource(new URI("http://my.test/r")),
elementFactory.createResource(new URI("http://my.test/p")));
client.add(triple1);
client.add(triple2);
client.close();
client = AbstractGraphFactory.createGraph(HOST, myUri);
ClosableIterator iter = client.find(null, null, null);
Triple triple1got = (Triple) iter.next();
Triple triple2got = (Triple) iter.next();
System.out.println(iter.hasNext());
System.out.println(triple1got.getSubject().equals(triple2got.getSubject())); // should be true
More information about the Mulgara-general
mailing list