[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Fri Sep 12 23:41:44 EDT 2003


mwilkinson
Fri Sep 12 22:41:44 EDT 2003
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv21515/Perl/MOBY

Modified Files:
	CommonSubs.pm 
Log Message:
added new service and a few new utility subroutines to the CommonSubs module

moby-live/Perl/MOBY CommonSubs.pm,1.11,1.12
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2003/07/17 15:50:14	1.11
+++ /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2003/09/13 02:41:44	1.12
@@ -349,8 +349,9 @@
             and/or Collection articles.  These are provided as XML::DOM nodes.
             
             i.e.:  @queries = ([$SIMPLE_DOM_NODE], [$SIMPLE_DOM_NODE2])
+            or  :  @queries = ([$COLLECTION_DOM_NODE], [$COLLECTION_DOM_NODE2])
             
-            is generated from the XML
+            the former is generated from the following XML:
             
                 ...
               <moby:Query>
@@ -365,6 +366,11 @@
                     </Simple>
                 </queryInput>
               </moby:Query>
+                 ...
+ note     : This subroutine enforces valid message structure
+            in that you may only have one Simple OR one Collection
+            article per queryInput!  if you have more, only the first
+            is read.  
 
 =cut
 
@@ -382,19 +388,64 @@
     }
 
     my @queries;
-    for (0..$x->getLength-1){
-		# there *should* only be *one* node per queryInput in a Simple article, but... yeah...
+    for (0..$x->getLength-1){ # there may be more than one queryInput per message
+		# but there *should* only be *one* child node per queryInput, Simple or Collection!
         my @this_query;
-        foreach $child($x->item($_)->getChildNodes){
-            next unless $child->getNodeType == ELEMENT_NODE;
-            push @this_query, $child;   # anyway, take all of the child elements, which are Simple Articles
+        foreach $child($x->item($_)->getChildNodes){ # still, iterate over them just in case (though the meaning is ambiguous if there is more than one)
+            next unless $child->getNodeType == ELEMENT_NODE; # ignore whitespace
+            push @this_query, $child;   # take the child elements, which are <Simple/> or <Collection/>
+            last;  # ENFORCE CORRECT XML!!  Only one input article per query!!
         }
         push @queries, \@this_query;
 	}
 	return @queries;  # return them in the order that they were discovered.
 }
 
+=head2 isSimpleArticle
 
+ name     : isSimpleArticle
+ function : tests an XML or XML DOM node to see if it represents a Simple article
+ usage    : if (isSimpleArticle($node)){do something to it}
+ input    : an XML::DOM node, or straight XML
+ returns  : boolean
+
+=cut
+
+sub isSimpleArticle {
+    my ($DOM) = @_;
+    unless (ref($DOM) =~ /XML\:\:DOM/){
+        my $parser = new XML::DOM::Parser;
+        my $doc;
+        eval {$doc = $parser->parse($DOM);};
+        return 0 if ($@);
+        $DOM = $doc->getDocumentElement();
+    }
+    return 1 if ($DOM->getTagName eq "Simple");
+    return 0;
+}
+
+=head2 isCollectionArticle
+
+ name     : isCollectionArticle
+ function : tests an XML or XML DOM node to see if it represents a Collection article
+ usage    : if (isCollectionArticle($node)){do something to it}
+ input    : an XML::DOM node, or straight XML
+ returns  : boolean
+
+=cut
+
+sub isCollectionArticle {
+    my ($DOM) = @_;
+    unless (ref($DOM) =~ /XML\:\:DOM/){
+        my $parser = new XML::DOM::Parser;
+        my $doc;
+        eval {$doc = $parser->parse($DOM);};
+        return 0 if ($@);
+        $DOM = $doc->getDocumentElement();
+    }
+    return 1 if ($DOM->getTagName eq "Collection");
+    return 0;
+}
 
 =head2 getNodeContentWithArticle
 
@@ -468,3 +519,31 @@
 	}
 	return @contents;
 }
+
+
+
+=head2 validateNamespaces
+
+ name     : validateNamespaces
+ function : checks the namespace ontology for the namespace lsid
+ usage    : @LSIDs = validateNamespaces(@namespaces)
+ args     : ordered list of either human-readable or lsid presumptive namespaces
+ returns  : ordered list of the LSID's corresponding to those
+            presumptive namespaces; undef for each namespace that was invalid
+
+
+=cut
+
+
+sub validateNamespaces {
+    # give me a list of namespaces and I will return the LSID's in order
+    # I return undef in that list position if the namespace is invalid
+    my (@namespaces) = @_;
+    my $OS = MOBY::Client::OntologyServer->new;
+    my @lsids;
+    foreach (@namespaces){	
+    	my ($s, $m, $LSID) = $OS->namespaceExists(term => $_);
+        push @lsids, $s?$LSID:undef;
+    }
+    return @lsids;
+}
\ No newline at end of file



More information about the MOBY-guts mailing list