我对此相当困惑了一段时间,但我终于学会了如何使用Raptor和Redland Python扩展解析大型N-Triples RDF store (.nt)。
一个常见的示例是执行以下操作:
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,而不将其加载到模型或任何类似复杂的东西中,该怎么办?
发布于 2013-02-06 21:27:23
import RDF
parser=RDF.NTriplesParser()
for triple in parser.parse_as_stream("file:./mybigNTfile.nt"):
print triple.subject, triple.predicate, triple.objecthttps://stackoverflow.com/questions/14730255
复制相似问题