[redland-dev] querying using bNodes (blank nodes)

Chris Mungall cjm at fruitfly.org
Wed May 23 03:14:39 BST 2007


Hi all

I'm writing a simple OWL module for perl

I'm struggling to find the correct syntax to use for querying bNodes  
in either RQL or SPARQL

I'm using RDF::Redland

I first construct a query - in RDQL

	SELECT ?x1,?x2 WHERE  (?x1 rdfs:subClassOf ?x2)

This is over an OWL document so ?x2 is often an owl:Restriction bNode

I can get the bnode ID like this:

	$bnode->blank_identifier

This typically gives me something like this:

	r1179878546r8710r116

But if I feed this back in like this:

	SELECT ?x1, ?x2 WHERE  ('r1179881893r8819r1' rdf:type  
owl:Restriction),('r1179881893r8819r1' owl:someValuesFrom ?x2), 
('r1179881893r8819r1' owl:onProperty ?x1)

I get:
	Redland error: syntax error, unexpected string literal, expecting  
'?' or URI literal or QName literal

I've tried various combinations - excluding quotes, prefixing with  
_:, anon:, using angle brackets...

This *does* seem to work:

	SELECT ?x1, ?x2 WHERE  (?in rdf:type owl:Restriction),(?in  
owl:someValuesFrom ?x2),(?in owl:onProperty ?x1) AND (?in eq  
'r1179882079r8828r5')

However, this query is painfully slow; and it's a bit unnerving not  
knowing why this works and the previous doesn't

I also tried the same thing with SPARQL:

Initial query:

	SELECT ?x1,?x2 WHERE {?x1 rdfs:subClassOf ?x2}

Then I feed the bnodes back in:

	SELECT ?x1, ?x2 WHERE  {'r1179882435r8852r5' rdf:type  
owl:Restriction . 'r1179882435r8852r5' owl:someValuesFrom ?x2 .  
'r1179882435r8852r5' owl:onProperty ?x1}

However, this misses the triples

I also tried this:

	SELECT ?x1, ?x2 WHERE  {_:r1179882435r8852r5 rdf:type  
owl:Restriction . _:r1179882435r8852r5 owl:someValuesFrom ?x2 .  
_:r1179882435r8852r5 owl:onProperty ?x1}

but this returns *all* restrictions, as if _:x is being treated as a  
free variable. This is consistent with the SPARQL spec:
	"Blank nodes in graph patterns act as non-distinguished variables,  
not as references to specific blank nodes in the data being queried"

So it seems that if I want to use SPARQL I can't split my query in  
two - I would have to say

	WHERE { ?x1 rdfs:subClassOf [ rdf:type owl:Restriction ; .... ] }

And avoid explicitly mentioning bnodes altogether. This isn't my  
preferred way of doing things - there are too many combinations of  
axioms and descriptions.

Should I just stick with the slow RQL method? Will this be robust to  
future changes? I'm not as familiar with RQL as I am with SPARQL.  I  
can't find any indication of the correct thing to do here:
http://www.w3.org/Submission/2004/SUBM-RDQL-20040109/

If the RDQL treatment of bNodes evolves more in the direction of  
SPARQL then I'm hosed if I embed the bnodes...

Thanks for any help
Chris



More information about the redland-dev mailing list