NAME
RDF::Trine::Store::File - Using a file with N-Triples as triplestore
VERSION
Version 0.1
SYNOPSIS
To be used as a normal triple store.
my $store = RDF::Trine::Store::File->new($filename);
$store->add_statement(RDF::Trine::Statement->new(
RDF::Trine::Node::Resource->new('http://example.org/a'),
RDF::Trine::Node::Resource->new('http://example.org/b'),
RDF::Trine::Node::Resource->new('http://example.org/c')
));
...
METHODS
new($filename)
A constructor, takes a filename as parameter. If the file doesn't exist, it will be created.
new_with_string('File;'.$filename)
A constructor, takes a string config as parameter. If the file doesn't exist, it will be created. The string will typically begin with File;
, e.g.
my $store = RDF::Trine::Store::File->new_with_string('File;/path/to/file.nt');
new_with_config({ storetype => 'File', file => $filename});
A constructor, takes a hashref config as parameter. If the file doesn't exist, it will be created. It needs to have a storetype
key with File
as the value, e.g.
my $store = RDF::Trine::Store::File->new_with_config({ storetype => 'File', file => $filename});
temporary_store
Constructor that creates a temporary file to work on.
add_statement($statement)
Adds the specified $statement
to the underlying model.
get_statements($subject, $predicate, $object)
Returns a stream object of all statements matching the specified subject, predicate and objects. Any of the arguments may be undef to match any value.
count_statements($subject, $predicate, $object)
Returns a count of all the statements matching the specified subject, predicate and objects. Any of the arguments may be undef to match any value.
remove_statement($statement)
Removes the specified $statement
from the underlying model.
remove_statements($subject, $predicate, $object)
Removes all statement matching the specified subject, predicate and objects. Any of the arguments may be undef to match any value.
get_contexts
Contexts are not supported for this store.
size
Returns the number of statements in the store. Breaks if there are comments or empty lines in the file.
etag
Returns an etag based on the last modification time of the file. Note: This has resolution of one second, so it cannot be relied on for data that changes fast.
nuke
Permanently removes the store file and its data.
DISCUSSION
This module is intended mostly as a simple backend to dump data to a file and do as little as possible in memory. Thus, it is mostly suitable in cases where a lot of data is written to file. It should be possible to use it as a SPARQL store with RDF::Query, but the performance is likely to be somewhere between terrible and abyssmal, so don't do that unless you are prepared to be waiting around.
On the good side, adding statements should be pretty fast, as it just appends to a file. The size
method should be pretty fast too, as it just counts the lines in that file. Finally, it supports the etag
method, not perfectly, but that's still pretty good!
It uses a lot of heuristics tied to the format chosen, i.e. N-Triples. That's a line-based format, with predictable amounts of whitespace, allowing us to create relatively simple regular expressions as search patterns in the file. This is likely to be somewhat fragile (it is making assumptions about the file that is true in the RDF::Trine::Serializer::Ntriples case, but not in the format), but it kinda works.
It is important to note that this module does nothing to prevent you from adding duplicate statements like other stores should do. This is because it would dramatically reduce add_statement
performance and thus kill the main use case for this module. Perhaps it could be made optional at some point, but for now, just be aware that this may not always return the right counts if two identical statements are inserted and possibly produce unexpected results if you against the advice above should attempt to use this a store for SPARQL.
I've decided to use File::Data to actually do the work with the file. Locking and that kind of stuff is done there and is thus Not My Problem. If it is yours, then File::Data is probably the right place to go and fix it.
TODO
This is beta-quality software but it has a pretty comprehensive test suite. These are some things that could be done:
Support bulk operations (somewhat less important)
Find a way to do duplicate checking efficiently
AUTHOR
Kjetil Kjernsmo, <kjetilk at cpan.org>
BUGS
Please report any bugs or feature requests to bug-rdf-trine-store-file at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RDF-Trine-Store-File. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc RDF::Trine::Store::File
The perlrdf mailing list is the right place to seek help and discuss this module:
http://lists.perlrdf.org/listinfo/dev
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=RDF-Trine-Store-File
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
LICENSE AND COPYRIGHT
Copyright 2011 Kjetil Kjernsmo.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.