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

NAME

6       RDF::NS - Just use popular RDF namespace prefixes from prefix.cc
7

SYNOPSIS

9         use RDF::NS '20181102';              # check at compile time
10         my $ns = RDF::NS->new('20181102');   # check at runtime
11
12         $ns->foaf;               # http://xmlns.com/foaf/0.1/
13         $ns->foaf_Person;        # http://xmlns.com/foaf/0.1/Person
14         $ns->foaf('Person');     # http://xmlns.com/foaf/0.1/Person
15         $ns->uri('foaf:Person'); # http://xmlns.com/foaf/0.1/Person
16
17         use RDF::NS;             # get rid if typing '$' by defining a constant
18         use constant NS => RDF::NS->new('20111208');
19         NS->foaf_Person;         # http://xmlns.com/foaf/0.1/Person
20
21         $ns->SPAQRL('foaf');     # PREFIX foaf: <http://xmlns.com/foaf/0.1/>
22         $ns->TTL('foaf');        # @prefix foaf: <http://xmlns.com/foaf/0.1/> .
23         $ns->XMLNS('foaf');      # xmlns:foaf="http://xmlns.com/foaf/0.1/"
24
25         # load your own mapping from a file
26         $ns = RDF::NS->new("mapping.txt");
27
28         # select particular mappings
29         %map = $ns->SELECT('rdf,dc,foaf');
30         $uri = $ns->SELECT('foo|bar|doz'); # returns first existing namespace
31
32         # instances of RDF::NS are just blessed hash references
33         $ns->{'foaf'};           # http://xmlns.com/foaf/0.1/
34         bless { foaf => 'http://xmlns.com/foaf/0.1/' }, 'RDF::NS';
35         print (scalar keys %$ns) . "prefixes\n";
36         $ns->COUNT;              # also returns the number of prefixes
37

DESCRIPTION

39       Hardcoding URI namespaces and prefixes for RDF applications is neither
40       fun nor maintainable.  In the end we all use more or less the same
41       prefix definitions, as collected at <http://prefix.cc>. This module
42       includes all these prefixes as defined at specific snapshots in time.
43       These snapshots correspond to version numbers of this module. By
44       selecting particular versions, you make sure that changes at prefix.cc
45       won't affect your programs.
46
47       The command line client rdfns is installed automatically with this
48       module:
49
50         $ rdfns rdf,foaf.ttl
51         @prefix foaf: <http://xmlns.com/foaf/0.1/> .
52         @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
53
54       This module does not require RDF::Trine, which is recommended
55       nevertheless.  (at least version 0.140).  If you prefer RDF::NS to
56       return instances of RDF::Trine::Node::Resource instead of plain
57       strings, use RDF::NS::Trine.  RDF::NS::URIS is a similar module that
58       returns instances of URI.
59
60       The code repository of this module contains an update script
61       <https://github.com/nichtich/RDF-NS/blob/master/update.pl> to download
62       the current prefix-namespace mappings from <http://prefix.cc>.
63

GENERAL METHODS

65       In most cases you only need the following lowercase methods.
66
67   new ( [ $file_or_date ] [ %options ] )
68       Create a new namespace mapping from a selected file, date, or hash
69       reference.  The special string "any" or the value 1 can be used to get
70       the newest mapping, but you should better select a specific version, as
71       mappings can change, violating backwards compatibility.  Supported
72       options include "warn" to enable warnings and "at" to specify a date.
73
74   "prefix"
75       Returns the namespace for prefix if namespace prefix is defined. For
76       instance "$ns->foaf" returns "http://xmlns.com/foaf/0.1/".
77
78   "prefix_name"
79       Returns the namespace plus local name, if namespace prefix is defined.
80       For instance "$ns->foaf_Person" returns
81       "http://xmlns.com/foaf/0.1/Person".
82
83   uri ( $short | "<$URI>" )
84       Expand a prefixed URI, such as "foaf:Person" or "foaf_Person".
85       Alternatively you can expand prefixed URIs with method calls, such as
86       "$ns->foaf_Person".  If you pass an URI wrapped in "<" and ">", it will
87       not be expanded but returned as given.
88

SERIALIZATION METHODS

90   TTL ( prefix[es] )
91       Returns a Turtle/Notation3 @prefix definition or a list of such
92       definitions in list context. Prefixes can be passed as single arguments
93       or separated by commas, vertical bars, and spaces.
94
95   SPARQL ( prefix[es] )
96       Returns a SPARQL PREFIX definition or a list of such definitions in
97       list context. Prefixes can be passed as single arguments or separated
98       by commas, vertical bars, and spaces.
99
100   XMLNS ( prefix[es] )
101       Returns an XML namespace declaration or a list of such declarations in
102       list context. Prefixes can be passed as single arguments or separated
103       by commas, vertical bars, and spaces.
104
105   TXT ( prefix[es] )
106       Returns a list of tabular-separated prefix-namespace-mappings.
107
108   BEACON ( prefix[es] )
109       Returns a list of BEACON format prefix definitions (not including
110       prefixes).
111

LOOKUP METHODS

113   PREFIX ( $uri )
114       Get a prefix of a namespace URI, if it is defined. This method does a
115       reverse lookup which is less performant than the other direction. If
116       multiple prefixes are defined, the first in sorted order is returned.
117       If you need to call this method frequently and with deterministic
118       response, better create a reverse hash (method REVERSE).
119
120   PREFIXES ( $uri )
121       Get all known prefixes of a namespace URI in sorted order.
122
123   REVERSE
124       Calling "$ns->REVERSE" is equal to "RDF::SN->new($ns)". See RDF::SN for
125       details.
126
127   SELECT ( prefix[es] )
128       In list context, returns a sorted list of prefix-namespace pairs, which
129       can be used to assign to a hash. In scalar context, returns the
130       namespace of the first prefix that was found. Prefixes can be passed as
131       single arguments or separated by commas, vertical bars, and spaces.
132

INTERNAL METHODS

134   SET ( $prefix => $namespaces [, $warn ] )
135       Set or add a namespace mapping. Errors are ignored unless enabled as
136       warnings with the third argument. Returns true if the mapping was
137       successfully added.
138
139   MAP ( $code [, prefix[es] ] )
140       Internally used to map particular or all prefixes. Prefixes can be
141       selected as single arguments or separated by commas, vertical bars, and
142       spaces. In scalar context, $_ is set to the first existing prefix (if
143       found) and $code is called. In list context, found prefixes are sorted
144       at mapped with $code.
145
146   GET ( $uri )
147       This method is used internally to create URIs as return value of the
148       URI method and all lowercase shortcut methods, such as "foaf_Person".
149       By default it just returns $uri unmodified.
150

SEE ALSO

152       There are several other CPAN modules to deal with IRI namespaces, for
153       instance RDF::Trine::Namespace, RDF::Trine::NamespaceMap,
154       URI::NamespaceMap, RDF::Prefixes, RDF::Simple::NS,
155       RDF::RDFa::Parser::Profile::PrefixCC, Class::RDF::NS, XML::Namespace,
156       XML::CommonNS etc.
157
159       This software is copyright (c) 2013- by Jakob Voss.
160
161       This is free software; you can redistribute it and/or modify it under
162       the same terms as the Perl 5 programming language system itself.
163
164
165
166perl v5.28.0                      2018-11-02                      RDF::NS(3pm)
Impressum