blib/lib/MOBY/RDF/Parsers/ServiceParser.pm untested

filter: Statementstmt 0.0% 0 / 315 Branchbran 0.0% 0 / 234 Conditioncond 0.0% 0 / 105 MC/DCmcdc 0.0% 0 / 70 Subroutinesub 0.0% 0 / 23 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 752 CC 118 SCAR 89.7
CC
118
Cov
0%
getServices
10712.0
_unwrap_datatype
42.0
_unwrap_namespace
42.0
CRAP 7886.6
1 #-----------------------------------------------------------------
2 # MOBY::RDF::Parsers::ServiceParser
3 # Author: Edward Kawas <edward.kawas@gmail.com>,
4 # For copyright and disclaimer see below.
5 #
6 # $Id: ServiceParser.pm,v 1.6 2009/02/03 18:05:03 kawas Exp $
7 #-----------------------------------------------------------------
8 package MOBY::RDF::Parsers::ServiceParser;
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  
19 use MOBY::Client::CollectionArticle;
20 use MOBY::Client::SimpleArticle;
21 use MOBY::Client::SecondaryArticle;
22 use MOBY::Client::ServiceInstance;
23  
24 use MOBY::RDF::Predicates::DC_PROTEGE;
25 use MOBY::RDF::Predicates::MOBY_PREDICATES;
26 use MOBY::RDF::Predicates::OMG_LSID;
27 use MOBY::RDF::Predicates::RDF;
28 use MOBY::RDF::Predicates::FETA;
29 use MOBY::RDF::Predicates::RDFS;
30  
31 use LS::ID;
32  
33 use vars qw /$VERSION/;
34 $VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /: (\d+)\.(\d+)/;
35  
36 =head1 NAME
37  
38 ServiceParser - An module for parsing the RDF that describes a biomoby service in the service instance ontology
39  
40 =cut
41  
42 =head1 SYNOPSIS
43  
44 use MOBY::RDF::Parsers::ServiceParser;
45 use Data::Dumper;
46  
47 # construct a parser for service instances
48 my $parser = MOBY::RDF::Parsers::ServiceParser->new();
49  
50 # get all services from a URL
51 my $service_arrayref = $parser->getServices(
52 'http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances/bioinfo.icapture.ubc.ca/getGoTerm'
53 );
54  
55 # print out details regarding 'bioinfo.icapture.ubc.ca/getGoTerm'
56 print Dumper( $service_arrayref );
57  
58 =cut
59  
60 =head1 DESCRIPTION
61  
62 This module contains the methods required to download and parse service instance RDF into individual services
63  
64 =cut
65  
66 =head1 WARNING
67  
68 Do not attempt to parse service instance RDF containing more than a few hundred services because the RDF is
69 parsed and held in memory.
70  
71 =cut
72  
73 =head1 AUTHORS
74  
75 Edward Kawas (edward.kawas [at] gmail [dot] com)
76  
77 =cut
78  
79 #-----------------------------------------------------------------
80  
81 =head1 SUBROUTINES
82  
83 =cut
84  
85 =head2 new
86  
87 Contructs a new ServiceParser.
88  
89 Input: none.
90  
91 Example:
92  
93 MOBY::RDF::Parsers::ServiceParser->new()
94  
95 =cut
96  
97 sub new {
98 my ($class) = @_;
99  
100 # create an object
101 my $self = bless {}, ref($class) || $class;
102  
103 # done
104 return $self;
105 }
106  
107 =head2 getServices
108  
109 Downloads RDF from $url, parses it and returns an arrayref of C<MOBY::Client::ServiceInstance>.
110  
111 Input: a scalar URL
112  
113 Example:
114  
115 my $parser = MOBY::RDF::Parsers::ServiceParser->new();
116 my $service_arref = $parser->getServices('http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances/bioinfo.icapture.ubc.ca/getGoTerm');
117  
118 =cut
119  
120 sub getServices {
121  
122 my ( $self, $url ) = @_;
123 my @services;
124 return \@services unless $url;
125  
126 # download string from url
127 my $rdf = undef;
128  
129 # 'try/catch'
130 eval { $rdf = MOBY::RDF::Utils->new()->getHttpRequestByURL($url); };
131 return \@services unless $rdf;
132  
133 # create RDF model and populate
134 my $storage = new RDF::Core::Storage::Memory;
135 my $model = new RDF::Core::Model( Storage => $storage );
136 my %options = (
137 Model => $model,
138 Source => $rdf,
139 SourceType => 'string',
140 BaseURI => "$url",
141 );
142 my $parser = new RDF::Core::Model::Parser(%options);
143 $parser->parse;
144  
145 # get information from the model
146 my $enumerator = $model->getStmts(
147 undef, undef,
148 new RDF::Core::Resource(
149 MOBY::RDF::Predicates::FETA
150 ->serviceDescription(
151 )
152 )
153 );
154 my $statement = $enumerator->getFirst;
155 while ( defined $statement ) {
156 my $instance = MOBY::Client::ServiceInstance->new;
157  
158 # set the name for the service
159 my $val = $model->getObjects(
160 $statement->getSubject,
161 new RDF::Core::Resource(
162 MOBY::RDF::Predicates::FETA
163 ->hasServiceNameText
164 )
165 );
166 $val = "" unless $$val[0];
167 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
168 $instance->name( MOBY::RDF::Utils::trim($val) );
169  
170 # set the category
171 $val = $model->getObjects(
172 $statement->getSubject,
173 new RDF::Core::Resource(
174 MOBY::RDF::Predicates::DC_PROTEGE->format
175 )
176 );
177 $val = "" unless $$val[0];
178 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
179 $instance->category( MOBY::RDF::Utils::trim($val) );
180  
181 # set the lsid
182 $val = $model->getObjects(
183 $statement->getSubject,
184 new RDF::Core::Resource(
185 MOBY::RDF::Predicates::DC_PROTEGE
186 ->identifier
187 )
188 );
189 $val = "" unless $$val[0];
190 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
191 $instance->LSID( MOBY::RDF::Utils::trim($val) );
192  
193 # set the signatureURL
194 $val = $model->getObjects(
195 $statement->getSubject,
196 new RDF::Core::Resource(
197 MOBY::RDF::Predicates::FETA
198 ->hasServiceDescriptionLocation
199 )
200 );
201 $val = "" unless $$val[0];
202 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
203 $instance->signatureURL( MOBY::RDF::Utils::trim($val) );
204  
205 # set the url
206 $val = $model->getObjects(
207 $statement->getSubject,
208 new RDF::Core::Resource(
209 MOBY::RDF::Predicates::FETA->locationURI
210 )
211 );
212 $val = "" unless $$val[0];
213 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
214 $instance->URL( MOBY::RDF::Utils::trim($val) );
215  
216 # set the service description text
217 $val = $model->getObjects(
218 $statement->getSubject,
219 new RDF::Core::Resource(
220 MOBY::RDF::Predicates::FETA
221 ->hasServiceDescriptionText
222 )
223 );
224 $val = "" unless $$val[0];
225 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
226 $instance->description( MOBY::RDF::Utils::trim($val) );
227  
228 # get providedBy node
229 my $providedBy =
230 $model->getObjects(
231 $statement->getSubject,
232 new RDF::Core::Resource(
233 MOBY::RDF::Predicates::FETA->providedBy
234 )
235 );
236 $providedBy = [] unless @$providedBy;
237 $providedBy = $$providedBy[0]
238 if ref($providedBy) eq 'ARRAY' and $$providedBy[0];
239 if ($providedBy) {
240  
241 # set the authoritative
242 $val = $model->getObjects(
243 $providedBy,
244 new RDF::Core::Resource(
245 MOBY::RDF::Predicates::FETA
246 ->authoritative
247 )
248 );
249 $val = "" unless $$val[0];
250 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
251 $instance->authoritative(
252 MOBY::RDF::Utils::trim($val) =~ m/true/i ? 1 : 0 );
253  
254 # set the contact email
255 $val = $model->getObjects(
256 $providedBy,
257 new RDF::Core::Resource(
258 MOBY::RDF::Predicates::DC_PROTEGE
259 ->creator
260 )
261 );
262 $val = "" unless $$val[0];
263 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
264 $instance->contactEmail( MOBY::RDF::Utils::trim($val) );
265  
266 # set the authority uri
267 $val = $model->getObjects(
268 $providedBy,
269 new RDF::Core::Resource(
270 MOBY::RDF::Predicates::DC_PROTEGE
271 ->publisher
272 )
273 );
274 $val = "" unless $$val[0];
275 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
276 $instance->authority( MOBY::RDF::Utils::trim($val) );
277 }
278  
279 # no longer need the providedBy node
280 $providedBy = undef;
281  
282 # get hasOperation node
283 my $hasOperation =
284 $model->getObjects(
285 $statement->getSubject,
286 new RDF::Core::Resource(
287 MOBY::RDF::Predicates::FETA->hasOperation
288 )
289 );
290 $hasOperation = [] unless @$hasOperation;
291 $hasOperation = $$hasOperation[0]
292 if ref($hasOperation) eq 'ARRAY' and $$hasOperation[0];
293  
294 # if this is missing ... what's the point?
295 next unless $hasOperation;
296  
297 # process any inputs
298 my $inputs = $model->getObjects(
299 $hasOperation,
300 new RDF::Core::Resource(
301 MOBY::RDF::Predicates::FETA->inputParameter
302 )
303 );
304 $inputs = [] unless @$inputs;
305 foreach my $input (@$inputs) {
306  
307 # check the type of param (simple, secondary, collection)
308 my $node =
309 $model->getObjects(
310 $input,
311 new RDF::Core::Resource(
312 MOBY::RDF::Predicates::FETA
313 ->hasParameterType
314 )
315 );
316 $node = [] unless @$node;
317 $node = $$node[0] if ref($node) eq 'ARRAY' and $$node[0];
318 $val = $model->getObjects(
319 $node,
320 new RDF::Core::Resource(
321 MOBY::RDF::Predicates::RDF->type
322 )
323 );
324 $val = "" unless $$val[0];
325 $val = $$val[0]->getURI if ref($val) eq 'ARRAY' and $$val[0];
326  
327 # process the datatype
328 if ( $val eq MOBY::RDF::Predicates::FETA->simpleParameter ) {
329 my $param = MOBY::Client::SimpleArticle->new();
330  
331 # get any namespaces
332 $val =
333 $model->getObjects(
334 $input,
335 new RDF::Core::Resource(
336 MOBY::RDF::Predicates::FETA
337 ->inNamespaces
338 )
339 );
340 $val = [] unless @$val;
341 foreach my $ns (@$val) {
342 $val =
343 $model->getObjects(
344 $ns,
345 new RDF::Core::Resource(
346 MOBY::RDF::Predicates::RDF->type
347 )
348 );
349 if ( $$val[0] ) {
350 for my $uri (@$val) {
351 $param->addNamespace( $self->_unwrap_namespace( $uri->getURI ) )
352 if $uri->getURI ne MOBY::RDF::Predicates::FETA
353 ->parameterNamespace;
354 }
355 }
356  
357 }
358  
359 # get the articlename
360 $val =
361 $model->getObjects(
362 $input,
363 new RDF::Core::Resource(
364 MOBY::RDF::Predicates::FETA
365 ->hasParameterNameText
366 )
367 );
368 $val = "" unless $$val[0];
369 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
370 $param->articleName($val);
371  
372 # get the datatype name
373 $val =
374 $model->getObjects(
375 $input,
376 new RDF::Core::Resource(
377 MOBY::RDF::Predicates::FETA
378 ->objectType
379 )
380 );
381 $val = undef unless $$val[0];
382 $val = $$val[0] if ref($val) eq 'ARRAY' and $$val[0];
383 $val =
384 $model->getObjects(
385 $val,
386 new RDF::Core::Resource(
387 MOBY::RDF::Predicates::RDF->type
388 )
389 );
390 if ( $$val[0] ) {
391 $param->objectType( $self->_unwrap_datatype($$val[0]->getURI) );
392 }
393  
394 # add the param to the service
395 push @{ $instance->input }, $param;
396 $param = undef;
397 }
398 elsif ( $val eq MOBY::RDF::Predicates::FETA->collectionParameter ) {
399 my $param = MOBY::Client::SimpleArticle->new();
400 my $collection = MOBY::Client::CollectionArticle->new();
401  
402 # get any namespaces
403 $val =
404 $model->getObjects(
405 $input,
406 new RDF::Core::Resource(
407 MOBY::RDF::Predicates::FETA
408 ->inNamespaces
409 )
410 );
411 $val = [] unless @$val;
412 foreach my $ns (@$val) {
413 $val =
414 $model->getObjects(
415 $ns,
416 new RDF::Core::Resource(
417 MOBY::RDF::Predicates::RDF->type
418 )
419 );
420 if ( $$val[0] ) {
421 for my $uri (@$val) {
422 $param->addNamespace( $self->_unwrap_namespace( $uri->getURI ) )
423 if $uri->getURI ne MOBY::RDF::Predicates::FETA
424 ->parameterNamespace;
425 }
426 }
427  
428 }
429  
430 # get the articlename
431 $val =
432 $model->getObjects(
433 $input,
434 new RDF::Core::Resource(
435 MOBY::RDF::Predicates::FETA
436 ->hasParameterNameText
437 )
438 );
439 $val = "" unless $$val[0];
440 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
441 $collection->articleName($val);
442  
443 # get the datatype name
444 $val =
445 $model->getObjects(
446 $input,
447 new RDF::Core::Resource(
448 MOBY::RDF::Predicates::FETA
449 ->objectType
450 )
451 );
452 $val = undef unless $$val[0];
453 $val = $$val[0] if ref($val) eq 'ARRAY' and $$val[0];
454 $val =
455 $model->getObjects(
456 $val,
457 new RDF::Core::Resource(
458 MOBY::RDF::Predicates::RDF->type
459 )
460 );
461 if ( $$val[0] ) {
462 $param->objectType( $self->_unwrap_datatype($$val[0]->getURI) );
463 }
464 $collection->addSimple($param);
465  
466 # add the param to the service
467 push @{ $instance->input }, $collection;
468 $param = undef;
469 }
470 elsif ( $val eq MOBY::RDF::Predicates::FETA->secondaryParameter ) {
471 my $param = MOBY::Client::SecondaryArticle->new;
472  
473 # get the articlename
474 $val =
475 $model->getObjects(
476 $input,
477 new RDF::Core::Resource(
478 MOBY::RDF::Predicates::FETA
479 ->hasParameterNameText
480 )
481 );
482 $val = undef unless $$val[0];
483 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
484 $param->articleName($val);
485  
486 # get the datatype name
487 $val =
488 $model->getObjects(
489 $input,
490 new RDF::Core::Resource(
491 MOBY::RDF::Predicates::FETA->datatype
492 )
493 );
494 $val = undef unless $$val[0];
495 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
496 $param->datatype($val);
497  
498 # get the max
499 $val =
500 $model->getObjects(
501 $input,
502 new RDF::Core::Resource(
503 MOBY::RDF::Predicates::FETA->max
504 )
505 );
506 $val = undef unless $$val[0];
507 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
508 $param->max($val);
509  
510 # get the min
511 $val =
512 $model->getObjects(
513 $input,
514 new RDF::Core::Resource(
515 MOBY::RDF::Predicates::FETA->min
516 )
517 );
518 $val = undef unless $$val[0];
519 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
520 $param->min($val);
521  
522 # get any enums
523 $val =
524 $model->getObjects(
525 $input,
526 new RDF::Core::Resource(
527 MOBY::RDF::Predicates::FETA->enum
528 )
529 );
530 $val = [] unless $$val[0];
531 foreach my $v ( @{$val} ) {
532 $param->addEnum( $v->getValue );
533 }
534  
535 # get the default
536 $val =
537 $model->getObjects(
538 $input,
539 new RDF::Core::Resource(
540 MOBY::RDF::Predicates::FETA
541 ->hasDefaultValue
542 )
543 );
544 $val = undef unless $$val[0];
545 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
546 $param->default($val);
547  
548 # get the description
549 $val =
550 $model->getObjects(
551 $input,
552 new RDF::Core::Resource(
553 MOBY::RDF::Predicates::FETA
554 ->hasParameterDescriptionText
555 )
556 );
557 $val = "" unless $$val[0];
558 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
559 $param->description($val);
560  
561 # add the secondary to the service
562 push @{ $instance->secondary }, $param;
563 $param = undef;
564 }
565 }
566  
567 # dont need $inputs
568 $inputs = undef;
569  
570 # process any outputs
571 my $outputs = $model->getObjects(
572 $hasOperation,
573 new RDF::Core::Resource(
574 MOBY::RDF::Predicates::FETA->outputParameter
575 )
576 );
577 $outputs = [] unless @$outputs;
578 foreach my $output (@$outputs) {
579  
580 # check the type of param (simple, secondary, collection)
581 my $node =
582 $model->getObjects(
583 $output,
584 new RDF::Core::Resource(
585 MOBY::RDF::Predicates::FETA
586 ->hasParameterType
587 )
588 );
589 $node = [] unless @$node;
590 $node = $$node[0] if ref($node) eq 'ARRAY' and $$node[0];
591 $val = $model->getObjects(
592 $node,
593 new RDF::Core::Resource(
594 MOBY::RDF::Predicates::RDF->type
595 )
596 );
597 $val = "" unless $$val[0];
598 $val = $$val[0]->getURI if ref($val) eq 'ARRAY' and $$val[0];
599  
600 # process the datatype
601 if ( $val eq MOBY::RDF::Predicates::FETA->simpleParameter ) {
602 my $param = MOBY::Client::SimpleArticle->new();
603  
604 # get any namespaces
605 $val =
606 $model->getObjects(
607 $output,
608 new RDF::Core::Resource(
609 MOBY::RDF::Predicates::FETA
610 ->inNamespaces
611 )
612 );
613 $val = [] unless @$val;
614 foreach my $ns (@$val) {
615 $val =
616 $model->getObjects(
617 $ns,
618 new RDF::Core::Resource(
619 MOBY::RDF::Predicates::RDF->type
620 )
621 );
622 if ( $$val[0] ) {
623 for my $uri (@$val) {
624 $param->addNamespace( $self->_unwrap_namespace( $uri->getURI ) )
625 if $uri->getURI ne MOBY::RDF::Predicates::FETA
626 ->parameterNamespace;
627 }
628 }
629  
630 }
631  
632 # get the articlename
633 $val =
634 $model->getObjects(
635 $output,
636 new RDF::Core::Resource(
637 MOBY::RDF::Predicates::FETA
638 ->hasParameterNameText
639 )
640 );
641 $val = "" unless $$val[0];
642 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
643 $param->articleName($val);
644  
645 # get the datatype name
646 $val =
647 $model->getObjects(
648 $output,
649 new RDF::Core::Resource(
650 MOBY::RDF::Predicates::FETA
651 ->objectType
652 )
653 );
654 $val = undef unless $$val[0];
655 $val = $$val[0] if ref($val) eq 'ARRAY' and $$val[0];
656 $val =
657 $model->getObjects(
658 $val,
659 new RDF::Core::Resource(
660 MOBY::RDF::Predicates::RDF->type
661 )
662 );
663 if ( $$val[0] ) {
664 $param->objectType( $self->_unwrap_datatype($$val[0]->getURI) );
665 }
666  
667 # add the param to the service
668 push @{ $instance->output }, $param;
669 $param = undef;
670 }
671 elsif ( $val eq MOBY::RDF::Predicates::FETA->collectionParameter ) {
672 my $param = MOBY::Client::SimpleArticle->new();
673 my $collection = MOBY::Client::CollectionArticle->new();
674  
675 # get any namespaces
676 $val =
677 $model->getObjects(
678 $output,
679 new RDF::Core::Resource(
680 MOBY::RDF::Predicates::FETA
681 ->inNamespaces
682 )
683 );
684 $val = [] unless @$val;
685 foreach my $ns (@$val) {
686 $val =
687 $model->getObjects(
688 $ns,
689 new RDF::Core::Resource(
690 MOBY::RDF::Predicates::RDF->type
691 )
692 );
693 if ( $$val[0] ) {
694 for my $uri (@$val) {
695 $param->addNamespace( $self->_unwrap_namespace( $uri->getURI ) )
696 if $uri->getURI ne MOBY::RDF::Predicates::FETA
697 ->parameterNamespace;
698 }
699 }
700 }
701  
702 # get the articlename
703 $val =
704 $model->getObjects(
705 $output,
706 new RDF::Core::Resource(
707 MOBY::RDF::Predicates::FETA
708 ->hasParameterNameText
709 )
710 );
711 $val = "" unless $$val[0];
712 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
713 $collection->articleName($val);
714  
715 # get the datatype name
716 $val =
717 $model->getObjects(
718 $output,
719 new RDF::Core::Resource(
720 MOBY::RDF::Predicates::FETA
721 ->objectType
722 )
723 );
724 $val = undef unless $$val[0];
725 $val = $$val[0] if ref($val) eq 'ARRAY' and $$val[0];
726 $val =
727 $model->getObjects(
728 $val,
729 new RDF::Core::Resource(
730 MOBY::RDF::Predicates::RDF->type
731 )
732 );
733 if ( $$val[0] ) {
734 $param->objectType( $self->_unwrap_datatype($$val[0]->getURI) );
735 }
736 $collection->addSimple($param);
737  
738 # add the param to the service
739 push @{ $instance->output }, $collection;
740 $param = undef;
741 }
742 }
743  
744 # dont need $outputs
745 $outputs = undef;
746  
747 # process the performsTask
748 # get performsTask node
749 my $performs =
750 $model->getObjects(
751 $hasOperation,
752 new RDF::Core::Resource(
753 MOBY::RDF::Predicates::FETA->performsTask
754 )
755 );
756 $performs = [] unless @$performs;
757 $performs = $$performs[0]
758 if ref($performs) eq 'ARRAY' and $$performs[0];
759 $val = $model->getObjects(
760 $performs,
761 new RDF::Core::Resource(
762 MOBY::RDF::Predicates::RDF->type
763 )
764 );
765 if ( $$val[0] ) {
766 for my $uri (@$val) {
767 $val = $uri->getURI
768 if $uri->getURI ne
769 MOBY::RDF::Predicates::FETA->operationTask();
770 last
771 if $uri->getURI ne
772 MOBY::RDF::Predicates::FETA->operationTask();
773 }
774 }
775 $val = "" if ref($val) eq 'ARRAY';
776 $instance->type( $self->_unwrap_servicetype ( MOBY::RDF::Utils::trim($val) ) );
777  
778 # dont need the performsTask node anymore
779 $performs = undef;
780  
781 # process any unit test information
782 my $unit_test =
783 $model->getObjects(
784 $hasOperation,
785 new RDF::Core::Resource(
786 MOBY::RDF::Predicates::FETA->hasUnitTest
787 )
788 );
789 $unit_test = [] unless @$unit_test;
790 foreach my $ut (@$unit_test) {
791 my $unit = new MOBY::Client::MobyUnitTest;
792  
793 # get example input
794 $val =
795 $model->getObjects(
796 $ut,
797 new RDF::Core::Resource(
798 MOBY::RDF::Predicates::FETA->exampleInput
799 )
800 );
801 $val = "" unless $$val[0];
802 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
803 $unit->example_input( MOBY::RDF::Utils::trim($val) );
804  
805 # get example output
806 $val =
807 $model->getObjects(
808 $ut,
809 new RDF::Core::Resource(
810 MOBY::RDF::Predicates::FETA
811 ->validOutputXML
812 )
813 );
814 $val = "" unless $$val[0];
815 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
816 $unit->expected_output( MOBY::RDF::Utils::trim($val) );
817  
818 # get regex
819 $val =
820 $model->getObjects(
821 $ut,
822 new RDF::Core::Resource(
823 MOBY::RDF::Predicates::FETA->validREGEX
824 )
825 );
826 $val = "" unless $$val[0];
827 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
828 $unit->regex( MOBY::RDF::Utils::trim($val) );
829  
830 # get xpath
831 $val =
832 $model->getObjects(
833 $ut,
834 new RDF::Core::Resource(
835 MOBY::RDF::Predicates::FETA->validXPath
836 )
837 );
838 $val = "" unless $$val[0];
839 $val = $$val[0]->getValue if ref($val) eq 'ARRAY' and $$val[0];
840 $unit->xpath( MOBY::RDF::Utils::trim($val) );
841  
842 # set the unit test in the service
843 push @{ $instance->unitTests }, $unit;
844  
845 #$instance->unitTest($unit);
846 }
847  
848 # this service is done ...
849 push @services, $instance;
850  
851 # next if any
852 $statement = $enumerator->getNext;
853 }
854 $enumerator->close;
855  
856 # return array ref
857 return \@services;
858  
859 }
860  
861 sub _unwrap_datatype {
862 my ($self, $uri) = @_;
863
864 # process the objectType, i.e. check to see if it is an LSID, or uri, etc
865 if ( $uri =~ m/RESOURCES\/MOBY\-S\/Objects(\/[A-Za-z0-9_\-]*)?$/ ) {
866 $uri = substr $1, 1 if $1;
867 } elsif (
868 $uri =~ m/RESOURCES\/MOBY\-S\/Objects(\#[A-Za-z0-9_\-]*)?$/ ) {
869 $uri = substr $1, 1 if $1;
870 } elsif ( $uri =~ m/^urn\:lsid/i ) {
871 #my $lsid = LS::ID->new( $uri );
872 #$uri = $lsid->object if $lsid;
873 }
874 return $uri;
875 }
876  
877 sub _unwrap_namespace {
878 my ($self, $n) = @_;
879 # get only the namespace name (strip from lsid or URI)
880 if ($n =~ m/RESOURCES\/MOBY\-S\/Namespaces(\/[A-Za-z0-9_\-]*)?$/) {
881 $n = substr $1, 1 if $1;
882 } elsif ($n =~ m/RESOURCES\/MOBY\-S\/Namespaces(\#[A-Za-z0-9_\-]*)?$/ ){
883 $n = substr $1, 1 if $1;
884 } elsif( $n =~ m/^urn\:lsid/i) {
885 #my $lsid = LS::ID->new($n);
886 #$n = $lsid->object if $lsid;
887 }
888 return $n;
889 }
890  
891 sub _unwrap_servicetype {
892 my ($self, $n) = @_;
893 # get only the servicetype name (strip from lsid or URI)
894 if ($n =~ m/RESOURCES\/MOBY\-S\/Services(\/[A-Za-z0-9_\-]*)?$/) {
895 $n = substr $1, 1 if $1;
896 } elsif ($n =~ m/RESOURCES\/MOBY\-S\/Services(\#[A-Za-z0-9_\-]*)?$/ ){
897 $n = substr $1, 1 if $1;
898 } elsif( $n =~ m/^urn\:lsid/i) {
899 #my $lsid = LS::ID->new($n);
900 #$n = $lsid->object if $lsid;
901 }
902 return $n;
903 }
904  
905  
906 1;
907 __END__