Let's talk about exceptions ...
How do you handle exceptions? Do you think upfront about the type of exceptions that you want to catch or do you just let the outside world handle it?

-- Jeroen van Bergen in JW Blogs

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Easily maintain RDF metadata models

Use scripts developed with the Jena RDF API to manage Resource Description Framework models

Similarly to how XML became the well-known standard adapted by many software vendors for data exchange, Resource Description Framework (RDF) is going in the same direction for describing and interchanging metadata. XML describes data using a document type definition (DTD) or an XML Schema Definition (XSD). RDF uses XML syntax and RDF Schema (RFDS) to describe the metadata as a data model.

This article explains how to use custom utilities developed with the Jena RDF API for managing RDF models stored in either a relational database or a file. Developed by HP Labs, the Jena framework is an open source implementation of RDF, RDFS, and OWL (Web Ontology Language) and includes a rule-based inference engine. It provides a Java API for creating and manipulating RDF models. In this article, I introduce SemanticRDFUtils.bat, a script developed with Jena that includes several tasks for maintaining Jena RDF metadata models stored in a relational database or a flat file. This article also explains how to use Prot�g� for creating semantic RDF files that include the schema (.rdfs) and the data file (.rdf).

Software installation

The following software must be installed before using SemanticRDFUtils.bat. Links to these tools are included in Resources.

  • J2SE 1.3 or a more recent version
  • Jena 2.0
  • Oracle 9.2.0.1.0
  • Apache Ant 1.5.4 or a more recent version
  • Prot�g� 2.1

A quick look at RDF and RDFS files

The following XML listings show the RDF and RDFS files for a sample alphabet cross reference model. They were created using the Prot�g� 2.1 GUI tool. The RDF file can be used as input while running the scripts and RDF query tool. The RDFS file is useful when you work with Prot�g� to add more data to the RDF file.

Listing 1. RDFTest1.rdf

                        <?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE rdf:RDF [
   <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
   <!ENTITY rdfs 'http://www.w3.org/TR/1999/PR-rdf-schema-19990303#'>
   <!ENTITY Maana 'http://www.vvasam.com/Maana#'>
]>
<rdf:RDF xmlns:rdf=""
   xmlns:Maana=""
   xmlns:rdfs="">
<Maana:ASCII rdf:about="RDFTest_Instance_0"
   Maana:Name="A"
   Maana:value="65"
   rdfs:label="A:65">
   <Maana:system rdf:resource="RDFTest_Instance_2"/>
</Maana:ASCII>
<Maana:System rdf:about="RDFTest_Instance_1"
   Maana:Name="lowercase"
   rdfs:label="lowercase"/>
<Maana:ASCII rdf:about="RDFTest_Instance_10000"
   Maana:Name="b"
   Maana:value="98"
   rdfs:label="b:98">
   <Maana:system rdf:resource="RDFTest_Instance_1"/>
</Maana:ASCII>
<Maana:ASCII rdf:about="RDFTest_Instance_10001"
   Maana:Name="B"
   Maana:value="66"
   rdfs:label="B:66">
   <Maana:system rdf:resource="RDFTest_Instance_2"/>
</Maana:ASCII>
<Maana:AscXRef rdf:about="RDFTest_Instance_10002"
   rdfs:label="b:98:B:66">
   <Maana:keyName rdf:resource="RDFTest_Instance_10000"/>
   <Maana:keyValue rdf:resource="RDFTest_Instance_10001"/>
</Maana:AscXRef>
<Maana:AscXRef rdf:about="RDFTest_Instance_10005"
   rdfs:label="a:97:A:65">
   <Maana:keyValue rdf:resource="RDFTest_Instance_0"/>
   <Maana:keyName rdf:resource="RDFTest_Instance_8"/>
</Maana:AscXRef>
<Maana:System rdf:about="RDFTest_Instance_2"
   Maana:Name="uppercase"
   rdfs:label="uppercase"/>
<Maana:ASCII rdf:about="RDFTest_Instance_8"
   Maana:Name="a"
   Maana:value="97"
   rdfs:label="a:97">
   <Maana:system rdf:resource="RDFTest_Instance_1"/>
</Maana:ASCII>
</rdf:RDF>
                   


Listing 2. RDFTest1.rdfs

                        <?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE rdf:RDF [
   <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
   <!ENTITY system 'http://protege.stanford.edu/system#'>
   <!ENTITY Maana 'http://www.vvasam.com/Maana#'>
   <!ENTITY rdfs 'http://www.w3.org/TR/1999/PR-rdf-schema-19990303#'>
]>
<rdf:RDF xmlns:rdf=""
   xmlns:system=""
   xmlns:rdfs=""
   xmlns:Maana="">
