Attean

 view release on metacpan or  search on metacpan

bin/attean_query  view on Meta::CPAN

#!/usr/bin/env perl

use v5.14;
use warnings;
no warnings 'once';
use autodie;
use File::Slurp;
use Scalar::Util qw(blessed);
use Attean;
use Attean::RDF;
use AtteanX::Functions::CompositeMaps;
use AtteanX::Functions::CompositeLists;
use Data::Dumper;
use Getopt::Long;
use Try::Tiny;
use open ':std', ':encoding(utf8)';

BEGIN { $Error::TypeTiny::StackTrace	= 1; }

if (scalar(@ARGV) < 1) {
	print STDERR <<"END";
Usage: $0 query.rq [data.ttl ...]

Parses the supplied SPARQL query to an Attean::Algebra object,
and executes it against a model containing the RDF data parsed
from the data file(s) using Attean::SimpleQueryEvaluator.

END
	exit(0);
}

AtteanX::Functions::CompositeMaps->register();
AtteanX::Functions::CompositeLists->register();

my $dryrun			= 0;
my $check_syntax	= 0;
my $verbose			= 0;
my $debug			= 0;
my $benchmark		= 0;
my $print_sparql	= 0;
my $print_plan		= 0;
my $print_algebra	= 0;
my $update			= 0;
my $out_format		= '';
my $short			= 0;
my $result			= GetOptions(
	"verbose"	=> \$verbose,
	"debug"		=> \$debug,
	"update"	=> \$update,
	"benchmark"	=> \$benchmark,
	'algebra'	=> \$print_algebra,
	'plan'		=> \$print_plan,
	"q"			=> \$print_sparql,
	'n'			=> \$dryrun,
	'c'			=> \$check_syntax,
	'short'		=> \$short,
	'output=s'	=> \$out_format,
);

my $qfile	= shift;

try {
	warn "Constructing model...\n" if ($verbose);
	my $store	= Attean->get_store('Memory')->new();
	my $model	= Attean::MutableQuadModel->new( store => $store );
	my $graph	= Attean::IRI->new('http://default-graph/');

	my $map		= URI::NamespaceMap->new();
	while (my $data = shift(@ARGV)) {
		my $base	= Attean::IRI->new('file://' . File::Spec->rel2abs($data));
		open(my $fh, '<:encoding(UTF-8)', $data);
		warn "Parsing data from $data...\n" if ($verbose);
		my $pclass	= Attean->get_parser( filename => $data ) // 'AtteanX::Parser::Turtle';
		my $parser	= $pclass->new(base => $base, namespaces => $map);
		my $iter	= $parser->parse_iter_from_io($fh);



( run in 1.429 second using v1.01-cache-2.11-cpan-5837b0d9d2c )