[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Thu Nov 29 17:52:40 UTC 2007


kawas
Thu Nov 29 12:52:40 EST 2007
Update of /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies
In directory dev.open-bio.org:/tmp/cvs-serv31379/RDF/Ontologies

Modified Files:
	Objects.pm Namespaces.pm Services.pm ServiceTypes.pm 
Log Message:
*modified the db access code (connections are now created and destroyed as needed, rather than trying to maintain a single connection)
*modified how URIs are obtained and used when creating RDF


moby-live/Perl/MOBY/RDF/Ontologies Objects.pm,1.4,1.5 Namespaces.pm,1.3,1.4 Services.pm,1.6,1.7 ServiceTypes.pm,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Objects.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Objects.pm	2007/07/19 18:26:59	1.4
+++ /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Objects.pm	2007/11/29 17:52:40	1.5
@@ -78,7 +78,6 @@
     my $CONF  = MOBY::Config->new;
 	$self->{uri}       = $CONF->{mobyobject}->{resourceURL} || 'http://biomoby.org/RESOURCES/MOBY-S/Objects#';
 	$self->{uri} = $self->{uri} . "#" unless $self->{uri} =~ m/^.*(\#{1})$/;
-	$self->{moby_data_handler} = $CONF-> getDataAdaptor( source => "mobyobject" )->dbh;
 	
 	$self->{uri_comp} = $self->{uri};
 	$self->{uri_comp} =~ s/\/MOBY\-S\//\/MOBY_SUB_COMPONENT\//;
@@ -127,7 +126,7 @@
 	# add root of ontology
 	$self->_addOntologyRoot($model);
 
-	my $db = $self->{moby_data_handler};
+	my $db = MOBY::Config->new()-> getDataAdaptor( source => "mobyobject" )->dbh;
 	my $sth  = $db->prepare( $self->{query_all} );
 	$sth->execute;
 
@@ -152,7 +151,6 @@
 	}
 	$sth->finish();
 	$db->disconnect();
-
 	my $xml        = '';
 	my $serializer = new RDF::Core::Model::Serializer(
 		Model   => $model,
@@ -198,7 +196,7 @@
 	my $node_factory = new RDF::Core::NodeFactory();
 
 	do {
-		my $db = $self->{moby_data_handler};
+		my $db = MOBY::Config->new()-> getDataAdaptor( source => "mobyobject" )->dbh;
 		my $sth  = $db->prepare( $self->{query} );
 		$sth->execute( ($term) );
 
@@ -443,9 +441,10 @@
 	my ( $self, $model, $term ) = @_;
 
 	my $termExists = 0;
-
+	
+	
 	do {
-		my $db = $self->{moby_data_handler};
+		my $db = MOBY::Config->new()-> getDataAdaptor( source => "mobyobject" )->dbh;
 		my $sth  = $db->prepare( $self->{query} );
 		$sth->execute( ($term) );
 

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Namespaces.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Namespaces.pm	2007/07/19 18:26:59	1.3
+++ /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Namespaces.pm	2007/11/29 17:52:40	1.4
@@ -76,7 +76,6 @@
     my $CONF  = MOBY::Config->new;
 	$self->{uri}       = $CONF->{mobynamespace}->{resourceURL} || 'http://biomoby.org/RESOURCES/MOBY-S/Namespaces#';
 	$self->{uri} = $self->{uri} . "#" unless $self->{uri} =~ m/^.*(\#{1})$/;
-	$self->{moby_data_handler} = $CONF-> getDataAdaptor( source => "mobynamespace" )->dbh;
 
 	$self->{query_all} = <<END;
 SELECT namespace_type, description, namespace_lsid, authority, contact_email FROM namespace ORDER BY namespace_type asc
@@ -158,7 +157,7 @@
 		);
 	}
 
-	my $db = $self->{moby_data_handler};
+	my $db = MOBY::Config->new()-> getDataAdaptor( source => "mobynamespace" )->dbh;
 	my $sth  = $db->prepare( $self->{query_all} );
 	$sth->execute;
 
@@ -306,7 +305,7 @@
 	my $node_factory = new RDF::Core::NodeFactory();
 
 	do {
-		my $db = $self->{moby_data_handler};
+		my $db = MOBY::Config->new()-> getDataAdaptor( source => "mobynamespace" )->dbh;
 		my $sth  = $db->prepare( $self->{query} );
 		$sth->execute( ($term) );
 

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Services.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Services.pm	2007/11/28 20:01:23	1.6
+++ /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Services.pm	2007/11/29 17:52:40	1.7
@@ -81,6 +81,18 @@
 #-----------------------------------------------------------------
 # new
 #-----------------------------------------------------------------
+
+=head2 new
+
+Instantiate a Services object.
+
+Parameters: 
+	* A Hash with keys:
+		-> endpoint		=> the BioMOBY registry endpoint to use <optional>
+		-> namespace	=> the BioMOBY registry namespace to use <optional>
+
+=cut
+
 sub new {
 	my ( $class, %args ) = @_;
 
@@ -89,16 +101,64 @@
 
 	# save some information retrieved from mobycentral.config
 	my $CONF = MOBY::Config->new;
-	$self->{uri} = $CONF->{mobycentral}->{resourceURL}
-	  || 'http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances#' unless (defined $args{uri} and $args{uri});
+
+	# FIXME get me from api call
+	$self->{instance_uri}  = $CONF->{mobycentral}->{resourceURL}   || '';
+	$self->{service_uri}   = $CONF->{mobyservice}->{resourceURL}   || '';
+	$self->{datatype_uri}  = $CONF->{mobyobject}->{resourceURL}    || '';
+	$self->{namespace_uri} = $CONF->{mobynamespace}->{resourceURL} || '';
 
 	# save the endpoint/namespace/uri if passed in
 	$self->{endpoint}  = $args{endpoint} if $args{endpoint};
 	$self->{namespace} = $args{endpoint} if $args{namespace};
-	$self->{uri}       = $args{uri}      if $args{uri} and defined $args{uri};         
 
-	# add a # at the end of the uri if it isnt there already
-	$self->{uri} = $self->{uri} . "#" unless $self->{uri} =~ m/^.*(\#{1})$/;
+	unless ( $self->{instance_uri} ) {
+		my $moby = MOBY::Client::Central->new(
+					 Registries => {
+						 mobycentral => {
+							 URL => $self->{endpoint},
+							 URI => 'http://mobycentral.cbr.nrc.ca/MOBY/Central'
+						 }
+					 }
+		  )
+		  if $self->{endpoint};
+
+		# otherwise use default one
+		$moby = MOBY::Client::Central->new() unless $self->{endpoint};
+
+		# moby is a hash ref now
+		$moby = $moby->retrieveResourceURLs();
+
+		# add all uris
+		$self->{instance_uri} = $moby->{ServiceInstance}->[0]
+		  if $moby->{ServiceInstance}->[0];
+		$self->{service_uri} = $moby->{Services}->[0] if $moby->{Services}->[0];
+		$self->{namespace_uri} = $moby->{Namespaces}->[0]
+		  if $moby->{Namespaces}->[0];
+		$self->{datatype_uri} = $moby->{Objects}->[0] if $moby->{Objects}->[0];
+
+		#revert to a default value if nothing is retrieved
+		$self->{instance_uri} =
+		  'http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances#'
+		  unless $moby->{ServiceInstance}->[0];
+		$self->{service_uri} = 'http://biomoby.org/RESOURCES/MOBY-S/Services#'
+		  unless $moby->{Services}->[0];
+		$self->{namespace_uri} =
+		  'http://biomoby.org/RESOURCES/MOBY-S/Namespaces#'
+		  unless $moby->{Namespaces}->[0];
+		$self->{datatype_uri} = 'http://biomoby.org/RESOURCES/MOBY-S/Objects#'
+		  unless $moby->{Objects}->[0];
+	}
+
+	# add a / at the end of the uri if it isnt there already
+	$self->{instance_uri} = $self->{instance_uri} . "#"
+	  unless $self->{instance_uri} =~ m/^.*(\#{1})$/;
+	$self->{service_uri} = $self->{service_uri} . "#"
+	  unless $self->{service_uri} =~ m/^.*(\#{1})$/;
+	$self->{namespace_uri} = $self->{namespace_uri} . "#"
+	  unless $self->{namespace_uri} =~ m/^.*(\#{1})$/;
+	$self->{datatype_uri} = $self->{datatype_uri} . "#"
+	  unless $self->{datatype_uri} =~ m/^.*(\#{1})$/;    
 
 	$self->{is_alive_path} = $CONF->{mobycentral}->{service_tester_path};
 
@@ -184,7 +244,7 @@
 
 	foreach my $SI (@$services) {
 		my $resource =
-		  new RDF::Core::Resource( $self->{uri},
+		  new RDF::Core::Resource( $self->{instance_uri},
 								   $SI->authority . "," . $SI->name );
 		$model->addStmt(
 						 new RDF::Core::Statement(
@@ -367,7 +427,7 @@
 				 $bnode,
 				 $resource->new( MOBY::RDF::Predicates::RDF->type ),
 				 new RDF::Core::Resource(
-					 "http://biomoby.org/RESOURCES/MOBY-S/Services#" . $SI->type
+					 $self->{service_uri} . $SI->type
 				 )
 			 )
 		);
@@ -419,7 +479,7 @@
 						$oType,
 						$resource->new( MOBY::RDF::Predicates::RDF->type ),
 						new RDF::Core::Resource(
-								  "http://biomoby.org/RESOURCES/MOBY-S/Objects#"
+								  $self->{datatype_uri}
 									. $_->objectType
 						  )    #TODO check for lsid
 					)
@@ -470,7 +530,7 @@
 							$inNamespaces,
 							$resource->new( MOBY::RDF::Predicates::RDF->type ),
 							new RDF::Core::Resource(
-"http://biomoby.org/RESOURCES/MOBY-S/Namespaces#"
+							$self->{namespace_uri}
 								  . $n
 							  )    #TODO check for lsids
 						)
@@ -534,7 +594,7 @@
 							$oType,
 							$resource->new( MOBY::RDF::Predicates::RDF->type ),
 							new RDF::Core::Resource(
-								  "http://biomoby.org/RESOURCES/MOBY-S/Objects#"
+								  $self->{datatype_uri}
 									. $simp->objectType
 							  )    #TODO check for lsid
 						)
@@ -570,7 +630,7 @@
 												MOBY::RDF::Predicates::RDF->type
 								),
 								new RDF::Core::Resource(
-"http://biomoby.org/RESOURCES/MOBY-S/Namespaces#"
+								$self->{namespace_uri}
 									  . $n
 								  )    #TODO check for lsids
 							)
@@ -738,7 +798,7 @@
 						$oType,
 						$resource->new( MOBY::RDF::Predicates::RDF->type ),
 						new RDF::Core::Resource(
-								  "http://biomoby.org/RESOURCES/MOBY-S/Objects#"
+								  $self->{datatype_uri}
 									. $_->objectType
 						  )    #TODO check for lsid
 					)
@@ -789,7 +849,7 @@
 							$inNamespaces,
 							$resource->new( MOBY::RDF::Predicates::RDF->type ),
 							new RDF::Core::Resource(
-"http://biomoby.org/RESOURCES/MOBY-S/Namespaces#"
+							$self->{namespace_uri}
 								  . $n
 							  )    #TODO check for lsids
 						)
@@ -853,7 +913,7 @@
 							$oType,
 							$resource->new( MOBY::RDF::Predicates::RDF->type ),
 							new RDF::Core::Resource(
-								  "http://biomoby.org/RESOURCES/MOBY-S/Objects#"
+								  $self->{datatype_uri}
 									. $simp->objectType
 							  )    #TODO check for lsid
 						)
@@ -889,7 +949,7 @@
 												MOBY::RDF::Predicates::RDF->type
 								),
 								new RDF::Core::Resource(
-"http://biomoby.org/RESOURCES/MOBY-S/Namespaces#"
+									$self->{namespace_uri}
 									  . $n
 								  )    #TODO check for lsids
 							)

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/ServiceTypes.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/ServiceTypes.pm	2007/07/19 18:26:59	1.2
+++ /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/ServiceTypes.pm	2007/11/29 17:52:40	1.3
@@ -77,7 +77,6 @@
     my $CONF  = MOBY::Config->new;
 	$self->{uri}       = $CONF->{mobyservice}->{resourceURL} || 'http://biomoby.org/RESOURCES/MOBY-S/Services#';
 	$self->{uri} = $self->{uri} . "#" unless $self->{uri} =~ m/^.*(\#{1})$/;
-	$self->{moby_data_handler} = $CONF-> getDataAdaptor( source => "mobyservice" )->dbh;
 	
 	$self->{query_all} = <<END;
 SELECT ot1.service_type, rt.relationship_type, ot2.service_type, ot1.description, ot1.service_lsid, ot1.authority, ot1.contact_email, ot2.service_lsid 
@@ -163,7 +162,7 @@
 		);
 	}
 
-	my $db = $self->{moby_data_handler};
+	my $db = MOBY::Config->new()-> getDataAdaptor( source => "mobyservice" )->dbh;
 	my $sth  = $db->prepare( $self->{query_all} );
 	$sth->execute;
 
@@ -313,7 +312,7 @@
 
 	# add the datatype Object to the model
 	do {
-		my $db = $self->{moby_data_handler};
+		my $db = MOBY::Config->new()-> getDataAdaptor( source => "mobyservice" )->dbh;
 		my $sth  = $db->prepare( $self->{query} );
 		$sth->execute( ($term) );
 




More information about the MOBY-guts mailing list