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>
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With