[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Fri Jul 4 14:43:09 UTC 2003


mwilkinson
Fri Jul  4 10:43:09 EDT 2003
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv1322/MOBY

Modified Files:
	Central.pm 
Log Message:
fixing errors in the registry and test scripts reported by Rebecca.  thanks!


moby-live/Perl/MOBY Central.pm,1.89,1.90
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Central.pm,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -r1.89 -r1.90
--- /home/repository/moby/moby-live/Perl/MOBY/Central.pm	2003/07/03 17:07:50	1.89
+++ /home/repository/moby/moby-live/Perl/MOBY/Central.pm	2003/07/04 14:43:09	1.90
@@ -1080,7 +1080,7 @@
 		return &_error("Registration Failed During SECONDARY Article Registration: $msg","") unless ($success==1);
 	}
 	
-	return &success("Registration successful", $SVC->service_instance_id);
+	return &_success("Registration successful", $SVC->service_instance_id);
 }
 
 sub _registerArticles {
@@ -1566,10 +1566,8 @@
 }
 
 sub _searchForServicesWithArticle {
-    my ($dbh, $inout, $node, $expand, $coll) = @_;  # coll is set if we are already searching
-	# the Simple articles within a Collection
-	# if we are, then an additional criterion of a common collection_inout_id
-	# is added to the query.... somehow...
+    my ($dbh, $inout, $node, $expand, $coll) = @_;
+
     return () unless $node->getNodeType == ELEMENT_NODE; # this will erase all current successful service instances!
     $debug && _LOG("searchServWthArticle ",$dbh, $inout, $node, $expand, $coll);
     # this element node may be a Simple or a Collection object
@@ -1578,34 +1576,18 @@
 	
 	my @valid_ids;
     if ($simp_coll eq "Collection"){
-		#######################################
-		# MARK START HERE
-		#######################################
-		
 		@valid_ids = &_searchForCollection($dbh, $node, $expand, $inout);
-		#return ();  # this will erase all current successful service_instance matches... too bad
-		# not yet implemented
-		#$debug && &_LOG("Collection!\n");  # the following SQl belongs in the service_instance object, but screw it, I'm running out of time!
-		#my $Simples = $node->getElementsByTagName('Simple');
-		#my $length = $Simples->getLength;
-		#my @simples;
-		#for (my $x=0; $x<$length; ++$x){
-		#	push @simples, $Simples->item($x);
-		#}
-		#@collids = &_searchForCollectedSimples($dbh, $inout, \@simples);
     } elsif ($simp_coll eq "Simple")  {
 		@valid_ids = &_searchForSimple($dbh,$node, $expand, $inout);
-
     }
 	return @valid_ids; 
 }
-
 sub _searchForSimple {
 	# returns list of service_instance ID's
 	# that match this simple
 	my ($dbh,$node, $expand, $inout) = @_;
 	$debug && _LOG($dbh,$node, $expand, $inout);
-	my ($objectURI, $namespaceURIs) = &_extractObjectTypesAndNamespaces($node); # ref of $hash{type}=[ns1, ns2, ns3]
+	my ($objectURI, $namespaceURIs) = &_extractObjectTypesAndNamespaces($node); # (objectType, [ns1, ns2, ns3])
 	unless ($objectURI){return ()};
 	my $ancestor_string = "'$objectURI',";
 	if ($expand){
@@ -1631,30 +1613,51 @@
 	}
 	return @ids;	
 }
+sub _searchForCollection {
 
-sub _searchForCollectedSimples {
-	# retuns the unique 
-	my ($dbh, $inout, $simples)= @_;
+	my ($dbh, $node, $expand, $inout)= @_;  # $node in this case is a Collection object
 	my $query;
-	foreach my $node(@{$simples}){
-		my ($objectURI, $namespaceURIs) = &_extractObjectTypesAndNamespaces($node);
+#######################
+#	return; # abort for the moment
+#######################
+		#######################################
+		# MARK START HERE
+		#######################################
+		
+	foreach my $simple($node->getChildNodes()){
+		next unless ($simple->getNodeType == ELEMENT_NODE);
+		next unless ($simple->getTagName =~ /simple/i);
+		my ($objectURI, $namespaceURIs) = &_extractObjectTypesAndNamespaces($simple);
+		
+		$query = "select c.service_instance_id, s.namespace_type_uris from simple_input as s, collection_input as c where s.collection_input_id IS NOT NULL and s.collection_input_id = c.collection_input_id AND object_type_uri = '$objectURI' ";
+		
 		my $nsquery;
 		foreach my $ns(@{$namespaceURIs}){ # namespaces are already URI's
 			$nsquery .=" OR namespace_type_uris like '%$ns%' ";
 		}
 		if ($nsquery){$nsquery =~ s/OR//;} # just the first
-		$query .= " OR (object_type_uri = '$objectURI' AND ($nsquery)) ";
+		$query .= " AND ($nsquery) ";
+		my $sth = $dbh->prepare($query);
+		$sth->execute;
+		my @valid_service_ids;
+		while (my ($id, $nss) = $sth->fetchrow_array){  # get the service instance ID and the namespaces that matched
+			my @ns = split ",", $nss;  # because of the database structure we have to re-test for *identity*, not just like%% similarity
+			my %nshash = map {($_, 1)} @ns,@{$namespaceURIs};  #we're going to test identity by building a hash of namespaces as keys 
+			if (scalar(keys %nshash) < scalar(@ns)+scalar(@{$namespaceURIs})){  # if the number of keys is less than the sum of the number of keys goign into the hash, then one of them was identical
+				push @valid_service_ids, $id;  # and therefore it really is a match, and is valid
+			}
+		}
+		&_LOG("QUERY: $query");
 	}	
-	if ($query){$query =~s/AND//;} # just the first
-	$debug && &_LOG("_searchForCollectedSimples QUERY = select distinct(collection_$inout"."id from  simple_$inout where collection_$inout"."_id IS NOT NULL AND $query\n\n");
-	
-	my $collids = $dbh->selectall_arrayref("create temporary table select distinct(collection_$inout"."id from  simple_$inout where  collection_$inout"."_id IS NOT NULL AND $query");
-	my @result;	
-	foreach (@{$collids}){
-		push @result, $_->[0];
-	}
-
-
+	return;
+#	if ($query){$query =~s/AND//;} # just the first
+#	$debug && &_LOG("_searchForCollectedSimples QUERY = select distinct(collection_$inout"."id from  simple_$inout where collection_$inout"."_id IS NOT NULL AND $query\n\n");
+	#
+	#my $collids = $dbh->selectall_arrayref("create temporary table select distinct(collection_$inout"."id from  simple_$inout where  collection_$inout"."_id IS NOT NULL AND $query");
+	#my @result;	
+	#foreach (@{$collids}){
+	#	push @result, $_->[0];
+	#}
 }
 
 sub _findServicePayload {




More information about the MOBY-guts mailing list