简体   繁体   English

创建owl本体类的实例并将它们保存在rdf存储中

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

I generated OWL ontology using Protege. 我使用Protege生成了OWL本体。 I want to use my OWL ontology and create the RDF triples to be saved in a triple store using Jena. 我想使用我的OWL本体并使用Jena创建RDF三元组以保存在三重存储中。

I know how to read/write RDF,but i dont know how to create instances for those OWL class(s). 我知道如何读/写RDF,但我不知道如何为那些OWL类创建实例。 For example: 例如:

sample OWL ontology I have 我有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>

RDF required is something like that 需要RDF就是这样的

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

You can create instances programmatically using the Jena Ontology API. 您可以使用Jena Ontology API以编程方式创建实例。 There are two ways this can be done. 有两种方法可以做到这一点。 Both require you to provide an OntClass object and an OntModel 两者都要求您提供OntClass对象OntModel

  1. Call the createIndividual method on an OntClass object. OntClass对象上调用createIndividual方法。

     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. OntModel对象上调用createIndividual方法,并将OntClass对象作为参数传递。

     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 有关更多信息,您可以访问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. 方法#1当您使用Jena或Sesame解析OWL时,您将在模型或图形中以三元组的形式获得猫头鹰。 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. 方法#2您可以通过以三元组的形式创建实例来解决此问题。 Following is the sample java code. 以下是示例java代码。 Please note that I did not test this code and this is just for understanding. 请注意,我没有测试此代码,这只是为了理解。

StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

sb.append(" xmlns:drug=\\" http://www.healthcare.com/patient/drug# \\""); 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(“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+"\\"/>"); 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. 但我建议使用方法#1,因为你有一个OWL文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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