RDF file to excel-readable format

浪子不回头ぞ 提交于 2019-12-08 00:25:47

问题


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?


回答1:


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> .

The result is:

<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.

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 .
}

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" |
---------------------------------

which is probably more useful. (You can specify CSV output too by adding --results csv).

(The librdf equivalent is roqet query.rq --data myfile.ttl -r csv)



来源:https://stackoverflow.com/questions/28944528/rdf-file-to-excel-readable-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!