33 |
'output-local-resource!' => \$Opt{output_local_resource}, |
'output-local-resource!' => \$Opt{output_local_resource}, |
34 |
'output-module!' => \$Opt{output_module}, |
'output-module!' => \$Opt{output_module}, |
35 |
'output-only-in-module=s' => \$Opt{output_resource_pattern}, |
'output-only-in-module=s' => \$Opt{output_resource_pattern}, |
36 |
'output-prop-perl!' => \$Opt{output_prop_perl}, |
'output-perl!' => \$Opt{output_prop_perl}, |
37 |
|
'output-perl-member-pattern=s' => \$Opt{output_perl_member_pattern}, |
38 |
'output-resource!' => \$Opt{output_resource}, |
'output-resource!' => \$Opt{output_resource}, |
39 |
'output-resource-uri-pattern=s' => \$Opt{output_resource_uri_pattern}, |
'output-resource-uri-pattern=s' => \$Opt{output_resource_uri_pattern}, |
40 |
|
'output-root-anon-resource!' => $Opt{output_root_anon_resource}, |
41 |
) or pod2usage (2); |
) or pod2usage (2); |
42 |
if ($Opt{help}) { |
if ($Opt{help}) { |
43 |
pod2usage (0); |
pod2usage (0); |
47 |
pod2usage (2); |
pod2usage (2); |
48 |
exit; |
exit; |
49 |
} |
} |
50 |
|
$Opt{file_name} = shift; |
51 |
|
$Opt{output_resource_pattern} ||= qr/./; |
52 |
|
$Opt{output_resource_uri_pattern} ||= qr/./; |
53 |
|
$Opt{output_root_anon_resource} = $Opt{output_anon_resource} |
54 |
|
unless defined $Opt{output_anon_resource}; |
55 |
$Opt{output_as_xml} = 1 unless $Opt{output_as_n3}; |
$Opt{output_as_xml} = 1 unless $Opt{output_as_n3}; |
56 |
$Opt{output_anon_resource} = 1 unless defined $Opt{output_anon_resource}; |
$Opt{output_anon_resource} = 1 unless defined $Opt{output_anon_resource}; |
57 |
$Opt{output_local_resource} = 1 unless defined $Opt{output_local_resource}; |
$Opt{output_local_resource} = 1 unless defined $Opt{output_local_resource}; |
58 |
$Opt{no_undef_check} = $Opt{no_undef_check} ? 0 : 1; |
$Opt{no_undef_check} = $Opt{no_undef_check} ? 0 : 1; |
59 |
|
$Opt{output_perl_member_pattern} ||= qr/./; |
60 |
|
|
61 |
BEGIN { |
BEGIN { |
62 |
require 'manakai/genlib.pl'; |
require 'manakai/genlib.pl'; |
70 |
our $State; |
our $State; |
71 |
our $result = new manakai::n3; |
our $result = new manakai::n3; |
72 |
|
|
|
$Opt{file_name} = shift; |
|
|
$Opt{output_resource_pattern} ||= qr/.+/; |
|
|
$Opt{output_resource_uri_pattern} ||= qr/.+/; |
|
73 |
|
|
74 |
$State->{DefaultFor} = $Opt{For}; |
$State->{DefaultFor} = $Opt{For}; |
75 |
|
|
88 |
my $primary = $result->get_new_anon_id (Name => 'boot'); |
my $primary = $result->get_new_anon_id (Name => 'boot'); |
89 |
$result->add_triple ($primary =>ExpandedURI q<d:module>=> $State->{module}) |
$result->add_triple ($primary =>ExpandedURI q<d:module>=> $State->{module}) |
90 |
if $Opt{output_module}; |
if $Opt{output_module}; |
91 |
$result->add_triple ($primary =>ExpandedURI q<d:DefaultFor> => $State->{DefaultFor}) |
$result->add_triple |
92 |
|
($primary =>ExpandedURI q<d:DefaultFor> => $State->{DefaultFor}) |
93 |
if $Opt{output_for}; |
if $Opt{output_for}; |
94 |
|
|
95 |
if ($Opt{output_module}) { |
if ($Opt{output_module}) { |
165 |
my ($mod, %opt) = @_; |
my ($mod, %opt) = @_; |
166 |
return unless defined $mod->{Name}; |
return unless defined $mod->{Name}; |
167 |
return unless $mod->{parentModule} =~ /$Opt{output_resource_pattern}/; |
return unless $mod->{parentModule} =~ /$Opt{output_resource_pattern}/; |
168 |
|
return if $Opt{output_prop_perl} and |
169 |
|
$mod->{ExpandedURI q<dis2pm:type>} and |
170 |
|
{ |
171 |
|
ExpandedURI q<ManakaiDOM:DOMAttribute> => 1, |
172 |
|
ExpandedURI q<ManakaiDOM:DOMMethod> => 1, |
173 |
|
}->{$mod->{ExpandedURI q<dis2pm:type>}} and |
174 |
|
$mod->{Name} and |
175 |
|
$mod->{Name} !~ /$Opt{output_perl_member_pattern}/; |
176 |
if ((defined $mod->{URI} and $opt{key} eq $mod->{URI}) or |
if ((defined $mod->{URI} and $opt{key} eq $mod->{URI}) or |
177 |
not defined $mod->{URI}) { |
not defined $mod->{URI}) { |
178 |
return if defined $mod->{URI} and |
return if defined $mod->{URI} and |
189 |
$result->add_triple ($uri =>ExpandedURI q<d:parentResource>=> |
$result->add_triple ($uri =>ExpandedURI q<d:parentResource>=> |
190 |
$opt{parent_class_uri}) |
$opt{parent_class_uri}) |
191 |
if defined $opt{parent_class_uri}; |
if defined $opt{parent_class_uri}; |
192 |
$result->add_triple ($uri =>ExpandedURI q<d:parentModule>=> |
if ($Opt{output_module}) { |
193 |
$mod->{parentModule}); |
$result->add_triple ($uri =>ExpandedURI q<d:parentModule>=> |
194 |
|
$mod->{parentModule}); |
195 |
|
} |
196 |
for (keys %{$mod->{Type}}) { |
for (keys %{$mod->{Type}}) { |
197 |
$result->add_triple ($uri =>ExpandedURI q<rdf:type>=> $_); |
$result->add_triple ($uri =>ExpandedURI q<rdf:type>=> $_); |
198 |
} |
} |
202 |
for (@{$mod->{Implement}}) { |
for (@{$mod->{Implement}}) { |
203 |
$result->add_triple ($uri =>ExpandedURI q<d:Implement>=> $_); |
$result->add_triple ($uri =>ExpandedURI q<d:Implement>=> $_); |
204 |
} |
} |
205 |
for (keys %{$mod->{For}}) { |
if ($Opt{output_for}) { |
206 |
$result->add_triple ($uri =>ExpandedURI q<d:For>=> $_); |
for (keys %{$mod->{For}}) { |
207 |
|
$result->add_triple ($uri =>ExpandedURI q<d:For>=> $_); |
208 |
|
} |
209 |
} |
} |
210 |
for (@{$mod->{hasResource}||[]}) { |
for (@{$mod->{hasResource}||[]}) { |
211 |
my $ruri = defined $_->{URI} |
my $ruri = defined $_->{URI} |
218 |
for my $prop ([ExpandedURI q<dis2pm:packageName>], |
for my $prop ([ExpandedURI q<dis2pm:packageName>], |
219 |
[ExpandedURI q<dis2pm:ifPackagePrefix>], |
[ExpandedURI q<dis2pm:ifPackagePrefix>], |
220 |
[ExpandedURI q<dis2pm:methodName>], |
[ExpandedURI q<dis2pm:methodName>], |
221 |
|
[ExpandedURI q<dis2pm:paramName>], |
222 |
[ExpandedURI q<ManakaiDOM:isRedefining>, |
[ExpandedURI q<ManakaiDOM:isRedefining>, |
223 |
ExpandedURI q<DOMMain:boolean>], |
ExpandedURI q<DOMMain:boolean>], |
224 |
[ExpandedURI q<ManakaiDOM:isForInternal>, |
[ExpandedURI q<ManakaiDOM:isForInternal>, |
225 |
|
ExpandedURI q<DOMMain:boolean>], |
226 |
|
[ExpandedURI q<d:Read>, ExpandedURI q<DOMMain:boolean>], |
227 |
|
[ExpandedURI q<d:Write>, |
228 |
ExpandedURI q<DOMMain:boolean>]) { |
ExpandedURI q<DOMMain:boolean>]) { |
229 |
$result->add_triple ($uri =>$prop->[0]=> |
$result->add_triple ($uri =>$prop->[0]=> |
230 |
n3_literal $mod->{$prop->[0]}) |
n3_literal $mod->{$prop->[0]}) |
231 |
if defined $mod->{$prop->[0]}; |
if defined $mod->{$prop->[0]}; |
232 |
} |
} |
233 |
|
for my $prop ([ExpandedURI q<d:Type>], |
234 |
|
[ExpandedURI q<dis2pm:if>]) { |
235 |
|
$result->add_triple ($uri =>$prop->[0]=> $mod->{$prop->[0]}) |
236 |
|
if defined $mod->{$prop->[0]}; |
237 |
|
} |
238 |
for (values %{$mod->{ExpandedURI q<dis2pm:method>}||{}}) { |
for (values %{$mod->{ExpandedURI q<dis2pm:method>}||{}}) { |
239 |
my $ruri = defined $_->{URI} |
my $ruri = defined $_->{URI} |
240 |
? $_->{URI} |
? $_->{URI} |
242 |
||= $result->get_new_anon_id (Name => $_->{Name})); |
||= $result->get_new_anon_id (Name => $_->{Name})); |
243 |
$result->add_triple ($uri =>ExpandedURI q<dis2pm:method>=> $ruri); |
$result->add_triple ($uri =>ExpandedURI q<dis2pm:method>=> $ruri); |
244 |
} |
} |
245 |
|
if ($mod->{ExpandedURI q<dis2pm:type>} eq |
246 |
|
ExpandedURI q<ManakaiDOM:DOMMethod>) { |
247 |
|
$result->add_triple |
248 |
|
($uri =>ExpandedURI q<dis2pm:param>=> |
249 |
|
my $p = $result->get_new_anon_id (Name => 'param')); |
250 |
|
$result->add_triple ($uri =>ExpandedURI q<rdf:type>=> |
251 |
|
ExpandedURI q<rdf:Seq>); |
252 |
|
my $i = 0; |
253 |
|
for (@{$mod->{ExpandedURI q<dis2pm:param>}||[]}) { |
254 |
|
my $ruri = defined $_->{URI} |
255 |
|
? $_->{URI} |
256 |
|
: ($_->{ExpandedURI q<d:anonID>} |
257 |
|
||= $result->get_new_anon_id (Name => $_->{Name})); |
258 |
|
$result->add_triple ($p =>(ExpandedURI q<rdf:_>).++$i=> $ruri); |
259 |
|
} |
260 |
|
} |
261 |
} |
} |
262 |
if ($Opt{output_local_resource}) { |
if ($Opt{output_local_resource}) { |
263 |
for (keys %{$mod->{Resource}}) { |
for (keys %{$mod->{Resource}}) { |
264 |
class_to_rdf ($mod->{Resource}->{$_}, parent_class => $mod, |
class_to_rdf ($mod->{Resource}->{$_}, %opt, parent_class => $mod, |
265 |
parent_class_uri => $uri, |
parent_class_uri => $uri, |
266 |
key => $_); |
key => $_); |
267 |
} |
} |
268 |
} |
} |
269 |
} else { ## Alias URI |
} else { ## Alias URI |
270 |
return if $opt{key} !~ /$Opt{output_resource_uri_pattern}/; |
return unless $opt{key} =~ /$Opt{output_resource_uri_pattern}/ or |
271 |
|
$mod->{URI} =~ /$Opt{output_resource_uri_pattern}/; |
272 |
$result->add_triple ($opt{key} =>ExpandedURI q<owl:sameAs>=> $mod->{URI}); |
$result->add_triple ($opt{key} =>ExpandedURI q<owl:sameAs>=> $mod->{URI}); |
273 |
} |
} |
274 |
} |
} |
275 |
for (sort keys %{$State->{Type}}) { |
for (sort keys %{$State->{Type}}) { |
276 |
|
next if not $Opt{output_root_anon_resource} and |
277 |
|
not defined $State->{Type}->{$_}->{URI}; |
278 |
class_to_rdf ($State->{Type}->{$_}, key => $_); |
class_to_rdf ($State->{Type}->{$_}, key => $_); |
279 |
} |
} |
280 |
} |
} |
317 |
my ($self) = @_; |
my ($self) = @_; |
318 |
use RDF::Notation3::XML; |
use RDF::Notation3::XML; |
319 |
my $notation3 = RDF::Notation3::XML->new; |
my $notation3 = RDF::Notation3::XML->new; |
320 |
$notation3->parse_string ($self->stringify); |
my $n3 = $self->stringify; |
321 |
|
my $rdf_ = ExpandedURI q<rdf:_>; |
322 |
|
$n3 =~ s/$rdf_/data:,dummy_/g; |
323 |
|
$notation3->parse_string ($n3); |
324 |
my $xml = $notation3->get_string; |
my $xml = $notation3->get_string; |
325 |
$xml =~ s/\brdf:nodeID="_:/rdf:nodeID="/g; |
$xml =~ s/\brdf:nodeID="_:/rdf:nodeID="/g; |
326 |
# $xml =~ s/^<\?xml version="1.0" encoding="utf-8"\?>\s*//; |
# $xml =~ s/^<\?xml version="1.0" encoding="utf-8"\?>\s*//; |