| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package RDF::Simple::NS; |
|
2
|
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
64
|
use strict; |
|
|
9
|
|
|
|
|
22
|
|
|
|
9
|
|
|
|
|
6607
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our |
|
6
|
|
|
|
|
|
|
$VERSION = do { my @r = (q$Revision: 1.4 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
|
9
|
16
|
|
|
16
|
0
|
36
|
my $class = shift; |
|
10
|
16
|
|
|
|
|
39
|
my %p = @_; |
|
11
|
16
|
|
33
|
|
|
140
|
return bless \%p, ref $class || $class; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub baseuri { |
|
15
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
16
|
0
|
|
|
|
|
0
|
my $baseuri = shift; |
|
17
|
0
|
|
0
|
|
|
0
|
$self->{baseuri} ||= $baseuri; |
|
18
|
0
|
|
|
|
|
0
|
return $self->{baseuri}; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub from_qname { |
|
22
|
0
|
|
|
0
|
1
|
0
|
my ($self,$name) = @_; |
|
23
|
0
|
|
|
|
|
0
|
my $ns; |
|
24
|
0
|
0
|
0
|
|
|
0
|
if (($name =~ m/\:/) and ($name !~ m/^http/)) { |
|
25
|
0
|
|
|
|
|
0
|
my ($space,$n) = split(/:/,$name); |
|
26
|
0
|
|
|
|
|
0
|
$ns = $self->entity_to_namespace($space); |
|
27
|
0
|
|
|
|
|
0
|
$name = $n; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
0
|
|
0
|
|
|
0
|
$ns ||= $self->baseuri; |
|
30
|
0
|
|
|
|
|
0
|
return $ns.$name; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub qname { |
|
34
|
42
|
|
|
42
|
1
|
73
|
my ($self,$thing) = @_; |
|
35
|
42
|
|
|
|
|
196
|
my ($ns,$part) = $thing =~ /(.+[\/|\#])(.+)/; |
|
36
|
|
|
|
|
|
|
|
|
37
|
42
|
|
|
|
|
83
|
my $entity = $self->namespace_to_entity($ns); |
|
38
|
42
|
100
|
|
|
|
131
|
$thing = $entity.':'.$part if $entity; |
|
39
|
42
|
|
|
|
|
103
|
return $thing; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Retrieve or add to the entity to namespace lookup hash |
|
43
|
|
|
|
|
|
|
sub lookup |
|
44
|
|
|
|
|
|
|
{ |
|
45
|
552
|
|
|
552
|
1
|
770
|
my $self = shift; |
|
46
|
552
|
|
|
|
|
750
|
my %add; |
|
47
|
552
|
50
|
|
|
|
1041
|
if (ref $_[0] eq 'HASH') |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
0
|
|
|
|
|
0
|
%add = %{$_[0]}; |
|
|
0
|
|
|
|
|
0
|
|
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
else |
|
52
|
|
|
|
|
|
|
{ |
|
53
|
552
|
|
|
|
|
967
|
%add = @_; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
$self->{_lookup} ||= |
|
56
|
|
|
|
|
|
|
{ |
|
57
|
552
|
|
100
|
|
|
1343
|
foaf => 'http://xmlns.com/foaf/0.1/', |
|
58
|
|
|
|
|
|
|
dc => 'http://purl.org/dc/elements/1.1/', |
|
59
|
|
|
|
|
|
|
rdfs => "http://www.w3.org/2000/01/rdf-schema#", |
|
60
|
|
|
|
|
|
|
daml => 'http://www.w3.org/2001/10/daml+oil#', |
|
61
|
|
|
|
|
|
|
space => 'http://frot.org/space/0.1/', |
|
62
|
|
|
|
|
|
|
geo => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
63
|
|
|
|
|
|
|
rdf => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", |
|
64
|
|
|
|
|
|
|
owl => 'http://www.w3.org/2002/07/owl#', |
|
65
|
|
|
|
|
|
|
ical => 'http://www.w3.org/2002/12/cal/ical#', |
|
66
|
|
|
|
|
|
|
dcterms=>"http://purl.org/dc/terms/", |
|
67
|
|
|
|
|
|
|
wiki=>"http://purl.org/rss/1.0/modules/wiki/", |
|
68
|
|
|
|
|
|
|
chefmoz=>"http://chefmoz.org/rdf/elements/1.0/", |
|
69
|
|
|
|
|
|
|
wot => "http://xmlns.com/wot/0.1/", |
|
70
|
|
|
|
|
|
|
cng => 'http://iconocla.st/cng#', |
|
71
|
|
|
|
|
|
|
status => 'http://www.w3.org/2003/06/sw-vocab-status/ns#', |
|
72
|
|
|
|
|
|
|
}; |
|
73
|
552
|
|
|
|
|
1140
|
foreach (keys %add) |
|
74
|
|
|
|
|
|
|
{ |
|
75
|
154
|
|
|
|
|
399
|
$self->{_lookup}->{$_} = $add{$_}; |
|
76
|
|
|
|
|
|
|
} # foreach |
|
77
|
552
|
|
|
|
|
725
|
return %{$self->{_lookup}}; |
|
|
552
|
|
|
|
|
3989
|
|
|
78
|
|
|
|
|
|
|
} # lookup |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub entity_to_namespace { |
|
81
|
395
|
|
|
395
|
1
|
626
|
my ($self,$entity) = @_; |
|
82
|
395
|
|
|
|
|
645
|
my %lookup = $self->lookup; |
|
83
|
395
|
|
|
|
|
1011
|
my $e = $lookup{$entity}; |
|
84
|
395
|
|
|
|
|
1746
|
return $e; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub uri { |
|
88
|
395
|
|
|
395
|
1
|
717
|
my ($self,$entity) = @_; |
|
89
|
395
|
50
|
|
|
|
815
|
if ($entity =~ m/\:/) { |
|
90
|
0
|
|
|
|
|
0
|
return $self->from_qname($entity); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
else { |
|
93
|
395
|
|
|
|
|
741
|
return $self->entity_to_namespace($entity); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub namespace_to_entity { |
|
98
|
42
|
|
|
42
|
1
|
102
|
my ($self,$ns) = @_; |
|
99
|
|
|
|
|
|
|
#$ns =~ s/\#//g; |
|
100
|
42
|
|
|
|
|
74
|
my %look = reverse $self->lookup; |
|
101
|
42
|
100
|
100
|
|
|
273
|
return $look{$ns} if $ns and (exists $look{$ns}); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub prefix { |
|
105
|
27
|
|
|
27
|
1
|
51
|
my ($self,$string) = @_; |
|
106
|
27
|
50
|
|
|
|
67
|
if ($string) { |
|
107
|
27
|
|
|
|
|
140
|
$string =~ s/:.+//; |
|
108
|
27
|
50
|
|
|
|
98
|
return $string if $string; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
0
|
|
|
|
|
|
return undef; |
|
111
|
|
|
|
|
|
|
} # prefix |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 RDF::Simple::NS |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
A utility class to help deal with RDF namespaces |
|
120
|
|
|
|
|
|
|
(converting between short (qualified) names |
|
121
|
|
|
|
|
|
|
and full URLs for XML namespaces. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $ns = RDF::Simple::NS->new; |
|
126
|
|
|
|
|
|
|
$ns->lookup('foaf'=>'http://xmlns.com/foaf/0.1/'); |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 METHODS |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head3 from_qname |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head3 qname |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head3 lookup |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$ns->lookup('short name'=>'http://full.path.to/namespace#'); |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Add an alias for a namespace (this will be used in the serialisation) |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head3 entity_to_namespace |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head3 uri |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head3 namespace_to_entity |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head3 prefix |