[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Fri Jul 11 22:10:49 UTC 2003


mwilkinson
Fri Jul 11 18:10:49 EDT 2003
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv14772/Perl/MOBY

Modified Files:
	Central.pm 
Log Message:
error in service discovery.  Services that did not care about namespaces were being ignored in queries that included namespaces as input.  A second error in Simple Article discovery allowed false namespaces to be discovered if it was a prefix of a longer namespace due to the silly %like% matching that I am doing to avoid having to do a big join on object and namespace tables

moby-live/Perl/MOBY Central.pm,1.95,1.96
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Central.pm,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- /home/repository/moby/moby-live/Perl/MOBY/Central.pm	2003/07/10 06:06:57	1.95
+++ /home/repository/moby/moby-live/Perl/MOBY/Central.pm	2003/07/11 22:10:48	1.96
@@ -1630,22 +1630,38 @@
 		$ancestor_string .= (join ',', map {"\'$_\'"} @ancestors);
 	}
 	$ancestor_string =~ s/\,$//;
+
+	my $query = "select service_instance_id, namespace_type_uris from simple_$inout where object_type_uri in ($ancestor_string) and service_instance_id IS NOT NULL ";# if service_instance_id is null then it must be a collection input.
+
 	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
-	my $query = "select distinct service_instance_id from simple_$inout where object_type_uri in ($ancestor_string) and service_instance_id IS NOT NULL ";# if service_instance_id is null then it must be a collection input.
-	($nsquery) && ($query .=" AND ($nsquery) ");
+	if ($nsquery){
+		$nsquery =~ s/OR//; # just the first
+		$nsquery .= " OR namespace_type_uris IS NULL";
+	    $query .=" AND ($nsquery) ";
+	}
 	$debug && _LOG("\nQUERY $query\n");
-	my $ids = $dbh->selectall_arrayref($query);
-	my @ids;
-	foreach (@{$ids}){
-		push @ids, $_->[0];
+
+	my @valid_services;
+
+	my $sth = $dbh->prepare($query);
+	while (my ($id, $nss) = $sth->fetchrow_array){  # get the service instance ID and the namespaces that matched
+		if (scalar @{$namespaceURIs}){  # if namespaces were specified, then validate the discovered service against this list
+			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_services, $id;  # and therefore it really is a match, and is valid
+			}
+		} else {  # if no namespace was specified, then all of them are valid
+			push @valid_services, $id
+		}
 	}
-	$debug && _LOG("Resulting IDs were ".(join ',', @ids)."\n");
-	return @ids;	
+	$debug && _LOG("Resulting IDs were ".(join ',', @valid_services)."\n");
+	return @valid_services;	
 }
+
 sub _searchForCollection {
 	my ($dbh, $node, $expand, $inout)= @_;  # $node in this case is a Collection object
 	my $query;
@@ -1675,6 +1691,7 @@
 		}
 		if ($nsquery){
 			$nsquery =~ s/^\sOR//; # just the first
+			$nsquery .= " OR namespace_type_uris IS NULL";
 			$query .= " AND ($nsquery) ";  # add the AND clause 
 		} 
 		




More information about the MOBY-guts mailing list