RDF::Prefixes(3pm)

πŸ’– RDF::Prefixes(3pm) β€” User Contributed Perl Documentation πŸ’–

okay bestie, this is RDF::Prefixes β€” the perl module that takes your big ugly URIs and turns them into cute little QNames. it's in the User Contributed Perl Documentation section, and it's about to be your new favorite thing, no cap. πŸ¦‹


✨ NAME ✨

RDF::Prefixes β€” a simple way to turn URIs into QNames πŸ’…


🌸 SYNOPSIS 🌸

my $context = RDF::Prefixes->new;
say $context->qname('http://purl.org/dc/terms/title');  # dc:title
say $context->qname('http://example.net/rdf/dc#title'); # dc2:title
say $context->turtle;  # @prefix dc: <http://purl.org/dc/terms/> .
                       # @prefix dc2: <http://example.net/rdf/dc#> .

like… look at that. it just knows. iconic. ✨


πŸŽ€ DESCRIPTION πŸŽ€

okay so real talk: this module is not so much for managing namespaces/prefixes in code (for that, go see RDF::Trine::NamespaceMap, bestie), but rather it's a helper for code that serialises data using namespaces. it's giving backstage crew energy. 🫢

it generates pretty prefixes, reducing http://purl.org/dc/terms/ down to dc instead of something too generic like like ns01 (yes, the original page says "like like", and honestly? relatable, we've all been there 😭). and it also gives you a context for keeping track of namespaces already used, so that when http://purl.org/dc/elements/1.1/ shows up, it won't stomp on the previous definition of dc. no namespace drama on this campus. πŸ’€

🧚 Constructor

new(\%suggestions, \%options)

  • Creates a new RDF prefix context. ✨
  • Suggestions for prefix mappings may be given, but there's no guarantee that they'll be used. it's a suggestion, not a contract, bestie.
  • The only option right now is 'syntax' that is used by the to_string method.
  • Both hashrefs are optional. πŸŽ€

πŸ‘‘ Methods

⚠️ Some URIs cannot be converted to QNames. In these cases, undef is returned. not everything can be slayed, and that's okay. πŸ’”
  • get_curie($uri) β€” As per get_qname, but allows for more relaxed return values, suitable for RDFa, Turtle or Notation 3, but not RDF/XML. Should never need to return undef. lowkey the chill one of the group. 🌈
  • preview_prefix($uri), preview_qname($uri), preview_curie($uri) β€” As per the get versions of these methods, but doesn't modify the context. it's the window-shopping version, no receipts. πŸ™ˆ
  • to_hashref β€” Returns a hashref of prefix mappings used so far. This is not especially necessary as the object may be treated as a hashref directly:
foreach my $prefix (keys %$context)
{
  printf("%s => %s\n", $prefix, $context->{$prefix});
}
  • TO_JSON β€” A synonym for to_hashref, provided for the benefit of the JSON package. shoutout to the JSON girlies. πŸ“
  • rdfa β€” Return the same data as to_hashref, but as a string suitable for placing in an RDFa 1.1 prefix attribute.
  • sparql β€” Return the same data as to_hashref, but as a string suitable for prefixing a SPARQL query.
  • turtle β€” Return the same data as to_hashref, but as a string suitable for prefixing a Turtle or Notation 3 file.
  • xmlns β€” Return the same data as to_hashref, but as a string of xmlns attributes, suitable for use with RDF/XML or RDFa.
  • to_string β€” Calls either rdfa, sparql, turtle (the default) or xmlns, based on the 'syntax' option passed to the constructor. This module overloads the stringification operator, so explicitly calling to_string is rarely necessary. it just works when you print it. main character behaviour fr fr. πŸ‘‘
 my $context  = RDF::Prefixes->new({}, {syntax=>'turtle'});
 my $dc_title = 'http://purl.org/dc/terms/title';
 print "# Prefixes\n" . $context;

πŸ’œ Internationalisation

Strings passed to and from this module are expected to be utf8 character strings, not byte strings. This is not explicitly checked for, but will be checked in a future version, so be warned! 🚨

URIs containing non-Latin characters should "just work". and honestly? we love that for them. 🌍✨


πŸ› BUGS πŸ›

Please report any bugs to <http://rt.cpan.org/>. (a link! in a manpage! in this economy! 🫢)


🌟 AUTHOR 🌟

Toby Inkster <tobyink@cpan.org>.


Copyright 2010-2013 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.

no warranty bestie, it said what it said, all caps and everything, respect the caps. 😀

and that's the whole page, pookie πŸ’– this was RDF::Prefixes(3pm) from the User Contributed Perl Documentation, generated for perl v5.34.0 and dated 2022-06-17. mwah. go turn some URIs into QNames and text me when you do. πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from