解析大型NTriples文件Python

2024-06-07 19:01:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用Parse large RDF in Python中的代码解析一个相当大的NTriples文件

我为python安装了raptor和redland绑定。在

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

但是程序挂起了,我怀疑它试图将整个文件加载到内存中或其他原因,因为它不能立即启动。在

有人知道怎么解决这个问题吗?在


Tags: 文件代码nameinparserformodelparse
1条回答
网友
1楼 · 发布于 2024-06-07 19:01:03

它的速度很慢,因为你正在向内存存储区中读取数据(RDF.型号()默认值)没有索引。所以它变得越来越慢。对N-Triples的解析确实是从文件中流出来的,它从不把它全部吸收到内存中。在

有关存储模型的概述,请参见Redland storage modules documentation。在这里,您可能需要存储type“哈希”和hash-type内存。在

s = RDF.HashStorage("abc", options="hash-type='memory'")
model = RDF.Model(s)

(未测试)

相关问题 更多 >

    热门问题