Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
31 RDF-Query/lib/RDF/Query.pm
@@ -344,6 +344,7 @@ sub prepare {
my $parsed = $self->{parsed};
my @vars = $self->variables( $parsed );
+ local($self->{model}) = $self->{model};
my $model = $self->{model} || $self->get_model( $_model, %args );
if ($model) {
$self->model( $model );
@@ -429,6 +430,8 @@ sub execute {
$lang_iri = 'http://www.w3.org/ns/sparql-service-description#SPARQL10Query';
}
+ local($self->{model}) = $self->{model};
+# warn "model: $self->{model}";
# warn "passthrough checking if model supports $lang_iri\n";
if ($self->{options}{allow_passthrough} and $model->supports($lang_iri)) {
$l->info("delegating $name execution to the underlying model");
@@ -484,9 +487,9 @@ sub execute_plan {
my $stream = $plan->as_iterator( $context );
if ($parsed->{'method'} eq 'DESCRIBE') {
- $stream = $self->describe( $stream );
+ $stream = $self->describe( $stream, $context );
} elsif ($parsed->{'method'} eq 'ASK') {
- $stream = $self->ask( $stream );
+ $stream = $self->ask( $stream, $context );
}
$l->debug("going to call post-execute hook");
@@ -643,7 +646,7 @@ sub plan_class {
=begin private
-=item C<describe ( $stream )>
+=item C<< describe ( $iter, $context ) >>
Takes a stream of matching statements and constructs a DESCRIBE graph.
@@ -654,7 +657,8 @@ Takes a stream of matching statements and constructs a DESCRIBE graph.
sub describe {
my $self = shift;
my $stream = shift;
- my $model = $self->model;
+ my $context = shift;
+ my $model = $context->model;
my @nodes;
my %seen;
while (my $row = $stream->next) {
@@ -694,7 +698,7 @@ sub describe {
=begin private
-=item C<ask ( $stream )>
+=item C<ask ( $iter, $context )>
Takes a stream of matching statements and returns a boolean query result stream.
@@ -705,6 +709,7 @@ Takes a stream of matching statements and returns a boolean query result stream.
sub ask {
my $self = shift;
my $stream = shift;
+ my $context = shift;
my $value = $stream->next;
my $bool = ($value) ? 1 : 0;
return RDF::Trine::Iterator::Boolean->new( [ $bool ] );
@@ -915,6 +920,13 @@ sub supports {
return $model->supports( @_ );
}
+=item C<< specifies_update_dataset >>
+
+Returns true if the query specifies a custom update dataset via the WITH or
+USING keywords, false otherwise.
+
+=cut
+
sub specifies_update_dataset {
my $self = shift;
no warnings 'uninitialized';
@@ -923,9 +935,11 @@ sub specifies_update_dataset {
=begin private
-=item C<< get_model ( $store ) >>
+=item C<< get_model ( $model ) >>
-Returns a model object for the specified RDF C<< $store >>.
+Returns a model object for use during execution.
+If C<< $model >> is a usable model, it is simply returned.
+Otherwise, a temporary model is constructed and returned.
=end private
@@ -1346,6 +1360,7 @@ sub model {
}
my $model = $self->{model};
unless (defined $model) {
+ Carp::confess "query->model shouldn't be calling get_model";
$model = $self->get_model();
}
@@ -1536,7 +1551,7 @@ L<http://www.perlrdf.org/>
=head1 LICENSE
-Copyright (c) 2005-2010 Gregory Todd Williams. This
+Copyright (c) 2005-2012 Gregory Todd Williams. This
program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
View
4 RDF-Query/lib/RDF/Query/Algebra/Table.pm
@@ -73,9 +73,9 @@ sub construct_args {
return ($self->rows);
}
-=item C<< triples >>
+=item C<< rows >>
-Returns a list of triples belonging to this BGP.
+Returns a list of variable bindings belonging to this data table.
=cut
View
33 RDF-Query/lib/RDF/Query/Expression/Function.pm
@@ -281,13 +281,32 @@ sub evaluate {
my ($ggp) = $self->arguments;
return $func->( $query, $context, $bound, $ggp, $active_graph );
} else {
- my @args = map {
- $_->isa('RDF::Query::Algebra')
- ? $_->evaluate( $query, $bound, $context, $active_graph )
- : ($_->isa('RDF::Trine::Node::Variable'))
- ? $bound->{ $_->name }
- : $_
- } $self->arguments;
+ my $model = ref($query) ? $query->{model} : undef;
+ if (blessed($context)) {
+ $model = $context->model;
+ }
+
+ my @args;
+ if (ref($query)) {
+ # localize the model in the query object (legacy code wants the model accessible from the query object)
+ local($query->{model}) = $model;
+ @args = map {
+ $_->isa('RDF::Query::Algebra')
+ ? $_->evaluate( $query, $bound, $context, $active_graph )
+ : ($_->isa('RDF::Trine::Node::Variable'))
+ ? $bound->{ $_->name }
+ : $_
+ } $self->arguments;
+ } else {
+ @args = map {
+ $_->isa('RDF::Query::Algebra')
+ ? $_->evaluate( $query, $bound, $context, $active_graph )
+ : ($_->isa('RDF::Trine::Node::Variable'))
+ ? $bound->{ $_->name }
+ : $_
+ } $self->arguments;
+ }
+
my $func = $query->get_function($uri);
unless ($func) {
throw RDF::Query::Error::ExecutionError -text => "Failed to get function for IRI $uri";
View
40 RDF-Query/lib/RDF/Query/Parser/SPARQL11.pm
@@ -63,7 +63,7 @@ our $r_STRING_LITERAL_LONG2 = qr/"""(("|"")?([^"\\]|${r_ECHAR}))*"""/;
our $r_LANGTAG = qr/@[a-zA-Z]+(-[a-zA-Z0-9]+)*/;
our $r_IRI_REF = qr/<([^<>"{}|^`\\\x{00}-\x{20}])*>/;
our $r_PN_CHARS_BASE = qr/([A-Z]|[a-z]|[\x{00C0}-\x{00D6}]|[\x{00D8}-\x{00F6}]|[\x{00F8}-\x{02FF}]|[\x{0370}-\x{037D}]|[\x{037F}-\x{1FFF}]|[\x{200C}-\x{200D}]|[\x{2070}-\x{218F}]|[\x{2C00}-\x{2FEF}]|[\x{3001}-\x{D7FF}]|[\x{F900}-\x{FDCF}]|[\x{FDF0}-\x{FFFD}]|[\x{10000}-\x{EFFFF}])/;
-our $r_PN_CHARS_U = qr/(_|${r_PN_CHARS_BASE})/;
+our $r_PN_CHARS_U = qr/([_:]|${r_PN_CHARS_BASE})/;
our $r_VARNAME = qr/((${r_PN_CHARS_U}|[0-9])(${r_PN_CHARS_U}|[0-9]|\x{00B7}|[\x{0300}-\x{036F}]|[\x{203F}-\x{2040}])*)/;
our $r_VAR1 = qr/[?]${r_VARNAME}/;
our $r_VAR2 = qr/[\$]${r_VARNAME}/;
@@ -1752,7 +1752,7 @@ sub _GraphPatternNotTriples_test {
sub _GraphPatternNotTriples {
my $self = shift;
if ($self->_test(qr/VALUES/i)) {
- $self->_InlineDataCluase;
+ $self->_InlineDataClause;
} elsif ($self->_test(qr/SERVICE/i)) {
$self->_ServiceGraphPattern;
} elsif ($self->_test(qr/MINUS/i)) {
@@ -1768,25 +1768,51 @@ sub _GraphPatternNotTriples {
}
}
-sub _InlineDataCluase {
+sub _InlineDataClause {
my $self = shift;
$self->_eat( qr/VALUES/i );
$self->__consume_ws_opt;
my @vars;
+
+ my $parens = 0;
+ if ($self->_test(qr/[(]/)) {
+ $self->_eat( qr/[(]/ );
+ $parens = 1;
+ }
while ($self->_test(qr/[\$?]/)) {
$self->_Var;
push( @vars, splice(@{ $self->{stack} }));
$self->__consume_ws_opt;
}
+ if ($parens) {
+ $self->_eat( qr/[)]/ );
+ }
my $count = scalar(@vars);
+
+ if (not($parens) and $count == 0) {
+ throw RDF::Query::Error::ParseError -text => "Syntax error: Expected VAR in inline data declaration";
+ }
+
+ my $short = (not($parens) and $count == 1);
$self->_eat('{');
$self->__consume_ws_opt;
my @rows;
- while ($self->_Binding_test) {
- my $terms = $self->_Binding($count);
- push( @rows, $terms );
- $self->__consume_ws_opt;
+ if (not($short) or ($short and $self->_Binding_test)) {
+ # { (term) (term) }
+ while ($self->_Binding_test) {
+ my $terms = $self->_Binding($count);
+ push( @rows, $terms );
+ $self->__consume_ws_opt;
+ }
+ } else {
+ # { term term }
+ while ($self->_BindingValue_test) {
+ $self->_BindingValue;
+ $self->__consume_ws_opt;
+ my ($term) = splice(@{ $self->{stack} });
+ push( @rows, [$term] );
+ }
}
$self->_eat('}');
View
8 RDF-Query/lib/RDF/Query/Plan/ComputedStatement.pm
@@ -120,13 +120,19 @@ sub execute ($) {
$nodes[ $i ] = $bound->{ $nodes[$i]->name };
}
}
+
+ $l->trace( "computed statement pattern after pre-binding: " . join(' ', map { $_->as_string } @nodes));
my $query = $context->query;
my $csg = $query->get_computed_statement_generators( $nodes[1]->uri_value );
unless (scalar(@$csg)) {
throw RDF::Query::Error::ExecutionError -text => "No computed statement generator found for predicate " . $nodes[1]->uri_value;
}
- my $iter = $csg->[0]->( $query, $bound, @nodes );
+ my $iter;
+ {
+ local($query->{model}) = $context->model;
+ $iter = $csg->[0]->( $query, $bound, @nodes );
+ }
if (blessed($iter)) {
$self->[0]{iter} = $iter;
$self->[0]{bound} = $bound;
View
35 RDF-Query/t/dev-computed-statements.t
@@ -3,6 +3,7 @@ use strict;
use warnings;
no warnings 'redefine';
use File::Spec;
+use Scalar::Util qw(blessed);
use lib qw(. t);
BEGIN { require "models.pl"; }
@@ -16,12 +17,14 @@ plan tests => 1 + ($tests * scalar(@models));
use_ok( 'RDF::Query' );
################################################################################
-Log::Log4perl::init( \q[
- log4perl.category.rdf.query.plan.computedtriple = DEBUG, Screen
- log4perl.appender.Screen = Log::Log4perl::Appender::Screen
- log4perl.appender.Screen.stderr = 0
- log4perl.appender.Screen.layout = Log::Log4perl::Layout::SimpleLayout
-] );
+# Log::Log4perl::init( \q[
+# log4perl.category.rdf.query = TRACE, Screen
+# log4perl.category.rdf.query.plan.computedstatement = TRACE, Screen
+# log4perl.category.rdf.query.plan.join.pushdownnestedloop = 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) {
@@ -41,6 +44,12 @@ foreach my $model (@models) {
END
$query->add_computed_statement_generator( 'http://www.jena.hpl.hp.com/ARQ/list#member' => \&__compute_list_member );
my $count = 0;
+
+# warn $model->as_string;
+# my ($plan, $ctx) = $query->prepare( $model );
+# warn $plan->explain();
+# $query->execute_plan( $plan, $ctx );
+
my $stream = $query->execute( $model );
my %expect = map { $_ => 1 } (1,2,3);
while (my $row = $stream->next) {
@@ -68,12 +77,12 @@ sub __compute_list_member {
my $first = RDF::Query::Node::Resource->new( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first' );
my $rest = RDF::Query::Node::Resource->new( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest' );
- use Scalar::Util qw(blessed);
+ my $model = $query->model;
if (blessed($p) and $p->isa('RDF::Query::Node::Resource') and $p->uri_value( 'http://www.jena.hpl.hp.com/ARQ/list#member' )) {
my @lists;
my $lists = ($c)
- ? $query->model->get_named_statements( $s, $first, $o, $c )
- : $query->model->get_statements( $s, $first, $o );
+ ? $model->get_named_statements( $s, $first, $o, $c )
+ : $model->get_statements( $s, $first, $o );
while (my $l = $lists->next) {
push(@lists, [$l, $l->subject]);
}
@@ -100,12 +109,12 @@ sub __compute_list_member {
return undef if (blessed($list) and $list->isa('RDF::Query::Node::Resource') and $list->uri_value eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil');
my $obj = $listst->object;
my $tail = ($c)
- ? $query->model->get_named_statements( $list, $rest, undef, $c )
- : $query->model->get_statements( $list, $rest, undef );
+ ? $model->get_named_statements( $list, $rest, undef, $c )
+ : $model->get_statements( $list, $rest, undef );
while (my $st = $tail->next) {
my $lists = ($c)
- ? $query->model->get_named_statements( $st->object, $first, $o, $c )
- : $query->model->get_statements( $st->object, $first, $o );
+ ? $model->get_named_statements( $st->object, $first, $o, $c )
+ : $model->get_statements( $st->object, $first, $o );
while (my $st = $lists->next) {
push(@lists, [$st, $head]);
}
View
12 RDF-Query/t/filters.t
@@ -17,6 +17,18 @@ my $GEO_DISTANCE_LOADED = ($@) ? 0 : 1;
use RDF::Query;
use RDF::Query::Node qw(iri);
+
+
+################################################################################
+# Log::Log4perl::init( \q[
+# log4perl.category.rdf.query.plan.filter = 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\n";

No commit comments for this range

Something went wrong with that request. Please try again.