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 theto_stringmethod. - Both hashrefs are optional. π
π Methods
get_prefix($uri)β Gets the prefix associated with a URI. e.g.get_prefix('http://purl.org/dc/terms/')might return'dc'.get_qname($uri)β Gets a QName for a URI. e.g.get_qname('http://purl.org/dc/terms/title')might return'dc:title'.
β οΈ 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 perget_qname, but allows for more relaxed return values, suitable for RDFa, Turtle or Notation 3, but not RDF/XML. Should never need to returnundef. lowkey the chill one of the group. πpreview_prefix($uri),preview_qname($uri),preview_curie($uri)β As per thegetversions 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 forto_hashref, provided for the benefit of the JSON package. shoutout to the JSON girlies. πrdfaβ Return the same data asto_hashref, but as a string suitable for placing in an RDFa 1.1prefixattribute.sparqlβ Return the same data asto_hashref, but as a string suitable for prefixing a SPARQL query.turtleβ Return the same data asto_hashref, but as a string suitable for prefixing a Turtle or Notation 3 file.xmlnsβ Return the same data asto_hashref, but as a string ofxmlnsattributes, suitable for use with RDF/XML or RDFa.to_stringβ Calls eitherrdfa,sparql,turtle(the default) orxmlns, based on the'syntax'option passed to the constructor. This module overloads the stringification operator, so explicitly callingto_stringis 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 π
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
- debian bookworm: librdf-prefixes-perl 0.005-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: librdf-prefixes-perl 0.005-2 Β· 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