CC: | Ivan Shmakov <oneingray [...] gmail.com> |
Subject: | the handling of a template with a blank node is seemingly incorrect |
Date: | Sat, 20 Nov 2010 02:14:57 +0600 |
To: | bug-RDF-Query [...] rt.cpan.org |
From: | Ivan Shmakov <ivan [...] main.uusia.org> |
I'm trying to execute an example query from [1]:
$ cat data.ttl
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:givenname "Alice" .
_:a foaf:family_name "Hacker" .
_:b foaf:firstname "Bob" .
_:b foaf:surname "Hacker" .
$ cat query.sparql
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
CONSTRUCT {
?x vcard:N _:v .
_:v vcard:givenName ?gname .
_:v vcard:familyName ?fname .
}
WHERE {
{ ?x foaf:firstname ?gname } UNION { ?x foaf:givenname ?gname } .
{ ?x foaf:surname ?fname } UNION { ?x foaf:family_name ?fname } .
}
$
Contrary to what the specification says, only a single node
seems to be produced for _:v (with /two/ vcard:N arcs pointing
at it):
$ rdf-query-2010-11-19 \
data.ttl "$(cat < query.sparql)"
_:rad698bec6861467e87b15dbf8dbeda12r1 <http://www.w3.org/2001/vcard-rdf/3.0#N> _:r1290196899r0 .
_:r1290196899r0 <http://www.w3.org/2001/vcard-rdf/3.0#givenName> "Bob" ;
<http://www.w3.org/2001/vcard-rdf/3.0#familyName> "Hacker" .
_:rad698bec6861467e87b15dbf8dbeda12r0 <http://www.w3.org/2001/vcard-rdf/3.0#N> _:r1290196899r0 .
$
[1] http://www.w3.org/TR/sparql11-query/#tempatesWithBNodes
--
FSF associate member #7257
### rdf-query-2010-11-19.pl -*- Perl -*-
use strict;
use warnings;
require RDF::Query;
require RDF::Trine::Model;
require RDF::Trine::Serializer::Turtle;
require RDF::Trine::Store::Memory;
sub show_graph {
my ($iter) = @_;
my $s
= new RDF::Trine::Serializer::Turtle ();
print ($s->serialize_iterator_to_string ($iter), "\n");
}
sub show_results {
my ($iterator) = @_;
for ( ; my $row = $iterator->next (); ) {
foreach my $k (keys (%$row)) {
print (" ", $k, " ", $row->{$k});
}
print ("\n");
}
}
die ("Usage: rdf-query-2010-11-19 TURTLE-FILE QUERY")
unless (1 + $#ARGV == 2);
my ($file, $sparql) = @ARGV;
my $store
= RDF::Trine::Store->new_with_config ({
"storetype" => "Memory",
"sources" => [
{
"file" => $file,
"syntax" => "turtle",
"base_uri" => "x-dummy:uri"
} ] });
my $model
= new RDF::Trine::Model ($store);
my $query
= new RDF::Query ($sparql)
or die ("Cannot create RDF:Query: ", $!, ": ");
my $iterator
= $query->execute ($model);
if ($iterator->isa ('RDF::Trine::Iterator::Graph')) {
show_graph ($iterator);
} else {
show_results ($iterator);
}
## Local variables:
## fill-column: 72
## indent-tabs-mode: nil
## End:
### rdf-query-2010-11-19.pl ends here
Message body not shown because it is not plain text.