Re: perllib suggestion: change Algae.pm datasource API

On Tue, Jun 26, 2001 at 06:01:05PM -0400, Dan Brickley wrote:
> 
> Hi Eric,
> 
> http://www.w3.org/1999/02/26-modules/
> http://www.w3.org/2001/Talks/0505-perl-RDF-lib/
> http://dev.w3.org/cvsweb/perl/modules/W3C/Rdf/Algae.pm?rev=1.41&content-type=text/x-cvsweb-markup
> 
> I've been looking at W3c::RDF::Algae.pm with an eye to dropping in
> alternate backend database implementations, like we discussed recently.
> I've also got a wrapper for the Squish RDF query language that I'll
> contrib when I've got some tests implemented to be sure it works properly.
> 
> Anyway, a suggestion: It seems the way Algae.pm currently works, one needs
> a class that implements W3C::RDF::RdfDB that can be constructed afresh by
> the query engine, ie. the method W3C::RDF::Algae::checkForDBSpec() wants
> to be passed a class name plus a bunch of initialisation parameters,
> which'll allow it to create a new instance of some species of RDF database.
> 
> Suggestion:
> Often one's application code will *already* have its hands on a reference
> to such a database object, so it'd be nice if this could just be passed
> to the query engine instead.
> 
> Currently you do: eval "require $dbSpec; \$\$pDb = new $dbSpec(\$parms);";
> 
> ...could you hack it to take a Perl reference instead? Would this break
> anything else? That way I can create RDF database instances and initialise
> them without having to have Algae do that work...

The "require $dbSpec; \$\$pDb = new $dbSpec(\$parms);" is the codepath
that is taken when you supply a source database as a string with
parameters. The alternative is to supply a source as a uri. The common
example of this is in the run.sh script (version 1.10):

-d"\"W3C::Rdf::RdfDB\" (\"name:local:/ephemeral\")" \
../test/algaeTest.rdf \
-a"(namespace '(fingerA http://finger.net/attrs/ \
		finger http://finger.net/get/ \
		t http://t.t/ \
		a http://a.a/ \
		myDb local:/) \
    attach '(\"W3C::Rdf::FingerDB\" (\"cacheTimeout:1\" \"name:myDb::fred\")) \
    ask '((~http://t.*/p1* ?s1 ?o1) \
	  (t::p2 ?o1 ?o2) \
	  (?o3 ?o2 ?o3) \
	  (t::p4 ?s1 ?o2)) \
    assert '((a::p1 ?o1 #?g1) (a::p2 ?g1 ?o2)) \
    ask '(myDb::fred \
          (fingerA::Name finger::localhost/eric ?name)) \
    collect '(?s1 ?o3 ?g1 ?o2 ?name) \
   )"

In this example, a finger database is fiven the name local:/fred and
is queried for triples of the form:
  (http://finger.net/attrs/Name http://finger.net/get/localhost/eric *)
The Algae interface advertises an addSource function that allows the
application to supply databases. You may then select such a database by
name so long as you have given it a name:
  if (exists $self->{-sources}[$i]{-name} && 
      $self->{-sources}[$i]{-name} eq $name) ...

The ugly part is that I think the RdfDB interface does not (currently)
advertise a setName function and you have to do something like:
  my $db = new RdfDB(-name => "http://example.org/ephem1");
or maybe just set the name of an existing RdfDB (or derivative):
  $db{-name} = $atomDictionary->getUri('http://example.org/ephem1');

Let me know how this works out and we can clean up the interface. I
think in the long run, the name should not be part of the RdfDB, but
instead associated in the Algae object itself.

-- 
-eric

(eric@w3.org)
Feel free to forward this message to any list for any purpose other than
email address distribution.

Received on Thursday, 5 July 2001 11:38:41 UTC