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@forAlldirectives it finds in the top-level graph. quick heads up bestie:@forAlldirectives 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: anRDF::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 asforAllabove, except it handles the@forSomedirectives instead. same rules, different sigil. π«parse_formula($base, $input)β hands you back anRDF::Trine::Node::Formulaobject representing the Notation 3 formula you passed in as$input. important:$inputshould 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::NTriplesRDF::Trine::Parser::TurtleRDF::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 AND LICENCE π
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
- debian bookworm: librdf-trin3-perl 0.206-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: librdf-trin3-perl 0.206-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms