[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Wed Nov 23 20:58:36 UTC 2005


mwilkinson
Wed Nov 23 15:58:36 EST 2005
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv17528/MOBY

Modified Files:
	Central.pm OntologyServer.pm 
Log Message:
modified the Perl Client API a little bit (in a way that is reflective of how I would like to modify it overall).  Changed the Relationships call such that it returns (a) the articleName as well as the related object,and (b) returns these as a hashref rather than a listref.  The MOBY Central API for the Relationships call has also changed in a way that should not break any existing code.  A new attribute has been added to the objectType element in the Relationship call response.  The attribute is articleName and it reflects the articleName of the associated objectType in the context of that relationship.

moby-live/Perl/MOBY Central.pm,1.222,1.223 OntologyServer.pm,1.88,1.89
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Central.pm,v
retrieving revision 1.222
retrieving revision 1.223
diff -u -r1.222 -r1.223
--- /home/repository/moby/moby-live/Perl/MOBY/Central.pm	2005/09/29 14:47:39	1.222
+++ /home/repository/moby/moby-live/Perl/MOBY/Central.pm	2005/11/23 20:58:36	1.223
@@ -484,7 +484,8 @@
 	(@ISAlist = @{$relationships->{$isa}}) if ($relationships->{$isa}) ;
 	# for each of the inherited parents, check their articleNames
 	foreach my $ISA(@ISAlist){  # $ISA = [lsid, articleName] (but articleName shuld be null anyway in this case)
-		my $what_it_is = shift @$ISA;
+		my $what_it_is = $ISA->{lsid};
+		# my $articleName = $ISA->{articleName}
 		map {($x=1) if ($what_it_is eq $_)} @primitive_lsids; # test primitives against this one
 	}
 	return $x; # return flag state
@@ -2892,8 +2893,8 @@
  outputXML :
   <Relationships>
     <Relationship relationshipType="RelationshipOntologyTerm">
-       <objectType lsid='urn:lsid...'>ExistingServiceType</objectType>
-       <objectType lsid='urn:lsid...'>ExistingServiceType</objectType>
+       <objectType lsid='urn:lsid...'>ExistingObjectType</objectType>
+       <objectType lsid='urn:lsid...'>ExistingObjectType</objectType>
     </Relationship>
     <Relationship relationshipType="AnotherRelationshipTerm">
         ....
@@ -2983,12 +2984,12 @@
 
 		$response .= "<Relationship relationshipType='$relationship' lsid='$rellsid'>\n";
 		foreach my $lsid_article ( @lsids_articles ) {
-			my ($lsid, $articleName) = @$lsid_article;
-			# ugh... I have to cheat here because the term is not returned from the Ontology Server
-			# one day we may have to fix this...
-			$lsid =~ /urn\:lsid\:[^\:]+\:[^\:]+\:([^\:]+)/;  # get the term portion of the LSID
-			$term = $1;
-			$response .= "<${ontology}Type lsid='$lsid'>$term</${ontology}Type>\n";
+			my $lsid = $lsid_article->{lsid};
+			my $term = $lsid_article->{term};
+			my $articleName = $lsid_article->{articleName};
+			$response .= "<${ontology}Type lsid='$lsid' ";
+			$response .= "articleName='$articleName'" if $articleName;
+			$response .= ">$term</${ontology}Type>\n";
 		}
 		$response .= "</Relationship>\n";
 	}

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/OntologyServer.pm,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -r1.88 -r1.89
--- /home/repository/moby/moby-live/Perl/MOBY/OntologyServer.pm	2005/09/30 23:14:12	1.88
+++ /home/repository/moby/moby-live/Perl/MOBY/OntologyServer.pm	2005/11/23 20:58:36	1.89
@@ -223,6 +223,94 @@
 	}
 }
 
+=head2 objectInfo
+
+=cut
+
+sub objectInfo{
+	my ( $self, %args ) = @_;
+
+	$CONFIG ||= MOBY::Config->new;    # exported by Config.pm
+	my $adaptor = $CONFIG->getDataAdaptor( datasource => 'mobyobject' );
+
+	my $term = $args{term};
+	$term =~ s/^moby://;    # if the term is namespaced, then remove that
+	my $sth;
+	return ( 0, "WRONG ONTOLOGY!", '' ) unless ( $self->ontology eq 'object' );
+	return (0, undef, undef) unless $term;
+
+	my $result;
+	
+	$result = $adaptor->query_object(type => $term);
+	my $row = shift(@$result);
+	#my $lsid = $row->{object_lsid};
+	#my $type = $row->{object_type};
+	#my $desc = $row->{description};
+	#my $auth = $row->{authority};
+	#my $email = $row->{contact_email};
+	#
+	if ($row->{object_lsid})
+	{ # if it is in there, then it has been discovered regardless of being foreign or not
+		return $row;
+	} elsif ( _isForeignLSID($term) ) { # if not in our ontology, but is a foreign LSID, then pass it back verbatim
+		return {object_lsid => $term,
+			object_type => $term,
+			description => "LSID $term does not exist in the biomoby.org Object Class system\n",
+			authority => "",
+			contact_email => "",
+		       };
+	} else { # under all other circumstances (i.e. not a term, or a non-existent biomoby LSID) then fail
+		return {object_lsid => "",
+			object_type => "",
+			description => "LSID $term does not exist in the biomoby.org Object Class system\n",
+			authority => "",
+			contact_email => "",
+		       };
+	}
+}
+
+
+=head2 serviceInfo
+
+=cut
+
+sub serviceInfo{
+	my ( $self, %args ) = @_;
+
+	$CONFIG ||= MOBY::Config->new;    # exported by Config.pm
+	my $adaptor = $CONFIG->getDataAdaptor( datasource => 'mobyservice' );
+
+	my $term = $args{term};
+	$term =~ s/^moby://;    # if the term is namespaced, then remove that
+	my $sth;
+	return ( 0, "WRONG ONTOLOGY!", '' ) unless ( $self->ontology eq 'service' );
+	return (0, undef, undef) unless $term;
+
+	my $result;
+	
+	$result = $adaptor->query_service(type => $term);
+	my $row = shift(@$result);
+
+	if ($row->{service_lsid})
+	{ # if it is in there, then it has been discovered regardless of being foreign or not
+		return $row;
+	} elsif ( _isForeignLSID($term) ) { # if not in our ontology, but is a foreign LSID, then pass it back verbatim
+		return {service_lsid => $term,
+			service_type => $term,
+			description => "LSID $term does not exist in the biomoby.org Object Class system\n",
+			authority => "",
+			contact_email => "",
+		       };
+	} else { # under all other circumstances (i.e. not a term, or a non-existent biomoby LSID) then fail
+		return {service_lsid => "",
+			service_type => "",
+			description => "LSID $term does not exist in the biomoby.org Object Class system\n",
+			authority => "",
+			contact_email => "",
+		       };
+	}
+}
+
 sub _isMOBYLSID {
 	my ($lsid) = @_;
 	return 1 if $lsid =~ /^urn\:lsid\:biomoby.org/;
@@ -536,7 +624,7 @@
 	(@ISAlist = @{$relationships->{$isa}}) if ($relationships->{$isa}) ;
 	# for each of the inherited parents, check their articleNames
 	foreach my $ISA(@ISAlist){  # $ISA = [lsid, articleName] (but articleName shuld be null anyway in this case)
-		my $what_it_is = shift @$ISA;
+		my $what_it_is = $ISA->{lsid};
 		# check the hasa relationships for common articleName
 		$foundCommonArticleNameFlag += _compareArticleNames(OS => $OS, type => $what_it_is, relationship => $hasalsid, targetArticleName => $articleName);
 		# check the has relationships for common articleName		
@@ -564,7 +652,7 @@
 	       if ($contents->{$content}){
 			my @CONTENTlist = @{$contents->{$content}};
 			foreach my $CONTAINED(@CONTENTlist){
-				$foundCommonArticleNameFlag = 1 if ($CONTAINED->[1] eq $targetArticleName); #->[1] is the articleName field
+				$foundCommonArticleNameFlag = 1 if ($CONTAINED->{articleName} eq $targetArticleName); #->[1] is the articleName field
 			}
 	       }
 	}
@@ -1111,11 +1199,11 @@
 	return \%result;
 }
 
