简体   繁体   English

使用定义的OWL本体创建RDF

[英]create RDF using defined OWL ontology

I'm generating RDF for a database table(s). 我正在为数据库表生成RDF。 I generated OWL ontology for the table(s) using Protégé. 我使用Protégé为表生成了OWL本体。 I want to use this OWL ontology and create the RDF in RDF/XML format for table data using Jena. 我想使用该OWL本体并使用Jena为表数据创建RDF / XML格式的RDF。 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. 我知道如何将RDF和OWL文件读写到内存中以生成模型,并且知道如何使用Resource,Property,ModelFactory等类生成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). 我无法做的是使用生成的本体(OWL文件)并为那些OWL类创建RDF实例。 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: 所需的RDF:

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

I'm able to generate RDF like this: 我能够生成如下RDF:

<rdf:Description rdf:about="Jack">
  <ns:salary>2004</ns:salary>
</rdf:Description>

What you want is a so called RDB2RDF mapper. 您需要一个所谓的RDB2RDF映射器。 Try D2RQ , a Java-based RDB2RDF mapper, for example. 尝试D2RQ ,一个基于Java的RDB2RDF映射器,例如。

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. 免责声明:我是W3C RDB2RDF工作组的联合主席,并且我的组为D2RQ的开发做出了巨大的贡献-还提供了许多其他使用各种语言的实现

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). 所需输出与现在正在创建的输出之间的唯一区别是存在Triple :Jack rdf:type :Person (并且,如果需要,可以定义默认名称空间,这样就不需要ns:前缀了)在您的XML元素上)。

Starting with your RDF 从您的RDF开始

<rdf:Description rdf:about="Jack">
  <ns:salary>2004</ns:salary>
</rdf:Description>

and adding the triple Jack rdf:type Person , you would have 并添加三重Jack rdf:type Person ,您将拥有

<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; RDF / XML规范允许rdf:type三元组的简写rdf:type if the URI for the type can be shorted to an XML name, then it can be used as the element name. 如果该类型的URI可以缩写为XML名称,则可以将其用作元素名称。 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. 如果是这样, PrefixMapping#setNsPrefix需要使用PrefixMapping#setNsPrefix来设置前缀。 ( Model implements PrefixMapping .) Model实现PrefixMapping 。)

model.setNsPrefix( "", "http://yourontologies.com/thisOntology#" );

and you'll get 你会得到的

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

when you serialize the model. 当您序列化模型时。

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

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