| 1 | package OpenGuides::RDF::Reader; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 2 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Exporter (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | $VERSION = '0.05'; | |||||||||
| 8 | 2 | @ISA = qw(Exporter); | |||||||||
| 9 | 2 | @EXPORT = qw(parse_rdf); | |||||||||
| 10 | 2 | @EXPORT_OK = qw(parse_rdf); | |||||||||
| 11 | 2 | %EXPORT_TAGS = (all => [qw(parse_rdf)]); | |||||||||
| 12 | } | ||||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | use XML::Simple; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | sub parse_rdf { | ||||||||
|
Subroutine
parse_rdf: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 17 | 2 | my $xml = shift; | |||||||||
| 18 | |||||||||||
| 19 | 2 | my $rdf = XMLin( $xml, | |||||||||
| 20 | ForceArray => [qw/foaf:based_near dc:subject/ ], | ||||||||||
| 21 | GroupTags => {'dc:source' => 'rdf:resource', | ||||||||||
| 22 | 'foaf:homepage' => 'rdf:resource' }, | ||||||||||
| 23 | #NumericEscape => 2, | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | 2 | my $geo; | |||||||||
| 27 | 2 | my $desc = $rdf->{'rdf:Description'}; | |||||||||
| 28 | 2 | ▶ | if (ref $desc eq 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 1 | $geo = $desc->[1]; | |||||||||
| 30 | 1 | $desc = $desc->[0]; | |||||||||
| 31 | } | ||||||||||
| 32 | else { | ||||||||||
| 33 | 1 | $geo = $rdf->{'geo:SpatialThing'}; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 2 | my %descmap = ( | |||||||||
| 37 | username => 'dc:contributor', | ||||||||||
| 38 | changed => 'dc:date', | ||||||||||
| 39 | version => 'wiki:version', | ||||||||||
| 40 | source => 'dc:source', | ||||||||||
| 41 | ); | ||||||||||
| 42 | 2 | my %geomap = ( | |||||||||
| 43 | country => 'country', | ||||||||||
| 44 | city => 'city', | ||||||||||
| 45 | address => 'address', | ||||||||||
| 46 | postcode => 'postalCode', | ||||||||||
| 47 | phone => 'phone', | ||||||||||
| 48 | fax => 'fax', | ||||||||||
| 49 | website => 'foaf:homepage', | ||||||||||
| 50 | opening_hours_text => 'chefmoz:Hours', | ||||||||||
| 51 | longitude => 'geo:long', | ||||||||||
| 52 | latitude => 'geo:lat', | ||||||||||
| 53 | category => 'dc:subject', | ||||||||||
| 54 | summary => 'dc:description', | ||||||||||
| 55 | ); | ||||||||||
| 56 | 2 | my %out; | |||||||||
| 57 | 2 | $out{$_} = $desc->{$descmap{$_}} for keys %descmap; | |||||||||
| 58 | 2 | $out{$_} = $geo->{$geomap{$_}} for keys %geomap; | |||||||||
| 59 | 1 | $out{locale} = [ map {$_->{'wn:Neighborhood'}{'foaf:name'}} | |||||||||
| 60 | 2 | ▶ | @{$geo->{'foaf:based_near'}} ] if exists $geo->{'foaf:based_near'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 2 | %out; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | =head1 NAME | ||||||||||
| 66 | |||||||||||
| 67 | OpenGuides::RDF::Reader - Parse and return OpenGuides metadata from RDF | ||||||||||
| 68 | |||||||||||
| 69 | =head1 SYNOPSIS | ||||||||||
| 70 | |||||||||||
| 71 | use OpenGuides::RDF::Reader; | ||||||||||
| 72 | use WWW::Mechanize; | ||||||||||
| 73 | ... | ||||||||||
| 74 | my $agent = WWW::Mechanize->new; | ||||||||||
| 75 | $agent->get("http://fooville.openguides.org/?id=Red_Lion;format=rdf"); | ||||||||||
| 76 | my %metadata = parse_rdf($agent->content); | ||||||||||
| 77 | |||||||||||
| 78 | |||||||||||
| 79 | =head1 DESCRIPTION | ||||||||||
| 80 | |||||||||||
| 81 | The L<OpenGuides> software deliberately exposes data collected on the town wiki | ||||||||||
| 82 | sites, making it available to other websites as RDF / XML. This functionality is | ||||||||||
| 83 | provided by the module L<OpenGuides::RDF> supplied in the OpenGuides distribution. | ||||||||||
| 84 | |||||||||||
| 85 | What OpenGuides::RDF::Reader does is the reverse process, i.e. take XML RDF data | ||||||||||
| 86 | and turn it back into a hash with keys comprising the metadata fields in OpenGuides. | ||||||||||
| 87 | The main use of this is for guide replication. | ||||||||||
| 88 | |||||||||||
| 89 | =head2 parse_rdf | ||||||||||
| 90 | |||||||||||
| 91 | This exported subroutine takes a string containing RDF and returns a list of | ||||||||||
| 92 | metadata key value pairs. | ||||||||||
| 93 | |||||||||||
| 94 | =head1 BUGS | ||||||||||
| 95 | |||||||||||
| 96 | Please report any bugs in this module using http://rt.cpan.org/ or posting to | ||||||||||
| 97 | bugs-openguides-rdf-reader (at) rt.cpan.org. | ||||||||||
| 98 | |||||||||||
| 99 | =head1 SUPPORT | ||||||||||
| 100 | |||||||||||
| 101 | For discussion of all matters relating to OpenGuides, there is a mailing list | ||||||||||
| 102 | http://openguides.org/mm/listinfo/openguides-dev. | ||||||||||
| 103 | |||||||||||
| 104 | =head1 AUTHOR | ||||||||||
| 105 | |||||||||||
| 106 | Ivor Williams | ||||||||||
| 107 | CPAN ID: IVORW | ||||||||||
| 108 | |||||||||||
| 109 | ivorw-openguides (at) xemaps.com | ||||||||||
| 110 | http://openguides.org/ | ||||||||||
| 111 | |||||||||||
| 112 | =head1 COPYRIGHT | ||||||||||
| 113 | |||||||||||
| 114 | This program is free software licensed under the... | ||||||||||
| 115 | |||||||||||
| 116 | The General Public License (GPL) | ||||||||||
| 117 | Version 2, June 1991 | ||||||||||
| 118 | |||||||||||
| 119 | The full text of the license can be found in the | ||||||||||
| 120 | LICENSE file included with this module. | ||||||||||
| 121 | |||||||||||
| 122 | |||||||||||
| 123 | =head1 SEE ALSO | ||||||||||
| 124 | |||||||||||
| 125 | L<OpenGuides>. | ||||||||||
| 126 | |||||||||||
| 127 | =cut | ||||||||||
| 128 | |||||||||||
| 129 | |||||||||||
| 130 | 2 | 1; | |||||||||
| 131 | # The preceding line will help the module return a true value | ||||||||||
| 132 | |||||||||||