[redland-dev] Problems with SPARQL's OPTIONAL pattern matching

fiandro at tiscali.it fiandro at tiscali.it
Fri Feb 24 16:45:03 GMT 2006


i've encounterd some problems with the following SPARQL query 

"PREFIX rdf: <http://www.dajobe.org/foaf.rdf> PREFIX foaf: <http:
//xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> 
SELECT ?x, ?y, ?name, ?depiction_title WHERE { ?x foaf:name ?name . ?x 
foaf:depiction ?y . OPTIONAL { ?y dc:title ?depiction_title } }"

on the simple RDF document attached at the end of this email.

If the "<dc:title>Me and my friends</dc:title>" line is removed from 
the RDF document and the query is executed via roqet, i'm told that 
some values are null but roqet exits correctly.

attilio at attilaptop:~/rdf$roqet -qs "file:
///home/attilio/rdf/foaf/foaf_atti_simplified.rdf"  -e "PREFIX rdf: 
<http://www.dajobe.org/foaf.rdf> PREFIX foaf: <http://xmlns.com/foaf/0.
1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?x, ?y, ?name, 
?depiction_title WHERE { ?x foaf:name ?name . ?x foaf:depiction ?y . 
OPTIONAL { ?y dc:title ?depiction_title } }" -i sparql
result: [x=uri<file:///home/attilio/rdf/foaf/foaf_atti_simplified.
rdf#i>, y=uri<http://www.swer.it/~attilio.fiandrotti/fossano/dscn4949.
jpg>, name=string("Attilio fiandrotti"), depiction_title=NULL]
if the query is done by a c# (or python) application (i did not try to 
write a C application), it gets the following SIGSEV signal

Breakpoint 1, librdf_new_node_from_node (node=0x0) at rdf_node.c:624
(gdb) p node
$7 = (librdf_node *) 0x0
(gdb) p *node
Cannot access memory at address 0x0
(gdb) bt
#0  librdf_new_node_from_node (node=0x0) at rdf_node.c:624
#1  0xb6db5563 in ?? ()
#2  0x00000000 in ?? ()
(gdb) c
rdf_node.c:624: (librdf_new_node_from_node) assertion failed: object 
pointer of type librdf_node is NULL.

Program received signal SIGABRT, Aborted.
0xb7b2a7a7 in raise () from /lib/tls/libc.so.6

Maybe i doing something wrong in my C# application, reported above 
(i'm new to both redland and C#) ?
Note that if the OPTIONAL constraint is removed, then i simply get no 
matches, as expected, but no crashes.

thanks a lot

Attilio Fiandrotti

*********SAMPLE APP**********
//mcs -g query_URI.cs -target:exe -r:Redland.dll; mono query_URI.exe

using System;
using Redland;

class QueryPG {
	public static void Main() {
	string my_uri = "file:///home/attilio/rdf/foaf/foaf_atti_simplified.
	string my_query = "PREFIX rdf: <http://www.dajobe.org/foaf.rdf> 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.
org/dc/elements/1.1/> SELECT ?x, ?y, ?name, ?depiction_title WHERE { ?x 
foaf:name ?name . ?x foaf:depiction ?y . OPTIONAL { ?y dc:title ?
depiction_title } }";

	Storage storage = new Storage ("memory", "test", null);
	Model model = new Model (storage);

	Parser parser = new Parser ("rdfxml");
	Console.WriteLine ("Parsing URI: {0}", my_uri);
	parser.ParseIntoModel (model, my_uri);

	Redland.Query q = new Redland.Query(my_query, null, "sparql", null);
	Redland.QueryResults results =  q.Execute(model);
	int i;
	while(results.MoveNext()) {
		for (i=0; i < results.BindingsCount(); i++) {
			if( (results != null) && (results.BindingName(i) != null) && 
(results.BindingValue(i) != null))
				Console.WriteLine( results.BindingName(i)+" => "+results.
BindingValue(i) );
	Console.WriteLine("\nQuery executed executed on \"" + my_uri + "\" 

*********RDF DOCUMENT**********

<?xml version="1.0"?>

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"

<foaf:PersonalProfileDocument rdf:about="">
  <foaf:maker rdf:resource="#i" />
  <foaf:primaryTopic rdf:resource="#i" />

<foaf:Person rdf:about="#i">
  <foaf:name>Attilio fiandrotti</foaf:name>
    <foaf:Image rdf:about="http://www.xyz.it/xyz.jpg">
       <dc:title>Me and my friends</dc:title>

Tiscali ADSL 4 Mega Flat
Naviga senza limiti con l'unica Adsl a 4 Mega di velocità a soli 19,95 € al mese!
Attivala subito e hai GRATIS 2 MESI e l'ATTIVAZIONE. 

More information about the redland-dev mailing list