Construct and Java - Part 1

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

(download the sample code)

The first step is to create a connection to the DataPort. This is achieved by creating a new instance of the DataPortProxy class.

  1. 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.

  1. final boolean response = proxy.add(“<http://example.com/people/bob>
  2. <http://example.com/terms#name>
  3. \”Bob Smith\”.”);

Finally, we close the connection to the data port.

  1. proxy.close();

Working with Jena

(download the sample code)

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.

  1. final Model model = ModelFactory.createDefaultModel();
  2. final Resource person = model.createResource(“http://example.com/people/bob”);
  3. final Property name = model.createProperty(“http://example.com/terms#name”);
  4. 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.

  1. 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.

0 Responses to “Construct and Java - Part 1”


  1. No Comments
  1. 1 Construct and Java - Part 2 at Construct

Leave a Reply