[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
Hi
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
624 LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(node, librdf_node,
NULL);
(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
Continuing.
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.
rdf";
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 + "\"
successfully.\n");
}
}
*********RDF DOCUMENT**********
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rss="http://purl.org/rss/1.0/"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wot="http://xmlns.com/wot/0.1/"
>
<foaf:PersonalProfileDocument rdf:about="">
<foaf:maker rdf:resource="#i" />
<foaf:primaryTopic rdf:resource="#i" />
</foaf:PersonalProfileDocument>
<foaf:Person rdf:about="#i">
<foaf:name>Attilio fiandrotti</foaf:name>
<foaf:depiction>
<foaf:Image rdf:about="http://www.xyz.it/xyz.jpg">
<dc:format>image/png</dc:format>
<dc:title>Me and my friends</dc:title>
</foaf:Image>
</foaf:depiction>
</foaf:Person>
</rdf:RDF>
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.
http://abbonati.tiscali.it/banner/middlepagetracking.html?c=webmailadsl&r=http://abbonati.tiscali.it/adsl/sa/4flat_tc/&a=webmail&z=webmail&t=14
More information about the redland-dev
mailing list