RDF-Flow

 view release on metacpan or  search on metacpan

lib/RDF/Flow.pm  view on Meta::CPAN

#ABSTRACT: RDF data flow pipeline

use RDF::Flow::Source qw(rdflow_uri);
use RDF::Flow::Union;
use RDF::Flow::Cascade;
use RDF::Flow::Pipeline;
use RDF::Flow::Cached;

use base 'Exporter';
our @EXPORT = qw(rdflow);
our @EXPORT_OK = qw(rdflow cached union cascade pipeline previous rdflow_uri);
our %EXPORT_TAGS = (
    all => [qw(rdflow cached union cascade pipeline previous)] );

our $PREVIOUS = RDF::Flow::Source->new( sub { shift->{'rdflow.data'} } );

sub rdflow   { RDF::Flow::Source->new(@_) }
sub union    { RDF::Flow::Union->new( @_ ) }
sub cascade  { RDF::Flow::Cascade->new( @_ ) }
sub pipeline { RDF::Flow::Pipeline->new( @_ ) }
sub cached   { RDF::Flow::Cached->new( @_ ); }

sub previous { $RDF::Flow::PREVIOUS; }

1;


__END__
=pod

lib/RDF/Flow.pm  view on Meta::CPAN

=over 4

=item C<rdflow>

Shortcut to create a new source with L<RDF::Flow::Source>.

=item C<cached>

Shortcut to create a new cached source with L<RDF::Flow::Cached>.

=item C<cascade>

Shortcut to create a new source cascade with L<RDF::Flow::Cascade>.

=item C<pipeline>

Shortcut to create a new source pipeline with L<RDF::Flow::Pipeline>.

=item C<previous>

A source that always returns C<rdflow.data> without modification.

=item C<union>

lib/RDF/Flow/Cascade.pm  view on Meta::CPAN


use Carp 'croak';
use Scalar::Util 'blessed';

sub new {
    my $class = shift;
    my ($inputs, $args) = sourcelist_args( @_ );

    my $self = bless {
        inputs => $inputs,
        name   => ($args->{name} || 'anonymous cascade'),
    }, $class;

    $self->match( $args->{match} );

    return $self;
}

sub about {
    my $self = shift;
    $self->name($self) . ' with ' . $self->size . ' inputs';

lib/RDF/Flow/Cascade.pm  view on Meta::CPAN

=head1 NAME

RDF::Flow::Cascade - Returns the first non-empty response of a sequence of sources

=head1 VERSION

version 0.178

=head1 SYNOPSIS

    use RDF::Flow qw(cascade);
    $src = cascade( @sources );                  # shortcut
    $src = cascade( @sources, name => 'foo' );   # with name

    use RDF::Flow::Cascade;
    $src = RDF::Flow::Cascade->new( @sources );  # explicit

    $rdf = $src->retrieve( $env );

=head1 DESCRIPTION

This L<RDF::Flow::Source> returns the first non-empty response of a given
sequence of sources.

t/graphviz.t  view on Meta::CPAN

eval "use GraphViz";
my $skip = $@;

SKIP: {
    skip('GraphViz required to run tests',1) if $skip;

    {package Cache; sub get {} sub set {} sub new {}}

    my $sa = rdflow( sub { }, name => "Foo" );
    my $sb = rdflow( sub { }, name => "Bar" );
    my $s1 = cascade( $sa, $sb );
    my $s2 = rdflow( sub { }, name => "S2" );
    my $s3 = union( rdflow( sub { }, name => "S3" ), rdflow ( sub{}, name => "S4") );

    my $c1 = RDF::Flow::Cached->new( $s1, Cache->new );
    my $s = pipeline ( $c1, $s2, $s3 );
    my $g = $s->graphviz;

    $g->as_png('flow.png');
    # TODO: check image

t/source_types.t  view on Meta::CPAN

use strict;
use warnings;

use Test::More;
use Test::RDF;
use RDF::Trine qw(statement iri);
use RDF::Flow qw(rdflow previous cascade union pipeline);
use RDF::Flow::Source qw(rdflow_uri);
use RDF::Flow::Union;
use RDF::Flow::Cascade;
use RDF::Flow::Pipeline;

my ($src, $rdf, $env);

#use Log::Contextual::SimpleLogger;
#use Log::Contextual qw( :log ),
#   -logger => Log::Contextual::SimpleLogger->new({ levels => [qw(trace info)]});

t/source_types.t  view on Meta::CPAN


$rdf = $src->retrieve( query('/foo') );
ok($rdf);

isomorph_graphs( $rdf, model(qw(
http://example.org/foo x:a y:foo
http://example.org/foo x:a y:bar)), 'union' );

$src = RDF::Flow::Cascade->new( $empty, $foo, \&bar );
$rdf = $src->retrieve( query('/foo') );
isomorph_graphs( $rdf, model(qw(http://example.org/foo x:a y:foo)), 'cascade' );

$src = cascade( $empty, \&bar, $foo );
$rdf = $src->retrieve( query('/foo') );
isomorph_graphs( $rdf, model(qw(http://example.org/foo x:a y:bar)), 'cascade' );

$env = query('/hi');
$src = pipeline( $foo, $bar );
$rdf = $src->retrieve( $env );
isomorph_graphs( $rdf, model(qw(http://example.org/hi x:a y:bar)), 'pipeline' );
is( $rdf, $env->{'rdflow.data'}, 'pipeline sets rdflight.data' );

$src = pipeline( $foo, $bar, $empty );
$rdf = $src->retrieve( query('/123') );
isomorph_graphs( $rdf, model(), 'empty source nils pipeline' );



( run in 0.657 second using v1.01-cache-2.11-cpan-49f99fa48dc )