[英]Create instance of classes of owl ontology and save them in rdf store
我使用Protege生成了OWL本體。 我想使用我的OWL本體並使用Jena創建RDF三元組以保存在三重存儲中。
我知道如何讀/寫RDF,但我不知道如何為那些OWL類創建實例。 例如:
我有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就是這樣的
<Person rdf:about="Jack">
<salary>1234</salary>
</Person>
您可以使用Jena Ontology API以編程方式創建實例。 有兩種方法可以做到這一點。 兩者都要求您提供OntClass
對象和OntModel
在OntClass
對象上調用createIndividual
方法。
OntClass class = ontModel.createClass( yourNamespace + "SomeClass" ); Individual instance = class.createIndividual( yourNamespace + "individual1");
在OntModel
對象上調用createIndividual
方法,並將OntClass
對象作為參數傳遞。
OntClass class = ontModel.createClass( yourNamespace + "SomeClass"); Individual individual = ontModel.createIndividual( yourNameSpace + "individual2", class);
有關更多信息,您可以訪問Jena Ontology API的官方教程
方法#1當您使用Jena或Sesame解析OWL時,您將在模型或圖形中以三元組的形式獲得貓頭鷹。 這些三元組可以存儲在三元組商店中。
方法#2您可以通過以三元組的形式創建實例來解決此問題。 以下是示例java代碼。 請注意,我沒有測試此代碼,這只是為了理解。
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 +”\\“/>”);
但我建議使用方法#1,因為你有一個OWL文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.