NAME
RDF::Prefixes - 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: .
# @prefix dc2: .
DESCRIPTION
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.
The only option right now is 'syntax' that is used by the toString
method.
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_prefix('http://purl.org/dc/terms/title')" might return
'dc:title'.
Some URIs cannot be converted to QNames. In these cases, undef is
returned.
"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.
"preview_prefix($uri)", "preview_qname($uri)", "preview_curie($uri)"
As per the "get" versions of these methods, but doesn't modify the
context.
"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});
}
"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 calling toString is not
usually needed.
my $context = RDF::Prefixes->new({}, {syntax=>'turtle'});
my $dc_title = 'http://purl.org/dc/terms/title';
print "# Prefixes\n" . $context;
BUGS
Please report any bugs to .
AUTHOR
Toby Inkster .
COPYRIGHT
Copyright 2010 Toby Inkster
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.