how to modelize a foaf file

378 views Asked by At

I'm doing my master thesis and I'm working in serval files which most of them have a csv extension .

I have also a foaf file and I have no idea how to modelize and read this kind of file. What should I do?

1

There are 1 answers

7
Roman Susi On

It is a little bit problematic to save RDF data (which "FOAF file" actually is) into some table-like file without sacrificing semantics, because RDF is richer format and converting to CSV is in a way "lossy".

Below is a Python script for naive conversion of RDF into CSV, where each RDF triple is mapped into CSV row (install rdflib library before trying this):

from rdflib import Graph
import csv

g = Graph()
g.parse('http://www.w3.org/People/Berners-Lee/card.rdf', format='xml')

with open('card.csv', 'wb') as csvfile:
    writer = csv.writer(csvfile)
    for triple in g:
        writer.writerow(triple)

To make more sense from RDF one should use some query language and write query (for example, in SPARQL) exactly for the data, which is desired from the RDF file.

Another question/answer which might help you: RDF file to excel-readable format (ttl is another encoding of RDF: RDF/Turtle )