문제

The Redland library and the RDF::Redland bindings for Perl are very well documented when it comes to creating a persistent store and a model and parsing an RDF/XML file into it, for instance here and here.

On the other hand, I cannot find any example about how to retrieve the model from my persistent store, and the obvious way does not work.

This is how I created the store:

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";

This works and informs me that I have 300k-something statements.

Then I try to retrieve this data with another script:

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;
}

This prints absolutely nothing.

Thanks for any help!

도움이 되었습니까?

해결책

I found the solution to my own problem and I am feeling incredibly stupid losing so many hours over that. So if that can help someone else going through the same hell, here it is.

The problem is not in retrieving the store, it is in saving it. This wasn't obvious because the three Berkeley DB files weigh 366 MB together. So at the end of the first script, just before undef'ing the storage and the model, one needs to sync them with $model->sync.

That's it.

(And the Berkeley files are still exactly the same size after that, except it works. Don't ask me why.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top