[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Tue Dec 9 21:06:51 UTC 2003


mwilkinson
Tue Dec  9 16:06:51 EST 2003
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv28169/Perl/MOBY

Modified Files:
	CommonSubs.pm 
Log Message:
added a generic server-side parser to CommonSubs that should basically do all of the work for you and be compatible with the 0.6 API.  Not yet documented; just testing on my own services first.

moby-live/Perl/MOBY CommonSubs.pm,1.28,1.29
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2003/11/12 16:47:16	1.28
+++ /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2003/12/09 21:06:51	1.29
@@ -143,9 +143,17 @@
 use XML::DOM;
 use MOBY::CrossReference;
 use MOBY::Client::OntologyServer;
+use strict;
+use warnings;
 
- at ISA = qw(Exporter);
- at EXPORT_OK = qw(
+use constant COLLECTION => 1;
+use constant SIMPLE => 2;
+use constant BE_NICE => 1;
+use constant BE_STRICT => 0;
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(COLLECTION SIMPLE BE_NICE BE_STRICT);
+our @EXPORT_OK = qw(
     getSimpleArticleIDs
     getSimpleArticleNamespaceURI
     simpleResponse
@@ -165,8 +173,13 @@
     extractResponseArticles
     getResponseArticles
     getCrossReferences
+    genericServiceInputParser
+    COLLECTION
+    SIMPLE
+    BE_NICE
+    BE_STRICT
     );
-%EXPORT_TAGS =(all => [qw(
+our %EXPORT_TAGS =(all => [qw(
     getSimpleArticleIDs
     getSimpleArticleNamespaceURI
     simpleResponse
@@ -186,9 +199,39 @@
     extractResponseArticles
     getResponseArticles
     getCrossReferences
+    genericServiceInputParser
+    COLLECTION
+    SIMPLE
+    BE_NICE
+    BE_STRICT
     )]);
 
 
+
+sub genericServiceInputParser {
+    my ($message, $namespaces) = @_;  # get the incoming MOBY query XML
+    my @inputs;           # set empty response
+    my @queries = getInputs($message);  # returns XML::DOM nodes
+    
+    foreach my $query(@queries){
+        my $queryID = getInputID($query);  # get the queryID attribute of the queryInput
+        my @input_articles = getArticles($query); # get the Simple/Collection articles making up this query
+        foreach my $input(@input_articles){       # input is a listref
+           my ($articleName, $article) = @{$input}; # get the named article
+           my $simple = isSimpleArticle($article);  # articles may be simple or collection
+           my $collection = isCollectionArticle($article);
+            if ($collection){
+                my @simples = getCollectedSimples($article);
+                push @inputs, [COLLECTION,$queryID, \@simples];
+
+            } elsif ($simple){
+                push @inputs, [SIMPLE,$queryID,$simple];
+            }
+        }
+    }
+    return @inputs;
+}
+
 #################################################
 					 ##################################
 					 ##################################
@@ -482,7 +525,7 @@
 sub getInputs {
 
 	my ($XML) = @_;
-
+    my $moby;
     unless (ref($XML) =~ /XML\:\:DOM/){
         my $parser = new XML::DOM::Parser;
         my $doc = $parser->parse($XML);
@@ -573,7 +616,7 @@
     return undef unless $moby->getNodeType == ELEMENT_NODE;
     return undef unless ($moby->getTagName =~ /queryInput/ || $moby->getTagName =~ /queryResponse/);
     my @articles;
-    foreach $child($moby->getChildNodes){ # there may be more than one Simple/Collection per input; iterate over them 
+    foreach my $child($moby->getChildNodes){ # there may be more than one Simple/Collection per input; iterate over them 
         next unless $child->getNodeType == ELEMENT_NODE; # ignore whitespace
         next unless ($child->getTagName =~ /Simple/ || $child->getTagName =~ /Collection/);
         my $articleName = $child->getAttribute('articleName');
@@ -608,7 +651,7 @@
     return undef unless ($moby->getTagName =~ /Collection/);
     
     my @articles;
-    foreach $child($moby->getChildNodes){ # there may be more than one Simple/Collection per input; iterate over them 
+    foreach my $child($moby->getChildNodes){ # there may be more than one Simple/Collection per input; iterate over them 
         next unless $child->getNodeType == ELEMENT_NODE; # ignore whitespace
         next unless ($child->getTagName =~ /Simple/);
         push @articles, $child;   # take the child elements, which are <Simple/> or <Collection/>
@@ -667,7 +710,7 @@
     my @queries;
     for (0..$x->getLength-1){ # there may be more than one queryInput per message
 		my @this_query;
-        foreach $child($x->item($_)->getChildNodes){ # there may be more than one Simple/Collection per input; iterate over them 
+        foreach my $child($x->item($_)->getChildNodes){ # there may be more than one Simple/Collection per input; iterate over them 
             next unless $child->getNodeType == ELEMENT_NODE; # ignore whitespace
                 push @this_query, $child;   # take the child elements, which are <Simple/> or <Collection/>
         }
@@ -814,7 +857,7 @@
         $nodes = $node->getElementsByTagName("moby:$element");
     }
 	for (0..$nodes->getLength-1){
-        $child = $nodes->item($_);
+        my $child = $nodes->item($_);
 		if (
             (($child->getAttribute("articleName")) && (($child->getAttribute("articleName") eq $articleName)))
             || (($child->getAttribute("moby:articleName")) && (($child->getAttribute("moby:articleName") eq $articleName)))){
@@ -859,6 +902,29 @@
 }
 
 
+
+
+=head2 validateThisNamespace
+
+ name     : validateThisNamespace
+ function : checks a given namespace against a list of valid namespaces
+ usage    : $valid = validateThisNamespace($ns, @validNS);
+ args     : ordered list of the namespace of interest and the list of valid NS's
+ returns  : boolean
+
+
+=cut
+
+
+sub validateThisNamespace {
+    my ($ns, @namespaces) = @_;
+    foreach (@namespaces){
+        return 1 if $ns eq $_;
+    }
+    return 0;
+}
+
+
 =head2 getResponseArticles (a.k.a. extractResponseArticles)
 
  name     : getResponseArticles
@@ -976,7 +1042,7 @@
         }
     }
     foreach (@xrefs){
-        $x = &_makeXrefType($_) if $_->getTagName =~/Xref/;
+        my $x = &_makeXrefType($_) if $_->getTagName =~/Xref/;
         $x = &_makeObjectType($_) if $_->getTagName =~ /Object/;
         push @XREFS, $x if $x;
     }




More information about the MOBY-guts mailing list