-=head2 Relationships
+=head2 RelationshipsDEPRECATED
 
 =cut
 
-sub Relationships {
+sub RelationshipsDEPRECATED {
 
 	# this entire subroutine assumes that there is NOT multiple parenting!!
 	my ( $self, %args ) = @_;
@@ -1167,6 +1255,69 @@
 	return \%results;    #results(relationship} = [[lsid1,articleNmae], [lsid2, articleName], [lsid3, articleName]]
 }
 
+
+=head2 Relationships
+
+=cut
+
+sub Relationships {
+
+	# this entire subroutine assumes that there is NOT multiple parenting!!
+	my ( $self, %args ) = @_;
+	my $ontology     = $args{ontology} ? $args{ontology} : $self->ontology;
+	my $term         = $args{term};
+	my $relationship = $args{relationship};
+	my $direction    = $args{direction} ? $args{direction} : 'root';
+	my $expand       = $args{expand} ? 1 : 0;
+	return
+	  unless (    $ontology
+			   && $term
+			   && ( ( $ontology eq 'service' ) || ( $ontology eq 'object' ) ) );
+
+	# convert $term into an LSID if it isn't already
+	if ( $ontology eq 'service' ) {
+		$term = $self->getServiceURI($term);
+		$relationship ||="isa";
+		my $OS = MOBY::OntologyServer->new(ontology => 'relationship');
+		$relationship = $OS->getRelationshipURI("service", $relationship);
+	} elsif ( $ontology eq 'object' ) {
+		$term = $self->getObjectURI($term);
+		$relationship ||="isa";
+		my $OS = MOBY::OntologyServer->new(ontology => 'relationship');
+		$relationship = $OS->getRelationshipURI("object", $relationship);
+	}
+	my %results;
+	while (    ( $term ne 'urn:lsid:biomoby.org:objectclass:Object' )
+			&& ( $term ne 'urn:lsid:biomoby.org:servicetype:Service' ) )
+	{
+		my $defs = $self->_doRelationshipsQuery(       $ontology,     $term,
+												 $relationship, $direction );
+		return {[]} unless $defs; # somethig has gone terribly wrong!
+		my $lsid;
+		my $rel;
+		my $articleName;
+		foreach ( @{$defs} ) {
+			$lsid = $_->[0];
+			$rel  = $_->[1];
+			$articleName = $_->[2];
+			$articleName ||="";
+			if ($ontology eq 'object'){
+				my $info = $self->objectInfo(term => $lsid);  # we need to get the term name, and that doesn't come from here
+				my $term = $info->{object_type};
+				push @{ $results{$rel} }, {lsid => $lsid, articleName => $articleName, term => $term};
+			} else {
+				my $info = $self->serviceInfo(term => $lsid);  # we need to get the term name, and that doesn't come from here
+				my $term = $info->{service_type};
+				push @{ $results{$rel} }, {lsid => $lsid, term => $term};
+			}
+		}
+		last unless ($expand);
+		last unless ( $direction eq "root" ); # if we aren't going to root, then be careful or we'll loop infnitely
+		$term = $lsid; # this entire subroutine assumes that there is NOT multiple parenting...
+	}
+	return \%results; 
+}
+
 sub _doRelationshipsQuery {
 	my ( $self, $ontology, $term, $relationship, $direction ) = @_;
 	$CONFIG ||= MOBY::Config->new;    # exported by Config.pm
@@ -1260,7 +1411,8 @@
 				#${$lsids}{relationshiptype}=[lsid, lsid, lsid];
 				foreach my $lsid_article ( @{ $lsids->{$relationship} } )
 				{                  # go through the related terms
-					my ($lsid, $article) = @{$lsid_article};
+					my $lsid = $lsid_article->{lsid},
+					my $article = $lsid_article->{articleName};
 					$debug && _LOG("found $lsid as relationship");
 					next
 					  if ( defined $IDS{$lsid} )




More information about the MOBY-guts mailing list