After you install Construct, the next thing you might want to do is add some data. This post will describe the basics.
The Java libraries bundled with Construct give you a couple of ways to contribute date: You can either pass RDF triples in directly, or work with Jena and submit a model when you’re ready to publish its contents.
Working with Triples
The first step is to create a connection to the DataPort. This is achieved by creating a new instance of the DataPortProxy class.
-
final DataPortProxy proxy = new DataPortProxy();
Next, we call the add() method of the proxy object, passing the RDF triple as an argument. Multiple triples can be added simultaneously by separating them with a period. The return indicates whether the add operation was successful.
-
final boolean response = proxy.add(“<http://example.com/people/bob>
-
<http://example.com/terms#name>
-
\”Bob Smith\”.”);
Finally, we close the connection to the data port.
-
proxy.close();
Working with Jena
When using Jena, the process is very similar. As before you should begin by creating a new instance of the DataPortProxy object. Next, a new model should be created, and populated with data.
-
final Model model = ModelFactory.createDefaultModel();
-
final Resource person = model.createResource(“http://example.com/people/bob”);
-
final Property name = model.createProperty(“http://example.com/terms#name”);
-
person.addProperty(name, “Bob Smith”);
Then, the contents of the Jena model is added to Construct through another of the proxy object’s add() methods. Remember to close the connection as before when you are finished.
-
final boolean response = proxy.add(model);
That’s the basics of adding data to Construct. The next post in this series will describe how to get data from Construct using the Query Service.
![[del.icio.us]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/digg.png)
![[Google]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/google.png)
![[StumbleUpon]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Windows Live]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.construct-infrastructure.org/wp-content/plugins/bookmarkify/email.png)
0 Responses to “Construct and Java - Part 1”
Leave a Reply