在创建持久存储和模型并将RDF/XML文件解析到其中时,Redland库和用于Perl的RDF::Redland绑定都有很好的文档记录,例如here和here.
另一方面,我找不到任何关于如何从我的持久化存储中检索模型的示例,而且明显的方法不起作用。
这就是我创建商店的方式:
my $storage =
new RDF::Redland::Storage( "hashes", "test",
"new='yes',hash-type='bdb',dir='data'" )
or die "Failed to create RDF::Redland::Storage\n";
my $model = new RDF::Redland::Model( $storage, "" )
or die "Failed to create RDF::Redland::Model for storage\n";
my $uri = new RDF::Redland::URI("file:test.rdf");
my $parser = new RDF::Redland::Parser( "rdfxml", "application/rdf+xml" )
or die "Failed to find parser\n";
my $stream = $parser->parse_as_stream( $uri, $uri );
my $count = 0;
while ( !$stream->end ) {
$model->add_statement( $stream->current );
$count++;
$stream->next;
}
$stream = undef;
$storage = undef;
$model = undef;
print "Done. There were $count statements.\n";这是有效的,并通知我我有300k左右的语句。
然后,我尝试使用另一个脚本检索此数据:
my $storage =
new RDF::Redland::Storage( "hashes", "test",
"hash-type='bdb',dir='data'" )
or die "Failed to create RDF::Redland::Storage\n";
my $model = new RDF::Redland::Model( $storage, "" )
or die "Failed to create RDF::Redland::Model for storage\n";
$model->sync; # tried with and without this line
my $stream = $model->as_stream;
while ( !$stream->end ) {
print "Statement: ", $stream->current->as_string, "\n";
$stream->next;
}这绝对不会打印任何内容。
谢谢你的帮助!
发布于 2013-02-05 18:33:27
我找到了自己的问题的解决方案,我觉得自己在这上面浪费了这么多时间是非常愚蠢的。因此,如果这可以帮助其他人经历同样的地狱,那么它就在这里。
问题不在于检索商店,而在于保存它。这并不明显,因为这三个Berkeley DB文件加起来有366 MB。因此,在第一个脚本的末尾,就在对存储和模型执行undef之前,需要将它们与$model->sync同步。
就这样。
( Berkeley文件在此之后仍然保持完全相同的大小,但它可以正常工作。(不要问我为什么。)
https://stackoverflow.com/questions/14648799
复制相似问题