1RDF::Prefixes(3)      User Contributed Perl Documentation     RDF::Prefixes(3)
2
3
4

NAME

6       RDF::Prefixes - simple way to turn URIs into QNames
7

SYNOPSIS

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

DESCRIPTION

16       This module is not so much for managing namespaces/prefixes in code
17       (see RDF::Trine::NamespaceMap for that), but as a helper for code that
18       serialises data using namespaces.
19
20       It generates pretty prefixes, reducing "http://purl.org/dc/terms/" to
21       "dc" rather than something too generic like like "ns01", and provides a
22       context for keeping track of namespaces already used, so that when
23       "http://purl.org/dc/elements/1.1/" is encountered, it won't stomp on
24       the previous definition of "dc".
25
26   Constructor
27       "new(\%suggestions, \%options)"
28           Creates a new RDF prefix context.
29
30           Suggestions for prefix mappings may be given, but there's no
31           guarantee that they'll be used.
32
33           The only option right now is 'syntax' that is used by the to_string
34           method.
35
36           Both hashrefs are optional.
37
38   Methods
39       "get_prefix($uri)"
40           Gets the prefix associated with a URI. e.g.
41           "get_prefix('http://purl.org/dc/terms/')" might return 'dc'.
42
43       "get_qname($uri)"
44           Gets a QName for a URI. e.g.
45           "get_qname('http://purl.org/dc/terms/title')" might return
46           'dc:title'.
47
48           Some URIs cannot be converted to QNames. In these cases, undef is
49           returned.
50
51       "get_curie($uri)"
52           As per "get_qname", but allows for more relaxed return values,
53           suitable for RDFa, Turtle or Notation 3, but not RDF/XML. Should
54           never need to return undef.
55
56       "preview_prefix($uri)", "preview_qname($uri)", "preview_curie($uri)"
57           As per the "get" versions of these methods, but doesn't modify the
58           context.
59
60       "to_hashref"
61           Returns a hashref of prefix mappings used so far. This is not
62           especially necessary as the object may be treated as a hashref
63           directly:
64
65             foreach my $prefix (keys %$context)
66             {
67               printf("%s => %s\n", $prefix, $context->{$prefix});
68             }
69
70       "TO_JSON"
71           A synonym for to_hashref, provided for the benefit of the JSON
72           package.
73
74       "rdfa"
75           Return the same data as "to_hashref", but as a string suitable for
76           placing in an RDFa 1.1 prefix attribute.
77
78       "sparql"
79           Return the same data as "to_hashref", but as a string suitable for
80           prefixing a SPARQL query.
81
82       "turtle"
83           Return the same data as "to_hashref", but as a string suitable for
84           prefixing a Turtle or Notation 3 file.
85
86       "xmlns"
87           Return the same data as "to_hashref", but as a string of xmlns
88           attributes, suitable for use with RDF/XML or RDFa.
89
90       "to_string"
91           Calls either "rdfa", "sparql", "turtle" (the default) or "xmlns",
92           based on the 'syntax' option passed to the constructor. This module
93           overloads the stringification operator, so explicitly calling
94           to_string is rarely necessary.
95
96            my $context  = RDF::Prefixes->new({}, {syntax=>'turtle'});
97            my $dc_title = 'http://purl.org/dc/terms/title';
98            print "# Prefixes\n" . $context;
99
100   Internationalisation
101       Strings passed to and from this module are expected to be utf8
102       character strings, not byte strings. This is not explicitly checked
103       for, but will be checked in a future version, so be warned!
104
105       URIs containing non-Latin characters should "just work".
106

BUGS

108       Please report any bugs to <http://rt.cpan.org/>.
109

AUTHOR

111       Toby Inkster <tobyink@cpan.org>.
112
114       Copyright 2010-2013 Toby Inkster
115
116       This library is free software; you can redistribute it and/or modify it
117       under the same terms as Perl itself.
118

DISCLAIMER OF WARRANTIES

120       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
121       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
122       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
123
124
125
126perl v5.32.0                      2020-07-28                  RDF::Prefixes(3)
Impressum