line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
2
|
|
|
|
|
|
|
#use warnings; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package RDF::Notation3::Template::TXML; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require 5.005_62; |
7
|
1
|
|
|
1
|
|
20
|
use RDF::Notation3; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1853
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
############################################################ |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@RDF::Notation3::Template::TXML::ISA = qw(RDF::Notation3); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _process_statement { |
15
|
0
|
|
|
0
|
|
|
my ($self, $subject, $properties) = @_; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
$subject = $self->_expand_prefix($subject); |
18
|
0
|
|
|
|
|
|
$subject =~ s/^<(.*)>$/$1/; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $prev; |
21
|
0
|
|
|
|
|
|
my $j = 0; |
22
|
0
|
|
|
|
|
|
foreach (@$properties) { |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if ($_->[0] ne 'i') { |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
0
|
|
|
|
if ($j == 0 or $prev eq 'i') { |
27
|
0
|
|
|
|
|
|
my @attr = (); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# nodeID is used for blank nodes |
30
|
0
|
0
|
|
|
|
|
if ($subject =~ /^$self->{ansuri}(.*)$/) { |
31
|
0
|
|
|
|
|
|
push @attr, ['rdf:nodeID' => "$self->{nIDpref}$1"]; |
32
|
|
|
|
|
|
|
} else { |
33
|
0
|
|
|
|
|
|
push @attr, ['rdf:about' => $subject]; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
$self->doStartElement('rdf:Description', \@attr); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my ($attr, $pred) = $self->_process_predicate($_->[0]); |
40
|
0
|
|
|
|
|
|
$pred =~ s/^:(.*)$/$1/; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
for (my $i = 1; $i < scalar @$_; $i++) { |
43
|
0
|
|
|
|
|
|
$_->[$i] = $self->_expand_prefix($_->[$i]); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my @attr = @$attr; |
46
|
0
|
|
|
|
|
|
my $val = ''; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# URI |
49
|
0
|
0
|
|
|
|
|
if ($_->[$i] =~ s/^<(.*)>$/$1/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# nodeID is used for blank nodes |
51
|
0
|
0
|
|
|
|
|
if ($_->[$i] =~ /^$self->{ansuri}(.*)$/) { |
52
|
0
|
|
|
|
|
|
push @attr, ['rdf:nodeID' => "$self->{nIDpref}$1"]; |
53
|
|
|
|
|
|
|
} else { |
54
|
0
|
|
|
|
|
|
push @attr, ['rdf:resource' => $_->[$i]]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# string2 |
58
|
|
|
|
|
|
|
} elsif ($_->[$i] =~ s/^"""(.*)"""$/$1/s) { |
59
|
0
|
|
|
|
|
|
$val = $_->[$i]; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# string1 |
62
|
|
|
|
|
|
|
} elsif ($_->[$i] =~ s/^"(.*)"$/$1/) { |
63
|
0
|
|
|
|
|
|
$val = $_->[$i]; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} else { |
66
|
0
|
|
|
|
|
|
$self->_do_error(402, $_->[$i]); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# # URI |
70
|
|
|
|
|
|
|
# $_->[$i] =~ s/^<(.*)>$/$1/ and |
71
|
|
|
|
|
|
|
# push @attr, ['rdf:resource' => $_->[$i]]; |
72
|
|
|
|
|
|
|
# # string2 |
73
|
|
|
|
|
|
|
# $_->[$i] =~ s/^"""(.*)"""$/$1/s and |
74
|
|
|
|
|
|
|
# $val = $_->[$i]; |
75
|
|
|
|
|
|
|
# # string1 |
76
|
|
|
|
|
|
|
# $_->[$i] =~ s/^"(.*)"$/$1/ and |
77
|
|
|
|
|
|
|
# $val = $_->[$i]; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# escaping literals |
80
|
0
|
|
|
|
|
|
$val =~ s/</g; |
81
|
0
|
|
|
|
|
|
$val =~ s/>/>/g; |
82
|
0
|
|
|
|
|
|
$val =~ s/&/&/g; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$self->doElement($pred, \@attr, $val); |
85
|
0
|
|
|
|
|
|
$self->{count}++; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
0
|
|
|
|
if ($j == scalar @$properties - 1 or |
89
|
|
|
|
|
|
|
($properties->[$j+1]->[0] eq 'i')) { |
90
|
0
|
|
|
|
|
|
$self->doEndElement('rdf:Description'); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} else { |
94
|
|
|
|
|
|
|
# inverse mode (is, <-) |
95
|
0
|
|
|
|
|
|
for (my $i=2; $i < scalar @$_; $i++) { |
96
|
0
|
|
|
|
|
|
$_->[$i] = $self->_expand_prefix($_->[$i]); |
97
|
0
|
|
|
|
|
|
$_->[$i] =~ s/^<(.*)>$/$1/; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my @attr = (); |
100
|
0
|
|
|
|
|
|
push @attr, [about => $_->[$i]]; |
101
|
0
|
|
|
|
|
|
$self->doStartElement('rdf:Description', \@attr); |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my ($attr, $pred) = $self->_process_predicate($_->[1]); |
104
|
0
|
|
|
|
|
|
my @attr2 = @$attr; |
105
|
0
|
|
|
|
|
|
$pred =~ s/^:(.*)$/$1/; |
106
|
0
|
|
|
|
|
|
push @attr2, ['rdf:resource' => $subject]; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$self->doElement($pred, \@attr2, ''); |
109
|
0
|
|
|
|
|
|
$self->{count}++; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
$self->doEndElement('rdf:Description'); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
0
|
|
|
|
|
|
$prev = $_->[0]; |
115
|
0
|
|
|
|
|
|
$j++; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _expand_prefix { |
121
|
0
|
|
|
0
|
|
|
my ($self, $qname) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
foreach (keys %{$self->{ns}->{$self->{context}}}) { |
|
0
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$qname =~ s/^$_:(.*)$/<$self->{ns}->{$self->{context}}->{$_}$1>/; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
if ($qname =~ /^([_a-zA-Z]\w*)*:[a-zA-Z]\w*$/) { |
128
|
0
|
|
|
|
|
|
$self->_do_error(106, $qname); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return $qname; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub _process_predicate { |
136
|
0
|
|
|
0
|
|
|
my ($self, $name) = @_; |
137
|
0
|
|
|
|
|
|
my @attr = (); |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my $p = ''; |
140
|
0
|
|
|
|
|
|
my $pushed = 0; |
141
|
0
|
0
|
|
|
|
|
if ($name =~ /^([_a-zA-Z]\w*)*:[a-zA-Z]\w*$/) { |
142
|
0
|
|
|
|
|
|
$p = $1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
} else { # not a QName - must be turned to QName |
145
|
0
|
|
|
|
|
|
my $qnamed = 0; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# checking if the NS already exists |
148
|
0
|
|
|
|
|
|
foreach (keys %{$self->{ns}->{$self->{context}}}) { |
|
0
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
my $ns = _escape_ns($self->{ns}->{$self->{context}}->{$_}); |
150
|
0
|
0
|
|
|
|
|
if ($name =~ s/^<$ns([a-zA-Z]\w*)>$/$_:$1/) { |
151
|
0
|
|
|
|
|
|
$qnamed = 1; |
152
|
0
|
|
|
|
|
|
$p = $_; |
153
|
0
|
|
|
|
|
|
last; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
# checking out hard-coded NS |
157
|
0
|
0
|
|
|
|
|
unless ($qnamed) { |
158
|
0
|
|
|
|
|
|
foreach (keys %{$self->{hardns}}) { |
|
0
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
my $ns = _escape_ns($self->{hardns}->{$_}->[1]); |
160
|
0
|
0
|
|
|
|
|
if ($name =~ s/^<$ns([a-zA-Z]\w*)>$/$self->{hardns}->{$_}->[0]:$1/) { |
161
|
0
|
|
|
|
|
|
$p = $self->{hardns}->{$_}->[0]; |
162
|
0
|
|
|
|
|
|
$self->{ns}->{$self->{context}}->{$p} = |
163
|
|
|
|
|
|
|
$self->{hardns}->{$_}->[1]; |
164
|
0
|
|
|
|
|
|
$qnamed = 1; |
165
|
0
|
|
|
|
|
|
$p = $self->{hardns}->{$_}->[0]; |
166
|
0
|
|
|
|
|
|
last; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
# inventing new NS |
171
|
0
|
0
|
|
|
|
|
unless ($qnamed) { |
172
|
0
|
|
|
|
|
|
my $i = 1; |
173
|
0
|
|
|
|
|
|
my $pref = 'pref'; |
174
|
0
|
|
|
|
|
|
while ($self->{ns}->{$self->{context}}->{$pref}) { |
175
|
0
|
|
|
|
|
|
$pref = "$pref$i"; |
176
|
0
|
|
|
|
|
|
$i++; |
177
|
|
|
|
|
|
|
} |
178
|
0
|
0
|
|
|
|
|
if ($name =~ s/^<(.*?)([a-zA-Z]\w*)>$/$pref:$2/) { |
179
|
0
|
|
|
|
|
|
push @attr, ["xmlns:$pref" => $1]; |
180
|
0
|
|
|
|
|
|
$qnamed = 1; |
181
|
0
|
|
|
|
|
|
$pushed = 1; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
} |
184
|
0
|
0
|
|
|
|
|
$self->_do_error(401, $name) unless $qnamed; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
0
|
0
|
|
|
|
|
unless ($pushed) { |
188
|
0
|
0
|
|
|
|
|
if ($p) { |
189
|
0
|
|
|
|
|
|
push @attr, ["xmlns:$p" => $self->{ns}->{$self->{context}}->{$p}]; |
190
|
0
|
0
|
|
|
|
|
$self->_do_error(106, $name) |
191
|
|
|
|
|
|
|
unless $self->{ns}->{$self->{context}}->{$p}; |
192
|
|
|
|
|
|
|
} else { |
193
|
0
|
|
|
|
|
|
push @attr, ["xmlns" => $self->{ns}->{$self->{context}}->{''}]; |
194
|
0
|
0
|
|
|
|
|
$self->_do_error(106, $name) |
195
|
|
|
|
|
|
|
unless $self->{ns}->{$self->{context}}->{''}; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
return (\@attr, $name); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub _escape_ns { |
204
|
0
|
|
|
0
|
|
|
my $ns = shift; |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
$ns =~ s/\+/\\+/; |
207
|
0
|
|
|
|
|
|
$ns =~ s/\*/\\*/; |
208
|
0
|
|
|
|
|
|
$ns =~ s/\?/\\?/; |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
return $ns; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
1; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
__END__ |