RDF文件为excel可读格式 [英] RDF file to excel-readable format
问题描述
我下载了.ttl格式的rdf文件-我是RDF的新手,我试图查看是否可以以某种简单的txt/csv格式获取数据.有人知道该怎么做吗?
I downloaded an rdf file of the format .ttl - I am new to RDF and I am trying to see if I can get the data in a simple txt/csv format of some sort. Does anyone know how to do this?
推荐答案
RDF有一个非常简单的数据模型:只是subject
predicate
object
.您可以通过将文件转换为n-triples
来查看:
RDF has a very simple data model: it's just subject
predicate
object
. You can see this by converting your file to n-triples
:
$ rdfcopy myfile.ttl # apache jena
$ rapper -i turtle myfile.ttl # rapper (part of librdf)
但这是有限的.假设您从外观漂亮的乌龟文件开始:
But this is limited. Suppose you start with the nice looking turtle file:
@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> .
结果是:
<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> .
换句话说,所有内容都减少到三列.
In other words everything is reduced to three columns.
您可能更喜欢运行一个简单的sparql查询.它将为您提供更有用的表格结果:
You might prefer running a simple sparql query instead. It will give you tabular results of a more useful kind:
prefix ex: <http://example.com/>
select ?person ?age ?name
where {
?person ex:age ?age ;
ex:name ?name .
}
使用apache jena的arq进行运行:
Running that using apache jena's arq:
$ arq --data myfile.ttl --query query.rq
---------------------------------
| person | age | name |
=================================
| <Delia> | 45 | "Delia Jones" |
| <Brian> | 34 | "Brian Smith" |
---------------------------------
这可能更有用. (您也可以通过添加--results csv
来指定CSV输出.)
which is probably more useful. (You can specify CSV output too by adding --results csv
).
(相当于librdf是roqet query.rq --data myfile.ttl -r csv
)
(The librdf equivalent is roqet query.rq --data myfile.ttl -r csv
)
这篇关于RDF文件为excel可读格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!