Reputation: 31
I generated OWL ontology using Protege. I want to use my OWL ontology and create the RDF triples to be saved in a triple store using Jena.
I know how to read/write RDF,but i dont know how to create instances for those OWL class(s). For example:
sample OWL ontology I have
<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>
RDF required is something like that
<Person rdf:about="Jack">
<salary>1234</salary>
</Person>
Upvotes: 3
Views: 7565
Reputation: 799
Approach #1 When you parse OWL using Jena or Sesame, you'll get the owl in form of triples in either a Model or a Graph. And these triples can be stored in a triplet store.
Approach #2 You can solve this problem by creating the instances in the form of triples. Following is the sample java code. Please note that I did not test this code and this is just for understanding.
StringBuilder sb = new StringBuilder();
sb.append(" xmlns:drug=\"http://www.healthcare.com/patient/drug#\""); sb.append(" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"");
sb.append("compliance:treatmensub rdf:resource=\"http://www.healthcare.com/patient/drug##id_pa_"+id+"pr"+"_"+drugname+"\"/>");
but I suggest approach #1 to follow as you have an OWL file.
Upvotes: 2
Reputation: 18543
You can create instances programmatically using the Jena Ontology API. There are two ways this can be done. Both require you to provide an OntClass
object and an OntModel
Call the createIndividual
method on an OntClass
object.
OntClass class = ontModel.createClass( yourNamespace + "SomeClass" );
Individual instance = class.createIndividual( yourNamespace + "individual1");
Call the createIndividual
method on an OntModel
object and pass an OntClass
object as an argument.
OntClass class = ontModel.createClass( yourNamespace + "SomeClass");
Individual individual = ontModel.createIndividual( yourNameSpace + "individual2", class);
For more information, you can visit the official tutorial for Jena Ontology API
Upvotes: 5