2013-02-06 4 views
3

꽤 오랫동안 혼란 스러웠지만 Raptor와 Redland Python Extensions를 사용하여 큰 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에 파일을 추가하려면 어떻게해야할까요?

답변

2
import RDF 

parser=RDF.NTriplesParser() 

for triple in parser.parse_as_stream("file:./mybigNTfile.nt"): 
    print triple.subject, triple.predicate, triple.object 
+0

[이 질문에] (http://stackoverflow.com/questions/42493215/parse-rdf-file-python)을 (를) 볼 수 있습니까? – Stuart2041