| 1 |
|
| #----------------------------------------------------------------- |
| 2 |
|
| # MOBY::RDF::Parsers::ServiceTypeParser |
| 3 |
|
| # Author: Edward Kawas <edward.kawas@gmail.com>, |
| 4 |
|
| # For copyright and disclaimer see below. |
| 5 |
|
| # |
| 6 |
|
| # $Id: ServiceTypeParser.pm,v 1.4 2008/11/25 18:05:44 kawas Exp $ |
| 7 |
|
| #----------------------------------------------------------------- |
| 8 |
|
| package MOBY::RDF::Parsers::ServiceTypeParser; |
| 9 |
|
| use strict; |
| 10 |
|
| |
| 11 |
|
| # imports |
| 12 |
|
| use RDF::Core::Model::Parser; |
| 13 |
|
| use RDF::Core::Model; |
| 14 |
|
| use RDF::Core::Storage::Memory; |
| 15 |
|
| use RDF::Core::Resource; |
| 16 |
|
| |
| 17 |
|
| use MOBY::RDF::Utils; |
| 18 |
|
| use MOBY::RDF::Predicates::DC_PROTEGE; |
| 19 |
|
| use MOBY::RDF::Predicates::MOBY_PREDICATES; |
| 20 |
|
| use MOBY::RDF::Predicates::OMG_LSID; |
| 21 |
|
| use MOBY::RDF::Predicates::RDF; |
| 22 |
|
| use MOBY::RDF::Predicates::RDFS; |
| 23 |
|
| |
| 24 |
|
| use vars qw /$VERSION/; |
| 25 |
|
| $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/; |
| 26 |
|
| |
| 27 |
|
| =head1 NAME |
| 28 |
|
| |
| 29 |
|
| ServiceTypeParser - An module for obtaining services from the RDF Service Type ontology |
| 30 |
|
| |
| 31 |
|
| =cut |
| 32 |
|
| |
| 33 |
|
| =head1 SYNOPSIS |
| 34 |
|
| |
| 35 |
|
| use MOBY::RDF::Parsers::ServiceTypeParser; |
| 36 |
|
| use Data::Dumper; |
| 37 |
|
| |
| 38 |
|
| # construct a parser for service types |
| 39 |
|
| my $parser = MOBY::RDF::Parsers::ServiceTypeParser->new(); |
| 40 |
|
| |
| 41 |
|
| # get all service types from a URL |
| 42 |
|
| my $services_href = $parser->getNamespaces('http://biomoby.org/RESOURCES/MOBY-S/Services'); |
| 43 |
|
| |
| 44 |
|
| # print out details regarding 'Analysis' |
| 45 |
|
| print Dumper($services_href->{'Analysis'}); |
| 46 |
|
| |
| 47 |
|
| =cut |
| 48 |
|
| |
| 49 |
|
| =head1 DESCRIPTION |
| 50 |
|
| |
| 51 |
|
| This module contains the methods required to download and parse Service Type RDF into individual service types |
| 52 |
|
| |
| 53 |
|
| =cut |
| 54 |
|
| |
| 55 |
|
| =head1 AUTHORS |
| 56 |
|
| |
| 57 |
|
| Edward Kawas (edward.kawas [at] gmail [dot] com) |
| 58 |
|
| |
| 59 |
|
| =cut |
| 60 |
|
| |
| 61 |
|
| #----------------------------------------------------------------- |
| 62 |
|
| |
| 63 |
|
| =head1 SUBROUTINES |
| 64 |
|
| |
| 65 |
|
| =cut |
| 66 |
|
| |
| 67 |
|
| =head2 new |
| 68 |
|
| |
| 69 |
|
| Contructs a new ServiceTypeParser. |
| 70 |
|
| |
| 71 |
|
| Input: none. |
| 72 |
|
| |
| 73 |
|
| Example: |
| 74 |
|
| |
| 75 |
|
| MOBY::RDF::Parsers::ServiceTypeParser->new() |
| 76 |
|
| |
| 77 |
|
| =cut |
| 78 |
|
| |
| 79 |
|
| sub new { |
| 80 |
|
| my ($class) = @_; |
| 81 |
|
| |
| 82 |
|
| # create an object |
| 83 |
|
| my $self = bless {}, ref($class) || $class; |
| 84 |
|
| |
| 85 |
|
| # done |
| 86 |
|
| return $self; |
| 87 |
|
| } |
| 88 |
|
| |
| 89 |
|
| =head2 getServiceTypes |
| 90 |
|
| |
| 91 |
|
| Downloads RDF from $url, parses it and returns a hashref of hash. |
| 92 |
|
| The key into the hashref is a service type name and the hash value |
| 93 |
|
| contains information on that service type. |
| 94 |
|
| The keys for the inner hash are: |
| 95 |
|
| |
| 96 |
|
| definintion |
| 97 |
|
| authURI |
| 98 |
|
| email |
| 99 |
|
| lsid |
| 100 |
|
| |
| 101 |
|
| Input: a scalar URL |
| 102 |
|
| |
| 103 |
|
| Example: |
| 104 |
|
| |
| 105 |
|
| my $parser = MOBY::RDF::Parsers::ServiceTypeParser->new(); |
| 106 |
|
| my $namespace_href = $parser->getServiceTypes('http://biomoby.org/RESOURCES/MOBY-S/Services'); |
| 107 |
|
| |
| 108 |
|
| =cut |
| 109 |
|
| |
| 110 |
|
| sub getServiceTypes { |
| 111 |
|
| |
| 112 |
|
| my ($self, $url) = @_; |
| 113 |
|
| my %hash; |
| 114 |
|
| return \%hash unless $url; |
| 115 |
|
| |
| 116 |
|
| # download string from url |
| 117 |
|
| my $rdf = undef; |
| 118 |
|
| |
| 119 |
|
| # 'try/catch' |
| 120 |
|
| eval { |
| 121 |
|
| $rdf = MOBY::RDF::Utils->new()->getHttpRequestByURL($url); |
| 122 |
|
| }; |
| 123 |
|
| return \%hash unless $rdf; |
| 124 |
|
| |
| 125 |
|
| |
| 126 |
|
| # create RDF model and populate |
| 127 |
|
| my $storage = new RDF::Core::Storage::Memory; |
| 128 |
|
| my $model = new RDF::Core::Model (Storage => $storage); |
| 129 |
|
| my %options = (Model => $model, |
| 130 |
|
| Source => $rdf, |
| 131 |
|
| SourceType => 'string', |
| 132 |
|
| BaseURI => "$url", |
| 133 |
|
| ); |
| 134 |
|
| my $parser = new RDF::Core::Model::Parser(%options); |
| 135 |
|
| $parser->parse; |
| 136 |
|
| |
| 137 |
|
| # get information from the model |
| 138 |
|
| my $enumerator = $model->getStmts(undef, new RDF::Core::Resource( MOBY::RDF::Predicates::DC_PROTEGE->publisher ), undef); |
| 139 |
|
| my $statement = $enumerator->getFirst; |
| 140 |
|
| while (defined $statement) { |
| 141 |
|
| my $servicetype = $statement->getSubject->getLocalValue; |
| 142 |
|
| my $authURI = $statement->getObject->getValue; |
| 143 |
|
| |
| 144 |
|
| my $definition = $model->getObjects($statement->getSubject, new RDF::Core::Resource( MOBY::RDF::Predicates::RDFS->comment ) ); |
| 145 |
|
| $definition = "" unless $$definition[0]; |
| 146 |
|
| $definition = $$definition[0]->getValue if ref ($definition) eq 'ARRAY' and $$definition[0]; |
| 147 |
|
| |
| 148 |
|
| my $email = $model->getObjects($statement->getSubject, new RDF::Core::Resource( MOBY::RDF::Predicates::DC_PROTEGE->creator ) ); |
| 149 |
|
| $email = "" unless $$email[0]; |
| 150 |
|
| $email = $$email[0]->getValue if ref ($email) eq 'ARRAY' and $$email[0]; |
| 151 |
|
| |
| 152 |
|
| my $lsid = $model->getObjects($statement->getSubject, new RDF::Core::Resource( MOBY::RDF::Predicates::DC_PROTEGE->identifier ) ); |
| 153 |
|
| $lsid = "" unless $$lsid[0]; |
| 154 |
|
| $lsid = $$lsid[0]->getValue if ref ($lsid) eq 'ARRAY' and $$lsid[0]; |
| 155 |
|
| |
| 156 |
|
| |
| 157 |
|
| my $isa = $model->getObjects($statement->getSubject, new RDF::Core::Resource( MOBY::RDF::Predicates::RDFS->subClassOf ) ); |
| 158 |
|
| $isa = "" unless $$isa[0]; |
| 159 |
|
| $isa = $$isa[0]->getLocalValue if ref ($isa) eq 'ARRAY' and $$isa[0]; |
| 160 |
|
| |
| 161 |
|
| $hash{$servicetype} = { |
| 162 |
|
| email => $email, |
| 163 |
|
| authURI => $authURI, |
| 164 |
|
| lsid => $lsid, |
| 165 |
|
| definition => $definition, |
| 166 |
|
| isa => $isa, |
| 167 |
|
| }; |
| 168 |
|
| $statement = $enumerator->getNext |
| 169 |
|
| } |
| 170 |
|
| $enumerator->close; |
| 171 |
|
| |
| 172 |
|
| # return hash |
| 173 |
|
| return \%hash; |
| 174 |
|
| |
| 175 |
|
| } |
| 176 |
|
| |
| 177 |
|
| 1; |
| 178 |
|
| __END__ |