<rdf:Property rdf:about="maxCardinality"
   rdfs:label="system:maxCardinality"/>
<rdf:Property rdf:about="minCardinality"
   rdfs:label="system:minCardinality"/>
<rdf:Property rdf:about="range"
   rdfs:label="system:range"/>
<rdfs:Class rdf:about="ASCII"
   rdfs:label="ASCII">
   <rdfs:subClassOf rdf:resource="Resource"/>
</rdfs:Class>
<rdfs:Class rdf:about="AscXRef"
   rdfs:label="AscXRef">
   <rdfs:subClassOf rdf:resource="Resource"/>
</rdfs:Class>
<rdf:Property rdf:about="Name"
   rdfs:label="Name">
   <rdfs:domain rdf:resource="ASCII"/>
   <rdfs:domain rdf:resource="System"/>
   <rdfs:range rdf:resource="Literal"/>
</rdf:Property>
<rdf:Property rdf:about="RDFTest_Slot_10003"
   rdfs:label="RDFTest_Slot_10003">
   <rdfs:range rdf:resource="Literal"/>
</rdf:Property>
<rdfs:Class rdf:about="System"
   rdfs:label="System">
   <rdfs:subClassOf rdf:resource="Resource"/>
</rdfs:Class>
<rdf:Property rdf:about="keyName"
   rdfs:label="keyName">
   <rdfs:range rdf:resource="ASCII"/>
   <rdfs:domain rdf:resource="AscXRef"/>
</rdf:Property>
<rdf:Property rdf:about="keyValue"
   rdfs:label="keyValue">
   <rdfs:range rdf:resource="ASCII"/>
   <rdfs:domain rdf:resource="AscXRef"/>
</rdf:Property>
<rdf:Property rdf:about="system"
   rdfs:label="system">
   <rdfs:domain rdf:resource="ASCII"/>
   <rdfs:range rdf:resource="System"/>
</rdf:Property>
<rdf:Property rdf:about="value"
   rdfs:label="value">
   <rdfs:domain rdf:resource="ASCII"/>
   <rdfs:range rdf:resource="Literal"/>
</rdf:Property>
</rdf:RDF>
                   


Overview of Jena and Prot�g�

The following sections give a high-level overview of Jena and Prot�g�. You can get more detailed information on both products from the links in Resources. For this article's purposes, I expect you already have a good understanding of Jena and Prot�g�.

Jena RDF and RDQL

The RDF data model is a collection of statements, with each statement consisting of three parts: resource, property, and value. The resource can be anything that can be identified by a URI and it can have properties. Each property contains its own values. A property, value, and statement can be a resource and have their own properties and values.

Jena persists the RDF model in either a database or a file. RDQL is query language for querying the RDF model. RDF provides a graph with directed edges where the nodes can be either resources or literals. RDQL offers a way of specifying a graph pattern that is matched against the graph to yield a set of matches. Figure 1 shows the RDF graph representation of the files shown in Listings 1 and 2.

Discuss

Start a new discussion or jump into one of the threads below:

Subject Replies Last post
. VZcgVCStKugDYkYZwww
By asdkjhuewr32
0 04/21/08 06:37 AM
by Anonymous
. RiFnvFIGgIdDaFn
By asdkjhuewr23
0 04/17/08 07:10 AM
by Anonymous
. fBGSbuKBTA
By asdkjhuewr23
0 04/17/08 05:42 AM
by Anonymous
. YKIBGwaVMIn
By asdkjhuewr23
0 04/17/08 04:57 AM
by Anonymous
. DPheDbqvYIEA
By abramoviesi
0 04/13/08 04:24 PM
by Anonymous
. SqrKOUyygJOtF
By abramoviesi
0 04/13/08 03:43 PM
by Anonymous
. GgzMnfYYzPPlcoPzpCS
By abramoviesi
0 04/13/08 03:03 PM
by Anonymous
. jkHmJqtLxqoNf
By mypicst
0 04/12/08 09:24 AM
by Anonymous
. CfnrKmCpWIRPGG
By Memmorium
0 04/11/08 11:55 AM
by Anonymous
. YjAjrGIdKxMqCsT
By zxevil175
0 04/02/08 09:17 AM
by Anonymous
. Easily maintain RDF metadata models
By JavaWorld
0 07/01/05 04:45 PM
by JavaWorld


Resources