使用耶拿(Jena)从CSV文件填充现有本体 [英] populate an existing ontology from a csv file using Jena
问题描述
如何使用耶拿(Jena)读取本体(猫头鹰文件)并从CSV文件填充该本体(ontModel),然后将填充的OntModel写入OWL文件
How to read an ontology (owl file) using jena and populate this ontology (ontModel) from a CSV file then write the populated OntModel into OWL file
推荐答案
您的问题分为三个部分:
There are three parts to your question:
- 将OWL文件读取到耶拿
Model
- 将CSV文件转换为RDF
- 将耶拿
Model
的内容写到文件中
- reading an OWL file into a Jena
Model
- converting a CSV file into RDF
- writing the contents of a Jena
Model
out to a file
使用Jena可以轻松实现第一个和第三个(请参阅Model.read()
和Model.write()
方法,以及FileManager
以获得一些从其他位置读取的便利性).
The first and third of these are easy with Jena (see Model.read()
and Model.write()
methods, and the FileManager
for some additional convenience support for reading from different locations).
第二部分是棘手的部分.通常,将CSV文件转换为RDF时,我们假设每一行代表一个RDF资源及其属性.您需要完成三个任务:
The second part is the tricky one. Typically, when converting a CSV file to RDF, we assume that each row represents one RDF resource and its properties. You have three tasks to achieve:
- 根据数据行中的某些键确定代表资源的URI
- 确定表示给定列值的RDF属性的URI
- 将每个列值映射到适当的资源URI或文字值.
例如,考虑以下CSV:
For example, consider the following CSV:
id,name,age,occupation
2718,fred,107,ninja
我们可以使用CSV的第一行来建议RDF谓词名称.对于前两列,foaf:name
和foaf:age
是适当的选择,但是对于第三列http://example.com/vocab#occupation
,我们可能需要在命名空间中使用新的谓词.资源URI将基于数据的任何键(在本例中为id
列),这表明第一行所表示的资源的URI将为http://example.com/data/employee/2718
.最后,我们必须映射数据.名称只是一个字符串,年龄是一个整数,职业是一种资源.有了这些选择,我们可能最终得到如下输出:
We can use the first row of the CSV to suggest RDF predicate names. foaf:name
and foaf:age
would be appropriate choices for the first two columns, but we may need a new predicate in our namespace for the third column http://example.com/vocab#occupation
. The resource URI will be based on whatever the key is for the data, in this case the id
column, suggesting that the URI for the resource denoted by the first row will be http://example.com/data/employee/2718
. Finally we have to map the data. The name is just a string, the age is an integer and the occupation is a resource. Given those choices, we may end up with output like:
<http://example.org/data/employee/2718>
a foaf:Person;
foaf:name "fred";
foaf:age "107"^^xsd:integer;
example_com:occupation <http://dbpedia.org/resource/Ninja>.
W3C工作草案 R2RML 定义了用于执行此类翻译的标准化映射语言.提供了各种 R2RML的实现.当然,如果您的映射相当稳定,那么只需编写一些代码以针对特定的输入数据执行CSV转换就可以非常简单地完成
The W3C working draft R2RML defines a standardised mapping language for performing these kinds of translations. Various implementations of R2RML are available. Of course, if your mapping is fairly stable it would be perfectly straightforward just to write some code to perform the translation from CSV for your particular input data.
这篇关于使用耶拿(Jena)从CSV文件填充现有本体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!