Attean
view release on metacpan or search on metacpan
bin/attean_parse view on Meta::CPAN
#!/usr/bin/env perl
use v5.14;
use autodie;
use strict;
use warnings;
use Getopt::Long;
use Scalar::Util qw(blessed);
use Time::HiRes qw(gettimeofday tv_interval);
use Attean;
use Try::Tiny;
use open ':std', ':encoding(utf8)';
unless (@ARGV) {
print <<"END";
Usage: $0 -list
$0 -i IN_FORMAT [-o OUT_FORMAT] FILENAME
END
exit;
}
my $verbose = 0;
my $pull = 0;
my $push = 0;
my $list = 0;
my $block_size = 25;
my $short = 0;
my $number_rows = 0;
my %namespaces;
my $in_format = 'GUESS';
my $out_format = 'TextTable';
my $result = GetOptions ("number" => \$number_rows, "short" => \$short, "list" => \$list, "verbose" => \$verbose, "block=i" => \$block_size, "pull" => \$pull, "push" => \$push, "in=s" => \$in_format, "out=s" => \$out_format, "define=s" => \%namespace...
if ($list) {
say "Parsers:";
say sprintf("- %s", s/^.*://r) for (sort Attean->list_parsers);
say "\nSerializers:";
say sprintf("- %s", s/^.*://r) for (sort Attean->list_serializers);
say '';
exit;
}
my $mapper = $short ? Attean::TermMap->short_blank_map : undef;
my $bmapper = $short ? $mapper->binding_mapper : undef;
unless (@ARGV) { push(@ARGV, '-') }
while (defined(my $file = shift)) {
my $in = $in_format;
my $out = $out_format;
my $fh;
my $base;
if ($file eq '-') {
$fh = \*STDIN;
$base = Attean::IRI->new('file:///dev/stdin');
} else {
open( $fh, '<:encoding(UTF-8)', $file ) or die $!;
$base = Attean::IRI->new('file://' . File::Spec->rel2abs($file));
}
my $out_io = \*STDOUT;
$| = 1;
my $parser;
my $map = URI::NamespaceMap->new( \%namespaces );
if ($in eq 'GUESS') {
my $class = Attean->get_parser( filename => $file ) // 'AtteanX::Parser::NTriples';
$parser = $class->new( base => $base, namespaces => $map );
} else {
$parser = Attean->get_parser($in)->new(namespaces => $map);
}
( run in 1.024 second using v1.01-cache-2.11-cpan-39bf76dae61 )