/usr/share/perl5/AtteanX/Parser/SPARQLTSV.pm is in libattean-perl 0.019-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | use v5.14;
use warnings;
=head1 NAME
AtteanX::Parser::SPARQLTSV - SPARQL Results TSV Parser
=head1 VERSION
This document describes AtteanX::Parser::SPARQLTSV version 0.019
=head1 SYNOPSIS
use Attean;
=head1 DESCRIPTION
...
=head1 ATTRIBUTES
=over 4
=item C<< canonical_media_type >>
=item C<< media_types >>
=item C<< file_extensions >>
=back
=head1 METHODS
=over 4
=cut
package AtteanX::Parser::SPARQLTSV 0.019 {
use utf8;
use Moo;
use Attean;
use Encode;
use Encode qw(decode);
use List::MoreUtils qw(zip);
use namespace::clean;
sub canonical_media_type { return "text/tab-separated-values" }
sub media_types {
return [qw(text/tab-separated-values)];
}
sub file_extensions { return [qw(tsv)] }
with 'Attean::API::ResultParser', 'Attean::API::PullParser', 'Attean::API::Parser';
=item C<< parse_iter_from_bytes( $data ) >>
Returns an iterator of L<Attean::API::Binding> objects that result from parsing
the data read from the UTF-8 encoded byte string C<< $data >>.
=cut
sub parse_iter_from_bytes {
my $self = shift;
my $data = shift;
open(my $fh, '<:encoding(UTF-8)', \$data);
return $self->parse_iter_from_io($fh);
}
=item C<< parse_iter_from_io( $fh ) >>
Returns an iterator of L<Attean::API::Binding> objects that result from parsing
the data read from the L<IO::Handle> object C<< $fh >>.
=cut
sub parse_iter_from_io {
my $self = shift;
my $fh = shift;
my $parser = Attean->get_parser('Turtle')->new(lazy_iris => $self->lazy_iris);
my $line = <$fh>;
unless (defined($line)) {
die "undefined header line in SPARQL/TSV parser";
}
chomp($line);
my @vars;
foreach my $v (split("\t", $line)) {
unless (substr($v, 0, 1) eq '?') {
Carp::confess "Bad variable syntax in SPARQL TSV data: '$v'";
}
push(@vars, substr($v, 1));
}
my $gen = sub {
my $line = <$fh>;
return unless defined($line);
chomp($line);
my @strings = split("\t", $line);
my %binding;
foreach my $i (0 .. $#vars) {
my $string = $strings[$i];
if (length($string)) {
my $var = $vars[$i];
my $bytes = encode('UTF-8', $string, Encode::FB_CROAK);
my $term = $parser->parse_term_from_bytes($bytes);
if ($term) {
$binding{ $var } = $term;
}
}
}
return Attean::Result->new( bindings => \%binding );
};
return Attean::CodeIterator->new(
generator => $gen,
item_type => $self->handled_type->role,
variables => \@vars,
);
}
}
1;
__END__
=back
=head1 BUGS
Please report any bugs or feature requests to through the GitHub web interface
at L<https://github.com/kasei/perlrdf/issues>.
=head1 AUTHOR
Gregory Todd Williams C<< <gwilliams@cpan.org> >>
=head1 COPYRIGHT
Copyright (c) 2014--2018 Gregory Todd Williams. This
program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
=cut
|