Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python library/code to parse .nt files from dbpedia

I want to parse the dbpedia data which is present in .nt format(N-Tuples). I have downloaded the .nt file and is there in my local disk.

For example, I want to find out all entities and their homepages.

I want to do it python. Right now the only way I could do is to do a grep, or iterate over all lines and select the ones which I want. Are there any good libraries which will allow me to do this?

I looked at RDFLib. But all the examples tell you how to write or create .nt format and not read from them.

like image 950
Sudar Avatar asked Jul 23 '26 12:07

Sudar


1 Answers

From the rdflib docs.:

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

your just needed the format= kwarg.

like image 64
Phil Cooper Avatar answered Jul 25 '26 01:07

Phil Cooper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!