[Mulgara-general] walking bnodes?
Alex Hall
alexhall at revelytix.com
Tue Apr 29 13:38:29 UTC 2008
Hi Thomas,
tl wrote:
> hi,
>
> i've got a modelling issue. best i start with an example. say, i'm
> modelling a text-object. it looks like this:
>
> subject1 type article
> title "some title"
> creator "a name"
> body complex_xhtml_blob
>
> now ... in some cases the body may be a blob (as above) while in other
> cases it is structured, like this:
>
> subject1 type article
> title "some title"
> creator "a name"
> body _bnode
> _bnode subtitle "some subtitle"
> paragraph "some text"
> image picture.gif
>
> the question now is: is it possible to query for all predicates/
> objects of a given subject and let the query automagically follow any
> _bnodes it encounters on the way? that's essentially the sparql
> DESCRIBE command [1] returning a Concise Bounded Description [2] i
> guess.
Fortunately, a SPARQL implementation has just been merged to the main
branch of Mulgara in SVN. This should provide the DESCRIBE feature that
you're looking for. I would recommend getting a checkout of the latest
version from SVN and playing around with it some. To the best of my
knowledge the SPARQL interpreter is not documented, but other people on
this list can probably help you out with that.
> does TQL even provide the capability to identify a bnode and do
> something different in that case)?
TQL does provide a mechanism for discovering the type of nodes in a
graph using the nodetyping resolver [1]. Unfortunately, it does not
provide direct support for blank nodes; I believe this is a restriction
imposed by the internal architecture. But it should be able to get you
close enough to what you're looking for. For instance:
create <rmi://localhost/server1#type>
<http://mulgara.org/mulgara#TypeModel>;
alias <rmi://localhost/server1#> as server;
select $p $o $p1 $o1 from <server:mymodel>
where (<subject1> $p $o
and ($o <rdf:type> <rdfs:Literal> in <server:type>
or $o <rdf:type> <mulgara:uriReference> in <server:type>))
or (<subject1> $p $o
minus ($o <rdf:type> <rdfs:Literal> in <server:type>
or $o <rdf:type> <mulgara:uriReference> in <server:type>)
and $o $p1 $o1);
Another possibility is to ditch the nodetyping resolver and just use a
simple subquery:
select $p $o subquery(select $p1 $o1 from <server:mymodel> where $o $p1
$o1) from <server:mymodel> where <subject1> $p $o ;
In this case, as you iterate over the answer from the query you would
examine the value of the $o variable, and if it's a blanknode (which
will have the form "_nodeXXXX") then evaluate the subquery.
Neither one of these methods that I've described will give you any sort
of recursion; they will only get you the first level of properties on
any blank node associated with the original subject of the query.
Regards,
Alex
[1] http://docs.mulgara.org/itqloperations/nodetyping.html
More information about the Mulgara-general
mailing list