Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing N-Triples Via Streaming

I was fairly confused about this for some time but I finally learned how to parse a large N-Triples RDF store (.nt) using Raptor and the Redland Python Extensions.

A common example is to do the following:

import RDF
parser=RDF.Parser(name="ntriples")
model=RDF.Model()
stream=parser.parse_into_model(model,"file:./mybigfile.nt")
for triple in model:
    print triple.subject, triple.predicate, triple.object

Parse_into_model() by default loads the object into memory, so if you are parsing a big file you could consider using a HashStorage as your model and serializing it that way.

But what if you want to just read the file and say, add it to MongoDB without loading it into a Model or anything complicated like that?

like image 309
ejang Avatar asked Sep 07 '25 09:09

ejang


1 Answers

import RDF

parser=RDF.NTriplesParser()

for triple in parser.parse_as_stream("file:./mybigNTfile.nt"):
  print triple.subject, triple.predicate, triple.object
like image 88
ejang Avatar answered Sep 10 '25 03:09

ejang