1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#!/usr/bin/env perl
use strict;
use warnings;
no warnings 'redefine';
use URI::file;
use lib qw(. t);
BEGIN { require "models.pl"; }
my @files = map { "data/$_" } qw(about.xrdf foaf.xrdf);
my @models = test_models( @files );
use Test::More;
plan tests => 1 + (12 * scalar(@models));
use_ok( 'RDF::Query' );
################################################################################
# Log::Log4perl::init( \q[
# log4perl.category.rdf.query.algebra = TRACE, Screen
# log4perl.appender.Screen = Log::Log4perl::Appender::Screen
# log4perl.appender.Screen.stderr = 0
# log4perl.appender.Screen.layout = Log::Log4perl::Layout::SimpleLayout
# ] );
################################################################################
foreach my $model (@models) {
print "\n#################################\n";
print "### Using model: $model\n";
# my $s = $model->as_stream;
# while ($s and not $s->end) {
# my $st = $s->current;
# warn $st->as_string;
# } continue { $s->next }
# - Collections: (1 ?x 3)
{
my $query = new RDF::Query ( <<"END", undef, undef, 'sparql' );
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?x
WHERE {
?a1 rdf:first "1"; rdf:rest ?a2 .
?a2 rdf:first ?x; rdf:rest ?a3 .
?a3 rdf:first "3"; rdf:rest rdf:nil .
}
END
my ($x) = $query->get( $model );
ok( $x, 'got collection element' );
is( $x->literal_value, 2 );
}
# - Collections: (1 ?x 3)
{
my $query = new RDF::Query ( <<"END", undef, undef, 'sparql' );
SELECT ?x
WHERE {
("1" ?x "3")
}
END
my ($x) = $query->get( $model );
ok( $x, 'got collection triples' );
is( $x->literal_value, 2 );
}
# - Collections: ?s ?p (1 ?x 3)
{
my $query = new RDF::Query ( <<"END", undef, undef, 'sparql' );
PREFIX test: <http://kasei.us/e/ns/test#>
SELECT ?x
WHERE {
<http://kasei.us/about/foaf.xrdf#greg> test:mycollection ("1" ?x "3") .
}
END
my ($x) = $query->get( $model );
ok( $x, 'got object collection triples' );
is( $x->literal_value, 2 );
}
# - Object Lists: ?x foaf:nick "kasei", "kasei_" .
{
my $query = new RDF::Query ( <<"END", undef, undef, 'sparql' );
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?name
WHERE {
?x foaf:nick "kasei", "The Samo Fool" .
?x foaf:name ?name
}
END
my ($name) = $query->get( $model );
ok( $name, 'got name' );
is( $name->literal_value, 'Gregory Todd Williams', 'Gregory Todd Williams' );
}
# - Blank Nodes: [ :p "v" ] and [] :p "v" .
{
my $query = new RDF::Query ( <<"END", undef, undef, 'sparql' );
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?name
WHERE {
[ a geo:Point; geo:lat "52.972770"; foaf:name ?name ]
}
END
my ($name) = $query->get( $model );
ok( $name, 'got name' );
is( $name->literal_value, 'Cliffs of Moher, Ireland', 'Cliffs of Moher, Ireland' );
}
# - 'a': ?x a :Class . [ a :myClass ] :p "v" .
{
my $query = new RDF::Query ( <<"END", undef, undef, 'sparql' );
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?name
WHERE {
[ a geo:Point; geo:lat "52.972770"; foaf:name ?name ]
}
END
my ($name) = $query->get( $model );
ok( $name, 'got name' );
is( $name->literal_value, 'Cliffs of Moher, Ireland', 'Cliffs of Moher, Ireland' );
}
}
|