[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Wed Oct 15 22:32:05 EDT 2003


mwilkinson
Wed Oct 15 21:32:05 EDT 2003
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv10136/Perl/MOBY

Modified Files:
	CommonSubs.pm 
Log Message:
fixing CommonSubs bug that Ken discovered a couple of days ago.  The getNodeContentWithArticle subroutine didn't burrow deeply enough into an object to find the nodes that were being searched for.  It now burrows throughout the object finding all matching nodes and returns the contents as an array with each element being the content of one match

moby-live/Perl/MOBY CommonSubs.pm,1.15,1.16
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2003/09/22 16:25:20	1.15
+++ /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2003/10/16 01:32:05	1.16
@@ -467,7 +467,8 @@
             $tagname     - the tagname (effectively from the Object type ontology)
             $articleName - the articleName that we are searching for
             
- returns  : an array of the stringified contents of each child node of the matching node
+ returns  : an array of the stringified text content for each
+            node that matched the tagname/articleName specified.
  notes    : This was written for the purpose of getting the values of
             String, Integer, Float, Date_Time, and other such primitives.
             For example, in the following XML:
@@ -493,8 +494,8 @@
               foreach (@queries){
                  my @inputs = @{$_}; #(may be more than one Simple/Collection input per query)
                  foreach my $input(@inputs){
-                     @sequence = getNodeContentWithArticle($_, "String", "SequenceString");
-                     print "Sequence was ".(join "", @sequence)."\n"; # join all lines of string
+                     @sequences = getNodeContentWithArticle($_, "String", "SequenceString");
+                     print "matching node contents were ".(join "\n\n", @sequences)."\n"; # join all lines of string
                  }   
               }
 
@@ -513,15 +514,22 @@
 	# carriage returns, as these might be meaningful!
 	my ($node, $element, $articleName) = @_;
 	my @contents;
-	foreach my $child ($node->getChildNodes){
-		print STDERR "looking at child ".($child->toString)." named " .($child->getNodeName)."comparing to $element\n\n\n\n";
-		next unless $child->getNodeTypeName eq "ELEMENT_NODE";
-        next unless (($child->getNodeName eq $element) || ($child->getNodeName eq "moby:$element"));
-		if (($child->getAttribute("articleName")) && (($child->getAttribute("articleName") eq $articleName))){
+    return () unless ref($node)=~/XML::DOM/;
+    return () unless $element;
+    return () unless $articleName;
+    my $nodes = $node->getElementsByTagName($element);
+    unless ($nodes->item(0)){
+        $nodes = $node->getElementsByTagName("moby:$element");
+    }
+	for (0..$nodes->getLength-1){
+        $child = $nodes->item($_);
+		if (
+            (($child->getAttribute("articleName")) && (($child->getAttribute("articleName") eq $articleName)))
+            || (($child->getAttribute("moby:articleName")) && (($child->getAttribute("moby:articleName") eq $articleName)))){
 			# now we have a valid child, get the content... stringified... regardless of what it is
-			print STDERR "FOUND CHILD ".($child->toString)."\n\n\n\n";
 			my $resp;
 			foreach ($child->getChildNodes){
+                next unless $_->getNodeType == TEXT_NODE;
 				$resp .= $_->toString;
 			}
 			push @contents, $resp;



More information about the MOBY-guts mailing list