RDF::T...tation3(3pm)

πŸ’– RDF::Trine::Parser::Notation3 β€” the whole vibe

okay so bestie, this is RDF::T...tation3(3pm) from the User Contributed Perl Documentation, and it's genuinely one of those pages that sounds boring for 0.2 seconds and then turns out to be lowkey iconic. it's the Notation 3 Parser for RDF::Trine. yes we're doing semantic web today. slay. πŸ¦‹


✨ NAME ✨

RDF::Trine::Parser::Notation3 β€” Notation 3 Parser. that's it, that's the name, she's simple, she's elegant, she parses Notation 3. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

the way you literally just do this:

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

three lines. a whole parser. main character energy fr fr. ✨


🌸 DESCRIPTION 🌸

This module provides a Notation 3 parser for RDF::Trine. periodt. that's the whole pitch, no notes. 🫢

πŸ’œ Methods πŸ’œ

This package exposes the standard RDF::Trine::Parser methods, plus these extra lil babies:

  • forAll($handler) β€” sets a callback handler for the @forAll directives it finds in the top-level graph. quick heads up bestie: @forAll directives sitting inside nested formulae do not get passed to this callback. only the top-level ones. iykyk. the handler should be a coderef that takes exactly one argument: an RDF::Trine::Node::Resource. and if you never set a handler at all? you'll get a warning when this directive shows up in the top-level graph, but parsing just keeps going. no drama, just vibes and a warning. 😭
  • forSome($handler) β€” literally the same deal as forAll above, except it handles the @forSome directives instead. same rules, different sigil. πŸ’«
  • parse_formula($base, $input) β€” hands you back an RDF::Trine::Node::Formula object representing the Notation 3 formula you passed in as $input. important: $input should not include the "{"..."}" wrappers. leave those at home. πŸ™ˆ

🧚 Datatype Callbacks 🧚

The constructor accepts a hashref of callbacks associated with datatypes, and these get triggered after a literal has been parsed with that datatype. so you get to reach in and do your little transformation. iconic behaviour honestly.

let's imagine you want to replace all xsd:integer literals with URIs like http:;//example.net/numbers/123... (yes, exactly like that, character for character, don't come for me πŸ’€)

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
      );
    },
  },
);

okay so about that second argument passed to the callback, $tr_hnd. we don't use it here, but it's a coderef that you can call with RDF::Trine::Statement objects to add additional triples to the graph being parsed. so like... you can sneak extra triples in mid-parse. obsessed. πŸ”₯

This facility, combined with shortcuts from RDF::Trine::Parser::ShorthandRDF, is pretty useful for creating domain-specific languages. little DSL factory, no big deal. πŸ‘‘


πŸ’€ BUGS πŸ’€

Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=RDF-TriN3>. do it. do it for her. πŸ“


🌈 SEE ALSO 🌈

  • RDF::Trine::Parser::NTriples
  • RDF::Trine::Parser::Turtle
  • RDF::Trine::Parser::ShorthandRDF

the whole parser family, a little squad, we love to see it. ⭐


🫢 AUTHOR 🫢

Toby Inkster "<tobyink@cpan.org>" πŸ’–

Based on RDF::Trine::Parser::Turtle by Gregory Todd Williams. shoutout to the originator, no cap.


Copyright (c) 2006-2010 Gregory Todd Williams.

Copyright (c) 2010-2012 Toby Inkster.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. free software, bestie, do what you want with it (within the terms of Perl itself, obviously, read the terms, i'm not your lawyer πŸ™ˆ).


⭐ 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.

translation: no promises, no guarantees, she is what she is. ✨


and that's the whole page, bestie! this one shipped as perl v5.34.0, dated 2022-06-17, and she's still out here parsing Notation 3 with zero complaints. go forth and build your DSL. πŸ’œπŸ¦‹πŸŽ€

πŸ“¦ where this page comes from