[RDF] Re: [rdfapi_perl] Reworked API

Jonas Liljegren jonas@rit.se
08 Jun 2001 18:05:35 +0200


Alberto Reggiori <areggiori@webweaving.org> writes:

> > UseCases:
> > 
> > 1. if i want to write callbacks for a parser, i would like
> > to use
> > 
> > $bundle->add($sub,$pred,$obj)
> > 
> > for each triple generated by the parser.
> > 
> > 2. if I have a given RDF graph and a given
> > resource $res I would like to be able
> > to use something like
> > 
> > $res->add(dc:title,"the title")->add(dc:creator,"me");
> 
> Yep exactly! :)
> 
> or even something more baroque like
> 
> $bundle->find($subject,$predicate,$value)->elements->add($dcq::created,time());
> 
> where find() would work on bundled models while add() on resources

Or like how you currently can do it in Wraf:

$bundle -> sel({ pred => $predicate,
                 subj => $subject,
                 obj  => $object }) -> li ->
        declare_add_prop($dcq::created,\time());


Ok. That could be shorter.  declare_add_prop() should probably have
add() as an abbrevation.  The reason why sel() looks like it does is
that I haven't yet needed a general find() function.  Everything in {}
is called a criterion and can be anything.

sel() adds a criterion on a container of resources. In this case a
container of arcs, represented by $bundle. The {} holds a list of
properties that the resources should have.  In one place in Wraf
(connected to the DAML search funtion) I use this code:

    my $arc = $focus->arc({ pred => $connection,
			    obj =>
			    {
				NS_FORM.'controlled_by' => $self,
			    }
			   })->list->[0];

$focus is a specific resouce. arc() finds the arcs that has $focus as
subject, $connection as predicate and the object should be another
resource that has a 'controlled_by' property with the value $self.
arc() returns a "selection" container.  list() turns that container to
an array.  list->[0] is similar to li(), that expects the container to
have only one item.


Ok. I will, in Wraf, probably support the syntax:

$bundle->find($predicate, $subject, $object)->li->add($dcq::created,\time());

And that would add the property to the selected arc.  If I would leave
out the li(), the property would be added to the new container
returned by find().


-- 
/ Jonas Liljegren

The Wraf project http://www.uxn.nu/wraf/
Sponsored by http://www.rit.se/