通过流解析N-Triples
问题描述:
我对此有些困惑了一段时间,但我终于学会了如何使用Raptor和Redland Python扩展来解析大型N-Triples RDF存储(.nt)。通过流解析N-Triples
一个常见的例子是做到以下几点:默认加载的对象
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()到内存中,所以如果你解析一个大的文件,你可以考虑使用HashStorage作为你的模型和序列化就这样。
但是,如果你只想读取文件并说,将其添加到MongoDB而不加载到模型或任何类似的复杂?
答
import RDF
parser=RDF.NTriplesParser()
for triple in parser.parse_as_stream("file:./mybigNTfile.nt"):
print triple.subject, triple.predicate, triple.object
你可以看看[这个问题](http://*.com/questions/42493215/parse-rdf-file-python)? – Stuart2041