Saturday, February 16, 2013

Jena Framework

My first goal of gaining the required knowledge to query DBPedia for some information of interest was accomplished by my last post. However, the journey is not yet complete! It is very important to be able to query such information automatically through a program. Hence, my next logical step was to get to know a framework that will allow me to do this. Jena was just perfect was this requirement.

Let me give you a quick intro on Jena. Jena (http://jena.sourceforge.net/index.html) is an open source Java framework developed by HP Labs that provides methods to be used  in Java programs to query any dataset following certain formats, RDF being one of them, through SPARQL and other similar query languages. 

To get information of interest from DBPedia and for that matter, any other database using Jena, I need to first know the methods offered by Jena. I am sure many of you will agree with me that just reading about the methods is boring. We can understand their usage faster and well through simple Java codes that uses Jena to query any database. We need not be loyal to DBPedia right away because my immediate aim is to understand methods of Jena. So, this post is all about Jena and how to create and query database through it. All the below experimentation is done on WINDOWS XP.

STARTING UP
Ofcourse, to achieve this aim, I have to first download Jena and have it setup on my system. I downloaded Jena 2.6.4 from http://jena.sourceforge.net/index.html and Jena 2.3 from http://sourceforge.net/projects/jena/files/Jena/Jena-2.3/ to get jena-2.6.4.zip and Jena-2.3.zip.

1. I extracted the contents of jena-2.6.4.zip to get a folder named 'Jena-2.6.4'.
2. I have eclipse (Version: Galileo) on my machine. I opened eclipse.

3. Went to File->New->Project. In the shown hierarchy, opened hierarchy under Java by clicking on the '+' (When expanded, shows '-') and selected Java Project. Clicked on 'Next' Button.
4. Selected 'Create project from existing source' and clicked on 'Browse' button next to 'Directory' to open 'Jena-2.6.4' folder.
5. Clicked on 'Finish' Button. Now, you should be able to see 'Jena-2.6.4' folder in your sidebar under 'Navigator' tab.
6. Expand the folder (By clicking on + sign) to view the folders inside 'Jena-2.6.4' folder.



























































EXAMPLES


Some simple example java programs are given under Jena-2.6.4->src-examples->Jena->examples->rdf named as Tutorial<no.>.java. Each of these file content is explained at An Introduction to RDF and the Jena RDF API. However, to run all these tutorials successfully, we need few .rdf files called 'vc-db-1.rdf' that isn't included in the 
 downloaded folder.


  1. vc-db-1.rdf - An explanation of the content of this file is provided at SPARQL Tutorial - Data Formats.
  2. vc-db-3.rdf - An explanation of the content of this file is provided at A Programmer's Introduction to RDQL.

 Save the downloaded file in 'Jena-2.6.4' folder. After this, I could run Tutorial05.java, Tutorial07.java and Tutorial08.java without any issues. But, Tutorial06.java gives an error 'WARN [main] (RDFDefaultErrorHandler.java:36) ...' that I am unable to figure out.

Again, for Tutorial09.java, we need 'vc-db-3.rdf' and 'vc-db-4.rdf' files. 

2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete