Updated support for quads in RDF::Trine
Gregory Williams
greg at evilfunhouse.com
Mon Jan 18 00:20:08 CET 2010
I've recently been working on bringing some sanity to supporting quads in RDF::Trine. I'm not sure how much anyone is using quads in the current RDF::Trine, but it's done pretty half-heartedly and I've tried to make changes to make the support more consistent and predictable.
So far, this is what I've done:
I've added a new nil-valued (singleton) Node class that is meant to be used in the graph/context slot of a quad that doesn't otherwise have such a value (when up-casting a triple to a quad, the graph/context is this new nil value). When viewing a store from the perspective of SPARQL, statements with a nil-valued graph/context slot can be considered as part of the "default graph".
I've updated the semantics of the following methods in RDF::Trine::Store classes: get_statements, count_statements, add_statement, and remove_statement. Here's what each does now:
GETTING STATEMENTS:
get_statements( s, p, o, g ) returns all quads (s,p,o,g). Note that any of the arguments can be undef as long as the count of arguments is 4. undef arguments will be interpreted as if they were variable nodes.
Both get_statements() and get_statements( s, p, o ) return quads (s,p,o,nil) for all distinct (s,p,o). I'm not sure about the variant with no arguments: maybe it should instead follow the quad semantics? Thoughts?
COUNTING STATEMENTS:
count_statements( s, p, o, g ) returns the count of (distinct) quads in the store.
Both count_statements() and count_statements( s, p, o ) return the count of distinct (s,p,o) for all statements (s,p,o,g). Again, I'm not sure if the no arguments variant should follow the quad semantics. Thoughts?
ADDING STATEMENTS:
add_statement( TRIPLE ) adds the quad (s,p,o,nil) to the store.
add_statement( TRIPLE, CONTEXT ) adds the quad (s,p,o,context) to the store.
add_statement( QUAD ) adds the quad QUAD to the store.
add_statement( QUAD, CONTEXT ) throws an exception.
REMOVING STATEMENTS:
remove_statement( TRIPLE ) removes the quad (s,p,o,nil) from the store.
remove_statement( TRIPLE, CONTEXT ) removes the quad (s,p,o,context) from the store.
remove_statement( QUAD ) removes the quad QUAD from the store.
remove_statement( QUAD, CONTEXT ) throws an exception.
I've made these changes to RDF::Trine::Store::DBI and added a new RDF::Trine::Store::Memory (that's based on pure-perl data structures without the need for SQLite) that follows this API.
Moving forward with this, there's an open issue I'd like to discuss. I'm considering adding quad support directly into RDF::Trine::Statement and doing away with RDF::Trine::Statement::Quad. The Statement constructor would fill in the graph/context slot with the nil-node if none is supplied. Obviously if this happened the APIs discussed above would be much simplified (adding and removing statements would have only a single method call variant each instead of the current four).
Does anyone have thoughts on these changes? Do you currently use quads with the existing DBI-based storage in RDF::Trine? I've packaged the current code with these changes if anybody wants to try it with existing code:
http://kasei.us/code/files/RDF-Trine-0.200_01.tar.gz
thanks,
.greg
More information about the Dev
mailing list