4

I'm generating RDF for a database table(s). I generated OWL ontology for the table(s) using Protégé. I want to use this OWL ontology and create the RDF in RDF/XML format for table data using Jena. I know how to read and write RDF and OWL files into memory to generate Models, and I know how to use Resource, Property, ModelFactory, etc., classes to generate RDF. What I'm unable to do is use the ontology (OWL file) I generated and create the RDF instances for those OWL class(s). For example:

sample OWL:

<owl:Class rdf:about="Person"/>
<owl:Class rdf:about="Animal"/>

<owl:DatatypeProperty rdf:about="salary">
    <rdfs:domain rdf:resource="Person"/>
    <rdfs:range rdf:resource="&xsd;real"/>
</owl:DatatypeProperty>

desired RDF:

<Person rdf:about="Jack">
  <salary>1234</salary> 
</Person>

I'm able to generate RDF like this:

<rdf:Description rdf:about="Jack">
  <ns:salary>2004</ns:salary>
</rdf:Description>
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Hari Gudigundla
  • 812
  • 10
  • 20
  • actually i dont understand what you want. Do you want to create individuals using your ontology? – Çağdaş Feb 14 '12 at 20:20
  • I'm not aware of 'individual' concept. I'll check that and get back to you. Thanks. – Hari Gudigundla Feb 14 '12 at 20:45
  • In your example, "Jack" is an individual. Also, what exactly are you trying to accomplish? You seem a bit confused about the distinctions between RDF & OWL, so perhaps if you describe what you want to achieve, we might be able to give you more directed information. – Michael Feb 14 '12 at 20:50
  • @Michael I'm trying to generate RDF/XML for the database table data as mentioned above. So I need to use the ontology and create individuals (probably each for each row in the table). – Hari Gudigundla Feb 14 '12 at 21:01
  • @Michael I'm able to create individual(s) and add properties to them. But when I try to serialize them using write() method, it's serializing the whole OWL ontology along with the individuals. As I already have an ontology I would like to serialize the individuals I create. Any help on this. – Hari Gudigundla Feb 14 '12 at 21:32
  • Are you using a relational database? – Michael Feb 16 '12 at 15:08

2 Answers2

7

What you want is a so called RDB2RDF mapper. Try D2RQ, a Java-based RDB2RDF mapper, for example.

Disclaimer: I'm co-chair of the W3C RDB2RDF Working Group and my group is heavily contributing to the development of D2RQ - there are a number of other implementations in various languages available as well.

Michael Hausenblas
  • 13,162
  • 4
  • 52
  • 66
3

The only difference between your desired output and the output that you are creating now is the presence of the triple :Jack rdf:type :Person (and, if you desire, defining the default namespace so that you don't need the ns: prefix on your XML elements).

Starting with your RDF

<rdf:Description rdf:about="Jack">
  <ns:salary>2004</ns:salary>
</rdf:Description>

and adding the triple Jack rdf:type Person, you would have

<rdf:Description rdf:about="Jack">
  <rdf:type rdf:resource="Person"/>
  <ns:salary>2004</ns:salary>
</rdf:Description>

The RDF/XML specification allows for a shorthand notation for rdf:type triples; if the URI for the type can be shorted to an XML name, then it can be used as the element name. Using this shorthand, you have

<ns:Person rdf:about="Jack">
  <ns:salary>2004</ns:salary>
</ns:Person>

which is your desired output, unless the prefix is really important. If it is, then you just need to use PrefixMapping#setNsPrefix to set a prefix. (Model implements PrefixMapping.)

model.setNsPrefix( "", "http://yourontologies.com/thisOntology#" );

and you'll get

<Person rdf:about="Jack">
  <salary>2004</salary>
</Person>

when you serialize the model.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353