3

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?

ejang
  • 3,982
  • 8
  • 44
  • 70

1 Answers1

3
import RDF

parser=RDF.NTriplesParser()

for triple in parser.parse_as_stream("file:./mybigNTfile.nt"):
  print triple.subject, triple.predicate, triple.object
ejang
  • 3,982
  • 8
  • 44
  • 70
  • could you take a look on [this question](http://stackoverflow.com/questions/42493215/parse-rdf-file-python)? – StuartDTO Feb 27 '17 at 19:13