简体   繁体   中英

Create instance of classes of owl ontology and save them in rdf store

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>

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

  1. Call the createIndividual method on an OntClass object.

     OntClass class = ontModel.createClass( yourNamespace + "SomeClass" ); Individual instance = class.createIndividual( yourNamespace + "individual1"); 
  2. 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM