Gita
Gita

Reputation: 159

How to process a .ttl file of 3 attributes using rdflib (python 3.x)?

I have a .ttl file which consists of 3 attributes.

Ex: <http://dbpedia.org/resource/James_B._McLeran> <http://www.w3.org/2000/01/rdf-schema#label> "James B. McLeran"@en .

How can I parse and store these attributes using RDFlib?

Expected output: subject = <http://dbpedia.org/resource/James_B._McLeran>
                 predicate = <http://www.w3.org/2000/01/rdf-schema#label>
                 object = "James B. McLeran"@en .

Upvotes: 2

Views: 1106

Answers (1)

Shreyas Nagare
Shreyas Nagare

Reputation: 21

from rdflib import Graph

g = Graph()

g.parse("http://downloads.dbpedia.org/something.ttl", format="turtle")

for triple in g:
    print(
        """
        subject = {}
        predicate = {}
        object = {}
        """.format(*triple)
    )

Upvotes: 1

Related Questions