Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse .ttl files with RDFLib?

I have a file in .ttl form. It has 4 attributes/columns containing quadruples of the following form:

  1. (id, student_name, student_address, student_phoneno).
  2. (id, faculty_name, faculty_address, faculty_phoneno).

I know how to parse .n3 form triples with RDFLib;

from rdflib import Graph
g = Graph()
g.parse("demo.nt", format="nt")

but I am not sure as to how to parse these quadruples.

My intent is to parse and extract all the information pertaining to a particular id. The id can be same for both student and faculty.

How can I use RDFLib to process these quadruples and use it for aggregation based on id?

Example snippet from .ttl file:

#@ <id1>
<Alice> <USA> <12345>

#@ <id1>
<Jane> <France> <78900>
like image 213
Keira Shaw Avatar asked Mar 02 '13 07:03

Keira Shaw


People also ask

How do I read a TTL file?

If you cannot open your TTL file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a TTL file directly in the browser: Just drag the file onto this browser window and drop it.

What is RDFLib in Python?

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information. This library contains parsers/serializers for almost all of the known RDF serializations, such as RDF/XML, Turtle, N-Triples, & JSON-LD, many of which are now supported in their updated form (e.g. Turtle 1.1).


1 Answers

Looks like turtle is supported at least as of rdflib 5.0.0. I did

from rdflib import Graph
graph = Graph()
graph.parse('myfile.ttl', format='ttl')

This parsed in just fine.

like image 69
labyrinth Avatar answered Sep 18 '22 09:09

labyrinth