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

πŸ“¦
version 1.019 Β· 7 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– RDF::Trine::Parser(3pm) πŸ’–

okay bestie, gather round, because we're talking about RDF::Trine::Parser β€” the RDF Parser class, straight out of the User Contributed Perl Documentation section, and yes she's serving version 1.019 πŸ’…


✨ NAME ✨

RDF::Trine::Parser β€” it's the RDF Parser class, no cap πŸŽ€

🌸 VERSION 🌸

This doc is describing RDF::Trine::Parser version 1.019. iconic. no notes. πŸ’–

πŸ¦‹ SYNOPSIS πŸ¦‹

here's the vibe, literally copy-paste energy:

use RDF::Trine::Parser;

RDF::Trine::Parser->parse_url_into_model( $url, $model );

my $parser     = RDF::Trine::Parser->new( 'turtle' );
$parser->parse_into_model( $base_uri, $rdf, $model );

$parser->parse_file_into_model( $base_uri, 'data.ttl', $model );

look at her go 🫢

πŸ’œ DESCRIPTION πŸ’œ

so RDF::Trine::Parser is a base class for RDF parsers, and she's giving factory energy too. you can use her to build parser objects by name or by media type with the new method β€” OR you can use her to abstract away the whole "which parser do I even pick" situation based on the media type of RDF content you pulled off the network, which is what the parse_url_into_model method is for. main character delegation, honestly. πŸ‘‘

πŸ”₯ METHODS πŸ”₯

  • media_type β€” hands you the canonical media type that belongs to this parser. that's it, that's the whole job. ✨
  • media_types β€” hands you the media types (plural, she contains multitudes 🌈) associated with this parser.
  • parser_by_media_type ( $media_type ) β€” gives you back the parser class that's the right fit for parsing content of the specified media type. and if there's no appropriate parser to be found? you get undef. 😭 (yeah, the original says "if not appropriate parser is found" β€” we're keeping that typo's spirit, bestie.)
  • guess_parser_by_filename ( $filename ) β€” best-guess time πŸŽ€ returns the best-guess parser class for parsing a file with the given filename. and if there's no appropriate parser found, it just defaults to RDF::Trine::Parser::RDFXML. default queen.
  • new ( $parser_name, @args ) β€” returns a brand new RDF::Trine::Parser object for the parser with the specified name (like rdfxml or turtle, iykyk). if no parser with that name exists, she throws a RDF::Trine::Error::ParserError exception. not a vibe, but it's the rules. πŸ’€

Any @args get passed straight through to the format-specific parser constructor. no middleman, no editing.

And if @args contains the key-value pair (canonicalize => 1), then literal value canonicalization will be attempted during parsing β€” with warnings being emitted for invalid lexical forms for recognized datatypes. so like, she tries, and she tells you when the lexical form is giving nonsense. πŸ‘€

  • parse_url_into_model ( $url, $model [, %args] ) β€” she retrieves the content from $url and attempts to parse the resulting RDF into $model, using a parser chosen by the associated content media type. slay. ✨

If %args contains a 'content_cb' key whose value is a CODE reference, that callback function gets called after a successful response, like this:

$content_cb->( $url, $content, $http_response_object )

If %args contains a 'useragent' key whose value is an LWP::UserAgent object, then that object is used to retrieve the requested URL β€” with no configuration (so no setting the Accept: header, none of the stuff that would ordinarily happen). otherwise, the default user agent (default_useragent in RDF::Trine) gets cloned and configured to retrieve content that will be acceptable to any available parser. teamwork, honestly. 🫢

  • parse_url ( $url, \&handler [, %args] ) β€” retrieves the content from $url and attempts to parse the resulting RDF. for every parsed RDF triple, &handler gets called with the triple as an argument. other than that little twist, this method acts just like parse_url_into_model. same girl, different hat. πŸŽ€
  • parse_into_model ( $base_uri, $data, $model [, context => $context] ) β€” parses the bytes in $data, using the given $base_uri. for each RDF statement parsed, she'll call $model->add_statement( $statement ). ✨
  • parse_file_into_model ( $base_uri, $fh, $model [, context => $context] ) β€” parses all data read from the filehandle or file $fh, using the given $base_uri. for each RDF statement parsed, she'll call $model->add_statement( $statement ). same energy as above but from a file, periodt. πŸ’…
  • parse_file ( $base_uri, $fh, $handler ) β€” parses all data read from the filehandle or file $fh, using the given $base_uri. if $fh is a filename, this method can guess the associated parse. for each RDF statement parsed, $handler->( $st ) gets called. 🌸
  • parse ( $base_uri, $rdf, \&handler ) β€” okay so ngl, the original doc just... lists this one and moves on. no description. she's mysterious. she's the silent main character. we respect her privacy. πŸ™ˆ
  • new_bnode_prefix () β€” returns a new prefix to be used in the construction of blank node identifiers. if either Data::UUID or UUID::Tiny are available, they get used to construct a globally unique bnode prefix. otherwise? you get an empty string. shrug, bestie. πŸ’€
  • default_accept_header β€” returns the default HTTP Accept header value used when requesting RDF content (like, for example, in parse_url_into_model) that may be parsed by one of the available RDF::Trine::Parser subclasses.

and by default, RDF/XML and Turtle are preferred over other media types. the favorites. the chosen ones. πŸ‘‘


πŸ’€ BUGS πŸ’€

found a bug? want a feature? pls report it through the GitHub web interface at <https://github.com/kasei/perlrdf/issues>. she's listening, she wants the tea. πŸ“

πŸ‘‘ AUTHOR πŸ‘‘

Gregory Todd Williams <gwilliams@cpan.org> β€” the icon, the legend, the author of the whole thing πŸ’–

Copyright (c) 2006-2012 Gregory Todd Williams. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. legal queen, protecting her work, as she should. πŸŽ€


and that's the whole page, bestie πŸ¦‹ that was perl v5.38.2, dated 2024-01-13, from the RDF::T...Parser(3pm) page β€” thanks for reading, mwah, go parse something iconic πŸ’…βœ¨

πŸ“¦ where this page comes from