| 1 | # RDF::Trine::Parser::NQuads | ||||||||||||||||||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | RDF::Trine::Parser::NQuads - N-Quads Parser | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | This document describes RDF::Trine::Parser::NQuads version 1.019 | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | use RDF::Trine::Parser; | ||||||||||||||||||||||||||||
| 15 | my $parser = RDF::Trine::Parser->new( 'nquads' ); | ||||||||||||||||||||||||||||
| 16 | $parser->parse_into_model( $base_uri, $data, $model ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | ... | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 METHODS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Beyond the methods documented below, this class inherits methods from the | ||||||||||||||||||||||||||||
| 25 | L<RDF::Trine::Parser> class. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =over 4 | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | package RDF::Trine::Parser::NQuads; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 68 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 68 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 68 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 68 | ▶ | use base qw(RDF::Trine::Parser::NTriples); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 68 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 68 | ▶ | use Encode qw(decode); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 68 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 68 | ▶ | use Log::Log4perl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 68 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 68 | ▶ | use RDF::Trine qw(literal); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 68 | ▶ | use RDF::Trine::Node; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 68 | ▶ | use RDF::Trine::Statement; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 68 | ▶ | use RDF::Trine::Error qw(:try); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | ###################################################################### | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 68 | our ($VERSION); | |||||||||||||||||||||||||||
| 53 | 68 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 54 | 68 | $VERSION = '1.019'; | |||||||||||||||||||||||||||
| 55 | 68 | $RDF::Trine::Parser::parser_names{ 'nquads' } = __PACKAGE__; | |||||||||||||||||||||||||||
| 56 | 68 | $RDF::Trine::Parser::format_uris{ 'http://sw.deri.org/2008/07/n-quads/#n-quads' } = __PACKAGE__; | |||||||||||||||||||||||||||
| 57 | 68 | foreach my $ext (qw(nq)) { | |||||||||||||||||||||||||||
| 58 | 68 | $RDF::Trine::Parser::file_extensions{ $ext } = __PACKAGE__; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 68 | my $class = __PACKAGE__; | |||||||||||||||||||||||||||
| 61 | 68 | $RDF::Trine::Parser::canonical_media_types{ $class } = 'text/x-nquads'; | |||||||||||||||||||||||||||
| 62 | 68 | foreach my $type (qw(text/x-nquads)) { | |||||||||||||||||||||||||||
| 63 | 68 | $RDF::Trine::Parser::media_types{ $type } = __PACKAGE__; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | ###################################################################### | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =item C<< parse_into_model ( $base_uri, $data, $model ) >> | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Parses the bytes in C<< $data >>, using the given C<< $base_uri >>. For each RDF triple | ||||||||||||||||||||||||||||
| 72 | or quad parsed, will call C<< $model->add_statement( $statement ) >>. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 6 | ▶ | sub parse_into_model { | ||||||||||||||||||||||||||
|
Subroutine
parse_into_model: called CC=5 SCAR=17.4
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 6 | my $proto = shift; | |||||||||||||||||||||||||||
| 78 | 6 | ▶ | my $self = blessed($proto) ? $proto : $proto->new(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 6 | my $uri = shift; | |||||||||||||||||||||||||||
| 80 | 6 | ▶ | if (blessed($uri) and $uri->isa('RDF::Trine::Node::Resource')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($uri) and $uri->isa("RDF::Trine::Node::Resource")
MC/DC0%0/2
builtin::blessed($uri) and $uri->isa("RDF::Trine::Node::Resource")
builtin::blessed($uri)
$uri->isa("RDF::Trine::Node::Resource")
Truth table33%1/3
A and B
A= builtin::blessed($uri)B= $uri->isa("RDF::Trine::Node::Resource")
| |||||||||||||||||||||||||||||
| 81 | 0 | $uri = $uri->uri_value; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 6 | my $input = shift; | |||||||||||||||||||||||||||
| 84 | 6 | my $model = shift; | |||||||||||||||||||||||||||
| 85 | 6 | my %args = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 6 | ▶ | if (my $context = $args{'context'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | throw RDF::Trine::Error::ParserError -text => "Cannot pass a context node to N-Quads parse_into_model method"; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 8 | ▶ | my $handler = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 92 | 8 | my $st = shift; | |||||||||||||||||||||||||||
| 93 | 8 | $model->add_statement( $st ); | |||||||||||||||||||||||||||
| 94 | 6 | }; | |||||||||||||||||||||||||||
| 95 | 6 | return $self->parse( $uri, $input, $handler ); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 8 | ▶ | sub _emit_statement { | ||||||||||||||||||||||||||
|
Subroutine
_emit_statement: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||
| 99 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 8 | my $handler = shift; | |||||||||||||||||||||||||||
| 101 | 8 | my $nodes = shift; | |||||||||||||||||||||||||||
| 102 | 8 | my $lineno = shift; | |||||||||||||||||||||||||||
| 103 | 8 | my $st; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 8 | ▶ | if ($self->{canonicalize}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 5 | ▶ | if ($nodes->[2]->isa('RDF::Trine::Node::Literal') and $nodes->[2]->has_datatype) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$nodes->[2]->isa("RDF::Trine::Node::Literal") and $nodes->[2]->has_datatype
MC/DC0%0/2
$nodes->[2]->isa("RDF::Trine::Node::Literal") and $nodes->[2]->has_datatype
$nodes->[2]->isa("RDF::Trine::Node::Literal")
$nodes->[2]->has_datatype
Truth table33%1/3
A and B
A= $nodes->[2]->isa("RDF::Trine::Node::Literal")B= $nodes->[2]->has_datatype
| |||||||||||||||||||||||||||||
| 107 | 5 | my $value = $nodes->[2]->literal_value; | |||||||||||||||||||||||||||
| 108 | 5 | my $dt = $nodes->[2]->literal_datatype; | |||||||||||||||||||||||||||
| 109 | 5 | my $canon = RDF::Trine::Node::Literal->canonicalize_literal_value( $value, $dt, 1 ); | |||||||||||||||||||||||||||
| 110 | 5 | $nodes->[2] = literal( $canon, undef, $dt ); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 8 | ▶ | if (scalar(@$nodes) == 3) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 115 | 1 | $st = RDF::Trine::Statement->new( @$nodes ); | |||||||||||||||||||||||||||
| 116 | } elsif (scalar(@$nodes) == 4) { | ||||||||||||||||||||||||||||
| 117 | 7 | $st = RDF::Trine::Statement::Quad->new( @$nodes ); | |||||||||||||||||||||||||||
| 118 | } else { | ||||||||||||||||||||||||||||
| 119 | # warn Dumper($nodes); | ||||||||||||||||||||||||||||
| 120 | 0 | throw RDF::Trine::Error::ParserError -text => qq[Not valid N-Quads data at line $lineno]; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 8 | $handler->( $st ); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 68 | 1; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||