Lab: Storing graphs and datasets with Jena and TDB

From Info216

Lab 4: Storing graphs and datasets with Jena and TDB

Because both labs 2 and 3 were rather large, and you will spend some time this week working on the project ideas, lab 4 is shorter. Use the extra time to continue your work on labs 2 and 3. The labs do not depend much on one another, so you do not have to do them in strict sequence.


TDBFactory (createDataset) Dataset (getDefaultModel, close, addNamedModel, getNamedModel) RDFDataMgr (write) RDFFormat


Storing graphs in files and in the TDB triple store. Working with multiple graphs (in a dataset).


Take one of the models you have created before and turn it into the default model in a TDB-backed dataset. (Tip: make a copy of your existing program first, in case you mess up the code. You can duplicate Java classes in Eclipse using cut-and-paste.) Remember to close the dataset at the end of the program!

Write a new program that opens the same TDB-backed dataset, gets the default model and writes it to System.out, without creating any resources and triples first. Check that all the triples from the previous task are still there nevertheless.

Honour tasks

Create another (default) model using the ModelFactory. Just add a single simple triple to it. Add the default model to your TDB-backed dataset as a named model.

Write out the old default and new named model in TRIG and TRIX formats. Are the results as you expected? Does the Dataset class in Jena offer a straightforward way to write out datasets?

Use RDFDataMgr to write your dataset (with the two models) first in TRIG and then TRIX formats. (Hint: you cannot give "TRIX" and "TRIG" as string parameters to this method. Instead, use RDFFormat values!) Compare the results.