| 1 | package SemanticWeb::OAI::ORE::TriX; | ||||||||||||||||||||||||||||
| 2 | #$Id: TriX.pm,v 1.13 2010-12-06 14:44:15 simeon Exp $ | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | SemanticWeb::OAI::ORE::TriX - Parse/serialize OAI-ORE Resource Maps in TriX format | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 SYNPOSIS | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Module to parse and serialize OAI-ORE ReMs in TriX format. | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | The TriX format is describe at L<http://www.w3.org/2004/03/trix/> | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use SemanticWeb::OAI::ORE::ReM; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use XML::Writer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 METHODS | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head2 Creator | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head3 new(%args) | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 0 | my $class=shift; | |||||||||||||||||||||||||||
| 35 | 0 | my $self={@_}; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | bless $self, (ref($class) || $class); | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 37 | 0 | return($self); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head2 Output | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head3 serialize() | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Seialize in TriX format, returns serializetion as a string. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub serialize { | ||||||||||||||||||||||||||
|
Subroutine
serialize: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 0 | my $self=shift; | |||||||||||||||||||||||||||
| 50 | 0 | my $out=''; | |||||||||||||||||||||||||||
| 51 | 0 | my $rem=$self->{rem}; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (ref($rem) and $rem->isa('SemanticWeb::OAI::ORE::ReM')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $rem and $rem->isa("SemanticWeb::OAI::ORE::ReM")
MC/DC0%0/2
ref $rem and $rem->isa("SemanticWeb::OAI::ORE::ReM")
ref $rem
$rem->isa("SemanticWeb::OAI::ORE::ReM")
Truth table0%0/3
A and B
A= ref $remB= $rem->isa("SemanticWeb::OAI::ORE::ReM")
| |||||||||||||||||||||||||||||
| 53 | # Get the info from the ReM | ||||||||||||||||||||||||||||
| 54 | 0 | my $name=$rem->name(); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # create an XML writer | ||||||||||||||||||||||||||||
| 57 | 0 | my $writer=XML::Writer->new('OUTPUT'=>\$out,'DATA_MODE'=>1,'DATA_INDENT'=>1); | |||||||||||||||||||||||||||
| 58 | 0 | $writer->startTag('trix', | |||||||||||||||||||||||||||
| 59 | 'xmlns'=>'http://www.w3.org/2004/03/trix/trix-1/', | ||||||||||||||||||||||||||||
| 60 | 'xmlns:ore'=>'http://www.openarchives.org/ORE'); | ||||||||||||||||||||||||||||
| 61 | # http://www.w3.org/2004/03/trix/trix-1/trix-1.0.xsd | ||||||||||||||||||||||||||||
| 62 | 0 | $writer->startTag('graph'); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # write name | ||||||||||||||||||||||||||||
| 65 | 0 | $writer->dataElement('uri',$name); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # write metadata | ||||||||||||||||||||||||||||
| 68 | 0 | $writer->comment('required metadata'); | |||||||||||||||||||||||||||
| 69 | 0 | write_triple($writer,$name,'ore:remTimeStamp',$rem->timestamp_as_iso8601()); | |||||||||||||||||||||||||||
| 70 | 0 | write_triple($writer,$name,'ore:remAuthority',$rem->authority()); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # write aggregated resources | ||||||||||||||||||||||||||||
| 73 | 0 | $writer->comment('aggregated resources'); | |||||||||||||||||||||||||||
| 74 | 0 | foreach my $uri ($rem->aggregated_resources()) { | |||||||||||||||||||||||||||
| 75 | 0 | write_triple($writer,$name,'ore:aggregates',$uri); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # write relations | ||||||||||||||||||||||||||||
| 79 | 0 | $writer->comment('rels'); | |||||||||||||||||||||||||||
| 80 | 0 | foreach my $rel (@{$rem->rels->as_array()}) { | |||||||||||||||||||||||||||
| 81 | 0 | write_triple($writer,@$rel); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | $writer->endTag('graph'); | |||||||||||||||||||||||||||
| 85 | 0 | $writer->endTag('trix'); | |||||||||||||||||||||||||||
| 86 | 0 | $writer->end(); | |||||||||||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||||||||||
| 88 | 0 | carp "Can't serialize something that isn't a rem: $rem, ".ref($rem)."\n"; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | return($out); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head2 SUBROUTINES | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head3 write_triple($writer,$subject,$predicate,$object) | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Write the ($subject,$predicate,$object) to $writer. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =cut | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub write_triple { | ||||||||||||||||||||||||||
|
Subroutine
write_triple: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 0 | my ($writer,$subject,$predicate,$object)=@_; | |||||||||||||||||||||||||||
| 103 | 0 | $writer->startTag('triple'); | |||||||||||||||||||||||||||
| 104 | # Subject and object may be id, uri, plainLiteral or typedLiteral | ||||||||||||||||||||||||||||
| 105 | 0 | $writer->dataElement('uri',$subject); | |||||||||||||||||||||||||||
| 106 | 0 | $writer->dataElement('uri',$predicate); | |||||||||||||||||||||||||||
| 107 | 0 | $writer->dataElement('uri',$object); | |||||||||||||||||||||||||||
| 108 | 0 | $writer->endTag('triple'); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | L<SemanticWeb::OAI::ORE::ReM> | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | Simeon Warner | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | Copyright 2007-2010 Simeon Warner. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | This module is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 124 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 2 | 1; | |||||||||||||||||||||||||||