RDF::Trine::Store::File - Using a file with N-Triples as triplestore
Version 0.1
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') )); ...
A constructor, takes a filename as parameter. If the file doesn't exist, it will be created.
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.
File;
my $store = RDF::Trine::Store::File->new_with_string('File;/path/to/file.nt');
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.
storetype
File
my $store = RDF::Trine::Store::File->new_with_config({ storetype => 'File', file => $filename});
Constructor that creates a temporary file to work on.
Adds the specified $statement to the underlying model.
$statement
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.
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.
Removes the specified $statement from the underlying model.
Removes all statement matching the specified subject, predicate and objects. Any of the arguments may be undef to match any value.
Contexts are not supported for this store.
Returns the number of statements in the store. Breaks if there are comments or empty lines in the file.
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.
Permanently removes the store file and its data.
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!
size
etag
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.
add_statement
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.
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
Kjetil Kjernsmo, <kjetilk at cpan.org>
<kjetilk at cpan.org>
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.
bug-rdf-trine-store-file at rt.cpan.org
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
http://annocpan.org/dist/RDF-Trine-Store-File
CPAN Ratings
http://cpanratings.perl.org/d/RDF-Trine-Store-File
Search CPAN
http://search.cpan.org/dist/RDF-Trine-Store-File/
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.
To install RDF::Trine::Store::File, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RDF::Trine::Store::File
CPAN shell
perl -MCPAN -e shell install RDF::Trine::Store::File
For more information on module installation, please visit the detailed CPAN module installation guide.