XML::Atom::OWL(3pm)

πŸ’– XML::Atom::OWL πŸ’–

okay bestie, so this is XML::Atom::OWL(3pm) β€” a lil Perl module from the User Contributed Perl Documentation corner of the world β€” and it's literally just here to take an Atom file and turn it into RDF. slay.


✨ NAME ✨

XML::Atom::OWL β€” parse an Atom file into RDF πŸ¦‹


🌸 SYNOPSIS 🌸

use XML::Atom::OWL;

$parser = XML::Atom::OWL->new($xml, $baseuri);
$graph  = $parser->graph;

like. that's it. that's the whole vibe. πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

The interface here is pretty similar to RDF::RDFa::Parser, if you know her. iykyk. πŸ’–

✨ Constructor ✨

  • new($xml, $baseuri, \%options, $storage) β€” this method creates a brand new XML::Atom::OWL object and hands it right back to you. ✨

The $xml variable may contain an XML (Atom) string, or an XML::LibXML::Document object. If it's a string, the document gets parsed using XML::LibXML, which will throw an exception if it is not well-formed. and here's the thing: XML::Atom::OWL does not catch the exception. so if it's malformed, it's giving uncaught exception energy, no cap. πŸ’€

The base URI is used to resolve relative URIs found in the document. 🧚

Currently only one option is defined: 'no_fetch_content_src', a boolean indicating whether <content src> URLs should be automatically fetched and added to the model as if inline content had been provided. They are fetched by default, but it's pretty rare for feeds to include this attribute. lowkey niche. πŸ™ˆ

$storage is an RDF::Trine::Storage object. If undef, then a new temporary store is created. very demure, very mindful. 🫢

✨ Public Methods ✨

  • uri β€” returns the base URI of the document being parsed. This will usually be the same as the base URI provided to the constructor. 🌈

Optionally it may be passed a parameter β€” an absolute or relative URI β€” in which case it returns the same URI which it was passed as a parameter, but as an absolute URI, resolved relative to the document's base URI. πŸ”₯

This seems like two unrelated functions, but if you consider the consequence of passing a relative URI consisting of a zero-length string, it in fact makes sense. the way that it makes sense... iconic. πŸ‘‘

  • dom β€” returns the parsed XML::LibXML::Document. πŸŽ€
  • graph β€” this method will return an RDF::Trine::Model object with all statements of the full graph. ✨

This method automatically calls consume. she does it herself, no need to ask. πŸ’…

  • root_identifier β€” returns the blank node or URI for the root element of the Atom document as an RDF::Trine::Node. 🌸

Calls consume automatically. yes queen, she's self-sufficient.

  • set_callbacks(\%callbacks) β€” set callback functions for the parser to call on certain events. These are only necessary if you want to do something especially unusual. ⭐
$p->set_callbacks({
  'pretriple_resource' => sub { ... } ,
  'pretriple_literal'  => sub { ... } ,
  'ontriple'           => undef ,
  });

For details of the callback functions, see the section CALLBACKS. set_callbacks must be used before consume. set_callbacks itself returns a reference to the parser object itself. πŸ¦‹

  • consume β€” the document is parsed. Triples extracted from the document are passed to the callbacks as each one is found; triples are made available in the model returned by the graph method. πŸ’–

This function returns the parser object itself, making it easy to abbreviate several of XML::Atom::OWL's functions:

my $iterator = XML::Atom::OWL->new(undef, $uri)
               ->consume->graph->as_stream;

You probably only need to call this explicitly if you're using callbacks. otherwise let the other methods do their lil thing. 🧚


πŸ’… CALLBACKS πŸ’…

Several callback functions are provided. These may be set using the set_callbacks function, which taskes a hashref of keys pointing to coderefs. The keys are named for the event to fire the callback on. πŸ”₯

✨ pretriple_resource ✨

This is called when a triple has been found, but before preparing the triple for adding to the model. It is only called for triples with a non-literal object value. no literals allowed at this party. πŸ™…

The parameters passed to the callback function are:

  • A reference to the XML::Atom::OWL object
  • A reference to the XML::LibXML::Element being parsed
  • Subject URI or bnode (string)
  • Predicate URI (string)
  • Object URI or bnode (string)
  • Graph URI or bnode (string or undef)

The callback should return 1 to tell the parser to skip this triple (not add it to the graph); return 0 otherwise. so 1 = nah, 0 = yeah. noted. ⭐

✨ pretriple_literal ✨

This is the equivalent of pretriple_resource, but is only called for triples with a literal object value. πŸŽ€

The parameters passed to the callback function are:

  • A reference to the XML::Atom::OWL object
  • A reference to the XML::LibXML::Element being parsed
  • Subject URI or bnode (string)
  • Predicate URI (string)
  • Object literal (string)
  • Datatype URI (string or undef)
  • Language (string or undef)
  • Graph URI or bnode (string or undef)
Beware: sometimes both a datatype and a language will be passed. This goes beyond the normal RDF data model.) 😭 the chaos of it all.

The callback should return 1 to tell the parser to skip this triple (not add it to the graph); return 0 otherwise. πŸ’…

✨ ontriple ✨

This is called once a triple is ready to be added to the graph. (After the pretriple callbacks.) The parameters passed to the callback function are:

  • A reference to the XML::Atom::OWL object
  • A reference to the XML::LibXML::Element being parsed
  • An RDF::Trine::Statement object.

The callback should return 1 to tell the parser to skip this triple (not add it to the graph); return 0 otherwise. The callback may modify the RDF::Trine::Statement object. yes you can touch it, it's yours now. πŸ‘‘


πŸ’€ BUGS πŸ’€

Please report any bugs to <http://rt.cpan.org/>. do your civic duty bestie 🫢


🌈 SEE ALSO 🌈

RDF::Trine, XML::Atom::FromOWL.

<http://www.perlrdf.org/>.


πŸ‘‘ AUTHOR πŸ‘‘

Toby Inkster <tobyink@cpan.org>. the icon behind the curtain πŸ’–


Copyright 2010-2011 Toby Inkster

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πŸŽ€


πŸ¦‹ 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.

fr fr, no promises, she said what she said. 😭

and that's the whole page bestie!! this beauty is running on perl v5.34.0, dated 2022-06-28, and it lives in the XML::Atom::OWL(3pm) manual β€” mwah πŸ’‹ go parse something cute πŸ’–βœ¨

πŸ“¦ where this page comes from