我下载了格式为.ttl的rdf文件 - 我是RDF的新手,我正在尝试查看是否可以使用某种简单的txt/csv格式获取数据.有谁知道如何做到这一点?
RDF有一个非常简单的数据模型:它只是subject
predicate
object
.您可以通过将文件转换为n-triples
以下内容来查看:
$ rdfcopy myfile.ttl # apache jena
$ rapper -i turtle myfile.ttl # rapper (part of librdf)
Run Code Online (Sandbox Code Playgroud)
但这是有限的.假设您从漂亮的乌龟文件开始:
@prefix ex: <http://example.com/>
<Brian> ex:age 34 ;
ex:name "Brian Smith" ;
ex:homepage <http://my.name.org/Brian> .
<Delia> ex:age 45 ;
ex:name "Delia Jones" ;
ex:email <mailto:delia@deliajones.com> .
Run Code Online (Sandbox Code Playgroud)
结果是:
<file:///tmp/Delia> <http://example.com/email> <mailto:delia@deliajones.com> .
<file:///tmp/Delia> <http://example.com/name> "Delia Jones" .
<file:///tmp/Delia> <http://example.com/age> "45"^^<http://www.w3.org/2001/XMLSchema#integer> .
<file:///tmp/Brian> <http://example.com/homepage> <http://my.name.org/Brian> .
<file:///tmp/Brian> <http://example.com/name> "Brian Smith" .
<file:///tmp/Brian> <http://example.com/age> "34"^^<http://www.w3.org/2001/XMLSchema#integer> .
Run Code Online (Sandbox Code Playgroud)
换句话说,一切都减少到三列.
您可能更喜欢运行简单的sparql查询.它将为您提供更有用的表格结果:
prefix ex: <http://example.com/>
select ?person ?age ?name
where {
?person ex:age ?age ;
ex:name ?name .
}
Run Code Online (Sandbox Code Playgroud)
使用apache jena的arq运行它:
$ arq --data myfile.ttl --query query.rq
---------------------------------
| person | age | name |
=================================
| <Delia> | 45 | "Delia Jones" |
| <Brian> | 34 | "Brian Smith" |
---------------------------------
Run Code Online (Sandbox Code Playgroud)
这可能更有用.(您也可以通过添加来指定CSV输出--results csv
).
(librdf等价物是roqet query.rq --data myfile.ttl -r csv
)