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
|
#!/usr/bin/env perl
use strict;
use warnings;
no warnings 'redefine';
use Test::More;
use lib qw(. t);
require "models.pl";
my @files = map { "data/$_" } qw(about.xrdf foaf.xrdf);
my @models = test_models( @files );
use_ok( 'RDF::Query' );
foreach my $model (@models) {
print "\n#################################\n";
print "### Using model: $model\n\n";
{
my $query = new RDF::Query ( <<"END", undef, undef, 'sparql' );
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
DESCRIBE ?person
WHERE { ?person foaf:name "Gregory Todd Williams" }
END
my $stream = $query->execute( $model );
ok( $stream->is_graph, "Stream is graph result" );
isa_ok( $stream, 'RDF::Trine::Iterator', 'stream' );
my $count = 0;
while (my $stmt = $stream->next) {
my $p = $stmt->predicate;
my $s = $p->as_string;
ok( $s, $s );
++$count;
}
# is( $count, 54, 'describe person expected graph size' );
}
{
my $query = new RDF::Query ( <<"END", undef, undef, 'sparql' );
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
DESCRIBE ?person
WHERE {
?image a foaf:Image ; foaf:maker ?person .
}
END
my $stream = $query->execute( $model );
ok( $stream->is_graph, "Stream is graph result" );
isa_ok( $stream, 'RDF::Trine::Iterator', 'stream' );
my $count = 0;
while (my $stmt = $stream->next) {
my $p = $stmt->predicate;
my $s = $p->as_string;
ok( $s, $s );
++$count;
}
# is( $count, 54, 'describe person expected graph size' );
}
{
my $query = new RDF::Query ( <<"END", undef, undef, 'sparql' );
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
DESCRIBE <http://kasei.us/about/foaf.xrdf>
END
my $stream = $query->execute( $model );
ok( $stream->is_graph, "Stream is graph result" );
isa_ok( $stream, 'RDF::Trine::Iterator', 'describe resource returns graph iterator' );
my $count = 0;
while (my $stmt = $stream->next) {
my $p = $stmt->predicate;
like( $p->uri_value, qr<^(http://xmlns.com/foaf/0.1/maker|http://www.w3.org/1999/02/22-rdf-syntax-ns#type|http://xmlns.com/wot/0.1/assurance|http://purl.org/dc/elements/1.1/(title|description|date))$>, 'expected predicate' );
++$count;
}
is( $count, 6, 'describe resource expected graph size' );
}
}
done_testing;
|