5 |
## unexpected entity reference are simply ignored. (In fact |
## unexpected entity reference are simply ignored. (In fact |
6 |
## all EntityRefernce nodes are ignored.) |
## all EntityRefernce nodes are ignored.) |
7 |
|
|
8 |
|
## TODO: Add a callback function invoked for every element |
9 |
|
## when XMLCC is implemented in WDCC. |
10 |
|
|
11 |
|
## ISSUE: <html:nest/> in RDF subtree? |
12 |
|
|
13 |
|
## ISSUE: PIs in RDF subtree should be validated? |
14 |
|
|
15 |
my $RDF_URI = q<http://www.w3.org/1999/02/22-rdf-syntax-ns#>; |
my $RDF_URI = q<http://www.w3.org/1999/02/22-rdf-syntax-ns#>; |
16 |
|
|
17 |
sub new ($) { |
sub new ($) { |
182 |
$check_rdf_namespace->($self, $attr); |
$check_rdf_namespace->($self, $attr); |
183 |
|
|
184 |
my $attr_xuri = $attr->manakai_expanded_uri; |
my $attr_xuri = $attr->manakai_expanded_uri; |
185 |
if ($attr_xuri eq $RDF_URI . 'id') { |
if ($attr_xuri eq $RDF_URI . 'ID') { |
186 |
unless (defined $subject) { |
unless (defined $subject) { |
187 |
$subject = {uri => '#' . $attr->value}; ## TODO: resolve() |
$subject = {uri => '#' . $attr->value}; ## TODO: resolve() |
188 |
} else { |
} else { |
225 |
if ($xuri ne $RDF_URI . 'Description') { |
if ($xuri ne $RDF_URI . 'Description') { |
226 |
$self->{ontriple}->(subject => $subject, |
$self->{ontriple}->(subject => $subject, |
227 |
predicate => {uri => $RDF_URI . 'type'}, |
predicate => {uri => $RDF_URI . 'type'}, |
228 |
object => {uri => $xuri}); |
object => {uri => $xuri}, |
229 |
|
node => $node); |
230 |
} |
} |
231 |
|
|
232 |
if ($rdf_type_attr) { |
if ($rdf_type_attr) { |
233 |
$self->{ontriple}->(subject => $subject, |
$self->{ontriple}->(subject => $subject, |
234 |
predicate => {uri => $RDF_URI . 'type'}, |
predicate => {uri => $RDF_URI . 'type'}, |
235 |
object => {uri => $rdf_type_attr->value}); ## TODO: resolve |
object => {uri => $rdf_type_attr->value}, ## TODO: resolve |
236 |
|
node => $rdf_type_attr); |
237 |
} |
} |
238 |
|
|
239 |
for my $attr (@prop_attr) { |
for my $attr (@prop_attr) { |
240 |
$self->{ontriple}->(subject => $subject, |
$self->{ontriple}->(subject => $subject, |
241 |
predicate => {uri => $attr->manakai_expanded_uri}, |
predicate => {uri => $attr->manakai_expanded_uri}, |
242 |
object => {value => $attr->value}); ## TODO: language |
object => {value => $attr->value}, ## TODO: language |
243 |
|
node => $attr); |
244 |
## TODO: SHOULD in NFC |
## TODO: SHOULD in NFC |
245 |
} |
} |
246 |
|
|
335 |
# |parseTypeResourcePropertyElt| |
# |parseTypeResourcePropertyElt| |
336 |
|
|
337 |
for my $attr ($resource_attr, $nodeid_attr, $dt_attr) { |
for my $attr ($resource_attr, $nodeid_attr, $dt_attr) { |
338 |
|
next unless $attr; |
339 |
$self->{onerror}->(type => 'attribute not allowed', |
$self->{onerror}->(type => 'attribute not allowed', |
340 |
level => $self->{grammer_level}, |
level => $self->{grammer_level}, |
341 |
node => $attr); |
node => $attr); |
345 |
my $object = {bnodeid => '## TODO: generate bnodeid'}; |
my $object = {bnodeid => '## TODO: generate bnodeid'}; |
346 |
$self->{ontriple}->(subject => $opt{subject}, |
$self->{ontriple}->(subject => $opt{subject}, |
347 |
predicate => {uri => $xuri}, |
predicate => {uri => $xuri}, |
348 |
object => $object); |
object => $object, |
349 |
|
node => $node); |
350 |
## TODO: reification |
## TODO: reification |
351 |
|
|
352 |
## As if nodeElement |
## As if nodeElement |
372 |
# |parseTypeCollectionPropertyElt| |
# |parseTypeCollectionPropertyElt| |
373 |
|
|
374 |
for my $attr ($resource_attr, $nodeid_attr, $dt_attr) { |
for my $attr ($resource_attr, $nodeid_attr, $dt_attr) { |
375 |
|
next unless $attr; |
376 |
$self->{onerror}->(type => 'attribute not allowed', |
$self->{onerror}->(type => 'attribute not allowed', |
377 |
level => $self->{grammer_level}, |
level => $self->{grammer_level}, |
378 |
node => $attr); |
node => $attr); |
384 |
for my $cn (@{$node->child_nodes}) { |
for my $cn (@{$node->child_nodes}) { |
385 |
if ($cn->node_type == $cn->ELEMENT_NODE) { |
if ($cn->node_type == $cn->ELEMENT_NODE) { |
386 |
push @resource, [$self->convert_node_element ($cn), |
push @resource, [$self->convert_node_element ($cn), |
387 |
{bnodeid => '## TODO: bnodeid generated'}]; |
{bnodeid => '## TODO: bnodeid generated'}, |
388 |
|
$cn]; |
389 |
} elsif ($cn->node_type == $cn->TEXT_NODE or |
} elsif ($cn->node_type == $cn->TEXT_NODE or |
390 |
$cn->node_type == $cn->CDATA_SECTION_NODE) { |
$cn->node_type == $cn->CDATA_SECTION_NODE) { |
391 |
if ($cn->data =~ /[^\x09\x0A\x0D\x20]/) { |
if ($cn->data =~ /[^\x09\x0A\x0D\x20]/) { |
399 |
if (@resource) { |
if (@resource) { |
400 |
$self->{ontriple}->(subject => $opt{subject}, |
$self->{ontriple}->(subject => $opt{subject}, |
401 |
predicate => {uri => $xuri}, |
predicate => {uri => $xuri}, |
402 |
object => $resource[0]->[1]); |
object => $resource[0]->[1], |
403 |
|
node => $node); |
404 |
} else { |
} else { |
405 |
$self->{ontriple}->(subject => $opt{subject}, |
$self->{ontriple}->(subject => $opt{subject}, |
406 |
predicate => {uri => $xuri}, |
predicate => {uri => $xuri}, |
407 |
object => {uri => $RDF_URI . 'nil'}); |
object => {uri => $RDF_URI . 'nil'}, |
408 |
|
node => $node); |
409 |
} |
} |
410 |
## TODO: reification |
## TODO: reification |
411 |
|
|
413 |
my $resource = shift @resource; |
my $resource = shift @resource; |
414 |
$self->{ontriple}->(subject => $resource->[1], |
$self->{ontriple}->(subject => $resource->[1], |
415 |
predicate => {uri => $RDF_URI . 'first'}, |
predicate => {uri => $RDF_URI . 'first'}, |
416 |
object => $resource->[0]); |
object => $resource->[0], |
417 |
|
node => $resource->[2]); |
418 |
if (@resource) { |
if (@resource) { |
419 |
$self->{ontriple}->(subject => $resource->[1], |
$self->{ontriple}->(subject => $resource->[1], |
420 |
predicate => {uri => $RDF_URI . 'rest'}, |
predicate => {uri => $RDF_URI . 'rest'}, |
421 |
object => $resource[0]->[1]); |
object => $resource[0]->[1], |
422 |
|
node => $resource->[2]); |
423 |
} else { |
} else { |
424 |
$self->{ontriple}->(subject => $resource->[1], |
$self->{ontriple}->(subject => $resource->[1], |
425 |
predicate => {uri => $RDF_URI . 'rest'}, |
predicate => {uri => $RDF_URI . 'rest'}, |
426 |
object => {uri => $RDF_URI . 'nil'}); |
object => {uri => $RDF_URI . 'nil'}, |
427 |
|
node => $resource->[2]); |
428 |
} |
} |
429 |
} |
} |
430 |
} elsif ($parse_attr) { |
} elsif ($parse_attr) { |
432 |
# |parseTypeOtherPropertyElt| ## TODO: What RDF Validator does? |
# |parseTypeOtherPropertyElt| ## TODO: What RDF Validator does? |
433 |
|
|
434 |
for my $attr ($resource_attr, $nodeid_attr, $dt_attr) { |
for my $attr ($resource_attr, $nodeid_attr, $dt_attr) { |
435 |
|
next unless $attr; |
436 |
$self->{onerror}->(type => 'attribute not allowed', |
$self->{onerror}->(type => 'attribute not allowed', |
437 |
level => $self->{grammer_level}, |
level => $self->{grammer_level}, |
438 |
node => $attr); |
node => $attr); |
446 |
$self->{ontriple}->(subject => $opt{subject}, |
$self->{ontriple}->(subject => $opt{subject}, |
447 |
predicate => {uri => $xuri}, |
predicate => {uri => $xuri}, |
448 |
object => {nodes => $value, |
object => {nodes => $value, |
449 |
datatype => $RDF_URI . 'XMLLiteral'}); |
datatype => $RDF_URI . 'XMLLiteral'}, |
450 |
|
node => $node); |
451 |
## TODO: reification |
## TODO: reification |
452 |
} else { |
} else { |
453 |
my $mode = 'unknown'; |
my $mode = 'unknown'; |
510 |
# |resourcePropertyElt| |
# |resourcePropertyElt| |
511 |
|
|
512 |
for my $attr (@prop_attr, $resource_attr, $nodeid_attr, $dt_attr) { |
for my $attr (@prop_attr, $resource_attr, $nodeid_attr, $dt_attr) { |
513 |
|
next unless $attr; |
514 |
$self->{onerror}->(type => 'attribute not allowed', |
$self->{onerror}->(type => 'attribute not allowed', |
515 |
level => $self->{grammer_level}, |
level => $self->{grammer_level}, |
516 |
node => $attr); |
node => $attr); |
521 |
|
|
522 |
$self->{ontriple}->(subject => $opt{subject}, |
$self->{ontriple}->(subject => $opt{subject}, |
523 |
predicate => {uri => $xuri}, |
predicate => {uri => $xuri}, |
524 |
object => $object); |
object => $object, |
525 |
|
node => $node); |
526 |
|
|
527 |
## TODO: reification |
## TODO: reification |
528 |
} elsif ($mode eq 'literal' or $mode eq 'literal-or-resource') { |
} elsif ($mode eq 'literal' or $mode eq 'literal-or-resource') { |
529 |
# |literalPropertyElt| |
# |literalPropertyElt| |
530 |
|
|
531 |
for my $attr (@prop_attr, $resource_attr, $nodeid_attr) { |
for my $attr (@prop_attr, $resource_attr, $nodeid_attr) { |
532 |
|
next unless $attr; |
533 |
$self->{onerror}->(type => 'attribute not allowed', |
$self->{onerror}->(type => 'attribute not allowed', |
534 |
level => $self->{grammer_level}, |
level => $self->{grammer_level}, |
535 |
node => $attr); |
node => $attr); |
542 |
$self->{ontriple}->(subject => $opt{subject}, |
$self->{ontriple}->(subject => $opt{subject}, |
543 |
predicate => {uri => $xuri}, |
predicate => {uri => $xuri}, |
544 |
object => {value => $text, |
object => {value => $text, |
545 |
datatype => $dt_attr->value}); |
datatype => $dt_attr->value}, |
546 |
|
node => $node); |
547 |
} else { |
} else { |
548 |
$self->{ontriple}->(subject => $opt{subject}, |
$self->{ontriple}->(subject => $opt{subject}, |
549 |
predicate => {uri => $xuri}, |
predicate => {uri => $xuri}, |
550 |
object => {value => $text, |
object => {value => $text, |
551 |
## TODO: language |
## TODO: language |
552 |
}); |
}, |
553 |
|
node => $node); |
554 |
} |
} |
555 |
|
|
556 |
## TODO: reification |
## TODO: reification |
558 |
## |emptyPropertyElt| |
## |emptyPropertyElt| |
559 |
|
|
560 |
for my $attr ($dt_attr) { |
for my $attr ($dt_attr) { |
561 |
|
next unless $attr; |
562 |
$self->{onerror}->(type => 'attribute not allowed', |
$self->{onerror}->(type => 'attribute not allowed', |
563 |
level => $self->{grammer_level}, |
level => $self->{grammer_level}, |
564 |
node => $attr); |
node => $attr); |
570 |
predicate => {uri => $xuri}, |
predicate => {uri => $xuri}, |
571 |
object => {value => '', |
object => {value => '', |
572 |
## TODO: language |
## TODO: language |
573 |
}); |
}, |
574 |
|
node => $node); |
575 |
|
|
576 |
## TODO: reification |
## TODO: reification |
577 |
} else { |
} else { |
589 |
if ($attr_xuri eq $RDF_URI . 'type') { |
if ($attr_xuri eq $RDF_URI . 'type') { |
590 |
$self->{ontriple}->(subject => $object, |
$self->{ontriple}->(subject => $object, |
591 |
predicate => {uri => $attr_xuri}, |
predicate => {uri => $attr_xuri}, |
592 |
object => $attr->value); ## TODO: resolve |
object => $attr->value, ## TODO: resolve |
593 |
|
node => $attr); |
594 |
} else { |
} else { |
595 |
## TODO: SHOULD be in NFC |
## TODO: SHOULD be in NFC |
596 |
$self->{ontriple}->(subject => $object, |
$self->{ontriple}->(subject => $object, |
597 |
predicate => {uri => $attr_xuri}, |
predicate => {uri => $attr_xuri}, |
598 |
object => {value => $attr->value, |
object => {value => $attr->value, |
599 |
## TODO: lang |
## TODO: lang |
600 |
}); |
}, |
601 |
|
node => $attr); |
602 |
} |
} |
603 |
} |
} |
604 |
|
|
605 |
$self->{ontriple}->(subject => $opt{subject}, |
$self->{ontriple}->(subject => $opt{subject}, |
606 |
predicate => {uri => $xuri}, |
predicate => {uri => $xuri}, |
607 |
object => $object); |
object => $object, |
608 |
|
node => $node); |
609 |
|
|
610 |
## TODO: reification |
## TODO: reification |
611 |
} |
} |