| 1 | =head1 NAME | ||
| 2 | |||
| 3 | AtteanX::Plan::SPARQLBGP - Plan for efficient evaluation of SPARQL BGPs on remote endpoints | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | This is typically only constructed by planning hacks deep in the code, | ||
| 8 | but might look like: | ||
| 9 | |||
| 10 | use v5.14; | ||
| 11 | use AtteanX::Plan::SPARQLBGP; | ||
| 12 | my $new_bgp_plan = AtteanX::Plan::SPARQLBGP->new(children => [$some_quads], | ||
| 13 | distinct => 0, | ||
| 14 | ordered => []); | ||
| 15 | |||
| 16 | =head1 DESCRIPTION | ||
| 17 | |||
| 18 | This plan class implements compiling basic graph patterns that can be | ||
| 19 | joined remotely on a SPARQL endpoint. | ||
| 20 | |||
| 21 | =head2 Attributes and methods | ||
| 22 | |||
| 23 | Consumes L<Attean::API::QueryTree>, L<Attean::API::Plan> and | ||
| 24 | L<Attean::API::UnionScopeVariablesPlan>, and introduces nothing | ||
| 25 | new. The most notable attribute is: | ||
| 26 | |||
| 27 | =over | ||
| 28 | |||
| 29 | =item C<< children >> | ||
| 30 | |||
| 31 | which takes an arrayref of L<Attean::Plan::Quad> objects to be | ||
| 32 | included in the Basic Graph pattern that will be evaluated against the | ||
| 33 | model. | ||
| 34 | |||
| 35 | =back | ||
| 36 | |||
| 37 | =head1 OTHER DETAILS | ||
| 38 | |||
| 39 | For author, copyright and other details, see L<AtteanX::Store::SPARQL>. | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | |||
| 44 | package AtteanX::Plan::SPARQLBGP; | ||
| 45 | |||
| 46 | 1 | ▶ | use v5.14; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 47 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 48 | |||
| 49 | 1 | our $AUTHORITY = 'cpan:KJETILK'; | |
| 50 | 1 | our $VERSION = '0.012'; | |
| 51 | |||
| 52 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 53 | 1 | ▶ | use Scalar::Util qw(blessed); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 54 | |||
| 55 | 1 | with 'Attean::API::QueryTree', | |
| 56 | 'Attean::API::Plan', | ||
| 57 | 'Attean::API::UnionScopeVariablesPlan', | ||
| 58 | 'MooX::Log::Any'; | ||
| 59 | |||
| 60 | 1 | ▶ | sub plan_as_string { |
|
Subroutine
plan_as_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 61 | 1 | my $self = shift; | |
| 62 | 1 | return 'SPARQLBGP'; | |
| 63 | } | ||
| 64 | |||
| 65 | 0 | ▶ | sub impl { |
|
Subroutine
impl: not called CC=2 SCAR=17.9
Pod
undocumented
| |||
| 66 | 0 | my $self = shift; | |
| 67 | 0 | my $model = shift; | |
| 68 | 0 | my $sparql = 'SELECT * WHERE {'; | |
| 69 | 0 | foreach my $child (@{$self->children}) { | |
| 70 | 0 | my @terms = $child->values; | |
| 71 | 0 | my $pattern = Attean::TriplePattern->new(@terms[0..2]); | |
| 72 | 0 | $sparql .= "\n " . $pattern->as_sparql . ' . '; | |
| 73 | } | ||
| 74 | 0 | $sparql .= "\n}\n"; | |
| 75 | 0 | $self->log->debug("Using query:\n$sparql"); | |
| 76 | 0 | ▶ | return sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 77 | 0 | return $model->get_sparql($sparql) | |
| 78 | } | ||
| 79 | 0 | } | |
| 80 | |||
| 81 | 1 | 1; | |