logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

RDF::Trine::Parser::Notation3 - Notation 3 Parser

Author

       Toby Inkster  "<tobyink@cpan.org>"

       Based on RDF::Trine::Parser::Turtle by Gregory Todd Williams.

Bugs

       Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=RDF-TriN3>.

Description

       This module provides a Notation 3 parser for RDF::Trine.

   Methods
       This package exposes the standard RDF::Trine::Parser methods, plus:

       forAll($handler)
           Sets a callback handler for @forAll directives found in the top-level graph. (@forAll found in nested
           formulae will not be passed to this callback.)

           The handler should be a coderef that takes a single argument: an RDF::Trine::Node::Resource.

           If  you do not set a handler, a warning will be issued when this directive are encountered in the top
           level graph, but parsing will continue.

       forSome($handler)
           As "forAll" but handles @forSome directives.

       "parse_formula($base, $input)"
           Returns an RDF::Trine::Node::Formula object representing the Notation  3  formula  given  as  $input.
           $input should not include the "{"..."}" wrappers.

   DatatypeCallbacks
       The constructor accepts a hashref of callbacks associated with datatypes, which will be triggered after a
       literal  has  been  parsed  with  that  datatype.  Let's imagine that you want to replace all xsd:integer
       literals with URIs like "http:;//example.net/numbers/123"...

        my $parser = RDF::Trine::Parser::Notation3->new(
          datatype_callback => {
            'http://www.w3.org/2001/XMLSchema#integer' => sub {
              my ($lit, $tr_hnd) = @_;
              return RDF::Trine::Node::Resource->new(
                'http:;//example.net/numbers/' . $lit->literal_value
              );
            },
          },
        );

       Note the second argument passed to the callback $tr_hnd. We don't use it here, but it's  a  coderef  that
       can be called with RDF::Trine::Statement objects to add additional triples to the graph being parsed.

       This  facility,  combined  with  shortcuts  from  RDF::Trine::Parser::ShorthandRDF  is  pretty useful for
       creating domain-specific languages.

Disclaimer Of Warranties

       THIS  PACKAGE  IS  PROVIDED  "AS  IS"  AND  WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
       LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

perl v5.38.2                                       2024-03-07                 RDF::Trine::Parser::Notation3(3pm)

Name

       RDF::Trine::Parser::Notation3 - Notation 3 Parser

See Also

       RDF::Trine::Parser::NTriples, RDF::Trine::Parser::Turtle, RDF::Trine::Parser::ShorthandRDF.

Synopsis

        use RDF::Trine::Parser;
        my $parser     = RDF::Trine::Parser->new( 'Notation3' );
        $parser->parse_into_model( $base_uri, $data, $model );

See Also