[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Mon Jul 9 19:54:31 UTC 2007


kawas
Mon Jul  9 15:54:31 EDT 2007
Update of /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies
In directory dev.open-bio.org:/tmp/cvs-serv31253/RDF/Ontologies

Modified Files:
	Objects.pm 
Log Message:
removed bnodes from RDF.
structure a little different than before...
BETA
moby-live/Perl/MOBY/RDF/Ontologies Objects.pm,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Objects.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Objects.pm	2007/07/05 17:38:26	1.1
+++ /home/repository/moby/moby-live/Perl/MOBY/RDF/Ontologies/Objects.pm	2007/07/09 19:54:31	1.2
@@ -73,6 +73,7 @@
 	# create an object
 	my $self = bless {}, ref($class) || $class;
 	$self->{uri}       = 'http://biomoby.org/RESOURCES/MOBY-S/Objects#';
+	$self->{uri_comp}       = 'http://biomoby.org/RESOURCES/MOBY_SUB_COMPONENT/Objects#';
 	$self->{query_all} = <<END;
 SELECT ot1.object_type, rt.relationship_type, ot2.object_type, rt.object2_articlename, ot1.description, ot1.object_lsid, ot1.authority, ot1.contact_email 
 FROM object as ot1, object_term2term as rt, object as ot2 
@@ -106,64 +107,16 @@
 =cut
 
 sub createAll {
-	my ($self, $hash) = @_;
+	my ( $self, $hash ) = @_;
 
 	# set up an RDF model
 	my $storage = new RDF::Core::Storage::Memory;
 	my $model   = new RDF::Core::Model( Storage => $storage );
 
 	my $prettyPrint = $hash->{prettyPrint} ? $hash->{prettyPrint} : 'yes';
-	
+
 	# add root of ontology
-	{
-		my $resource = new RDF::Core::Resource( $self->{uri}, "Object" );
-#		$model->addStmt(
-#			new RDF::Core::Statement(
-#				$resource,
-#				$resource->new( MOBY::RDF::Predicates::RDF->type ),
-#				new RDF::Core::Resource( MOBY::RDF::Predicates::OWL->Class )
-#			)
-#		);
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::RDFS->label ),
-				new RDF::Core::Literal("Object")
-			)
-		);
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::RDFS->comment ),
-				new RDF::Core::Literal(
-"a base object class consisting of a namespace and an identifier"
-				)
-			)
-		);
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::DC_PROTEGE->publisher ),
-				new RDF::Core::Literal("openinformatics.com")
-			)
-		);
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::DC_PROTEGE->identifier ),
-				new RDF::Core::Literal(
-"urn:lsid:biomoby.org:objectclass:Object:2001-09-21T16-00-00Z"
-				)
-			)
-		);
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::DC_PROTEGE->creator ),
-				new RDF::Core::Literal("jason\@openinformatics.com")
-			)
-		);
-	}
+	$self->_addOntologyRoot($model);
 
 	my $CONF = MOBY::Config->new;
 	my $adap = $CONF->getDataAdaptor( source => "mobyobject" );
@@ -181,15 +134,177 @@
 		my $lsid         = $$ref[5];
 		my $authority    = $$ref[6];
 		my $email        = $$ref[7];
-
+		
 		my $resource = new RDF::Core::Resource( $self->{uri}, $subject );
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::RDF->type ),
-				new RDF::Core::Resource( MOBY::RDF::Predicates::OWL->Class )
+		$self->_foo($model, $resource, $subject, $relationship, $object, $articlename, $description, $lsid, $authority, $email);
+
+	}
+	$sth->finish();
+	$db->disconnect();
+
+	my $xml        = '';
+	my $serializer = new RDF::Core::Model::Serializer(
+		Model   => $model,
+		Output  => \$xml,
+		BaseURI => 'URI://BASE/',
+	);
+	$serializer->serialize;
+	return new MOBY::RDF::Utils->prettyPrintXML( { xml => $xml } )
+	  unless $prettyPrint eq 'no';
+	return $xml;
+}
+
+=head2 createByName
+
+Return a string of RDF in XML that represents a specific datatype in the
+ Objects ontology. This sub routine takes one argument, 'term', 
+ that represents the ontology term that you would like to create RDF
+ for. For example, the term 'DNASequence' would return RDF describing
+ DNASequence and all of its parents and container relationships. 
+ 
+ This routine consumes a hash as input with keys:
+	term: the node to retrieve B<required>
+	prettyPrint: whether (yes) or not (no) to output 'pretty print' formatted XML. Defaults to 'yes'.
+
+=cut
+
+sub createByName {
+	my ( $self, $hash ) = @_;
+	die "No term specified!" unless $hash->{term};
+
+	# set up the term that we care about
+	my $term        = $hash->{term};
+	my $prettyPrint = $hash->{prettyPrint} ? $hash->{prettyPrint} : 'yes';
+
+	my $termExists = 0;
+
+	# set up an RDF model
+	my $storage = new RDF::Core::Storage::Memory;
+	my $model   = new RDF::Core::Model( Storage => $storage );
+
+	# add root of ontology
+	$self->_addOntologyRoot($model);
+	my $node_factory = new RDF::Core::NodeFactory();
+	
+	do {
+		my $CONF = MOBY::Config->new;
+		my $adap = $CONF->getDataAdaptor( source => "mobyobject" );
+		my $db   = $adap->dbh;
+		my $sth  = $db->prepare( $self->{query} );
+		$sth->execute( ($term) );
+
+# this line is here, because there are some datatypes in the ontology not rooted at 'Object' and while illegal, this would kill this code.
+		$term = '';
+
+		#base case
+		$term = '' if $term eq 'Object';
+
+		# returns an array of hash references
+		while ( my $ref = $sth->fetchrow_arrayref ) {
+			$termExists++;
+			my $subject      = $$ref[0];
+			my $relationship = $$ref[1];
+			my $object       = $$ref[2];
+			my $articlename  = $$ref[3] || '';
+			my $description  = $$ref[4];
+			my $lsid         = $$ref[5];
+			my $authority    = $$ref[6];
+			my $email        = $$ref[7];
+			my $resource = new RDF::Core::Resource( $self->{uri}, $subject );
+			$self->_foo($model, $resource, $subject, $relationship, $object, $articlename, $description, $lsid, $authority, $email);
+			do {
+				$term = $object;
+			} if $relationship =~ m/.*\:isa$/;
+
+		}
+		$sth->finish();
+		$db->disconnect();
+
+	} while ( $term && $term ne '' );
+	my $xml        = '';
+	my $serializer = new RDF::Core::Model::Serializer(
+		Model   => $model,
+		Output  => \$xml,
+		BaseURI => 'URI://BASE/',
+	);
+	$serializer->serialize;
+
+	# dont output anything unless term exists!
+	unless ( $termExists > 0 ) {
+		$xml = <<END;
+	<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>
+END
+	}
+	return new MOBY::RDF::Utils->prettyPrintXML( { xml => $xml } )
+	  unless $prettyPrint eq 'no';
+	return $xml;
+}
+
+sub _addOntologyRoot {
+	my ( $self, $model ) = @_;
+	my $resource = new RDF::Core::Resource( $self->{uri}, "Object" );
+
+	#		$model->addStmt(
+	#			new RDF::Core::Statement(
+	#				$resource,
+	#				$resource->new( MOBY::RDF::Predicates::RDF->type ),
+	#				new RDF::Core::Resource( MOBY::RDF::Predicates::OWL->Class )
+	#			)
+	#		);
+	$model->addStmt(
+		new RDF::Core::Statement(
+			$resource,
+			$resource->new( MOBY::RDF::Predicates::RDFS->label ),
+			new RDF::Core::Literal("Object")
+		)
+	);
+	$model->addStmt(
+		new RDF::Core::Statement(
+			$resource,
+			$resource->new( MOBY::RDF::Predicates::RDFS->comment ),
+			new RDF::Core::Literal(
+"a base object class consisting of a namespace and an identifier"
 			)
-		);
+		)
+	);
+	$model->addStmt(
+		new RDF::Core::Statement(
+			$resource,
+			$resource->new( MOBY::RDF::Predicates::DC_PROTEGE->publisher ),
+			new RDF::Core::Literal("openinformatics.com")
+		)
+	);
+	$model->addStmt(
+		new RDF::Core::Statement(
+			$resource,
+			$resource->new( MOBY::RDF::Predicates::DC_PROTEGE->identifier ),
+			new RDF::Core::Literal(
+				"urn:lsid:biomoby.org:objectclass:Object:2001-09-21T16-00-00Z"
+			)
+		)
+	);
+	$model->addStmt(
+		new RDF::Core::Statement(
+			$resource,
+			$resource->new( MOBY::RDF::Predicates::DC_PROTEGE->creator ),
+			new RDF::Core::Literal("jason\@openinformatics.com")
+		)
+	);
+
+}
+
+sub _foo {
+
+my ($self,$model, $resource, $subject, $relationship, $object, $articlename, $description, $lsid, $authority, $email) = @_;
+		
+
+		#		$model->addStmt(
+		#			new RDF::Core::Statement(
+		#				$resource,
+		#				$resource->new( MOBY::RDF::Predicates::RDF->type ),
+		#				new RDF::Core::Resource( MOBY::RDF::Predicates::OWL->Class )
+		#			)
+		#		);
 		$model->addStmt(
 			new RDF::Core::Statement(
 				$resource,
@@ -240,159 +355,73 @@
 
 		# add hasa container relationships
 		do {
-			my $bnode = new RDF::Core::NodeFactory()->newResource;
-			my $container = new RDF::Core::Resource( $self->{uri}, $object );
+			my $container = new RDF::Core::Resource( $self->{uri_comp}, $subject . "_" . $articlename );
+			$model->addStmt(
+				new RDF::Core::Statement(
+					$container, $container->new( MOBY::RDF::Predicates::RDF->type ),
+					new RDF::Core::Resource( $self->{uri}, $object )
+				)
+			);
 			$model->addStmt(
 				new RDF::Core::Statement(
 					$resource,
 					$resource->new(
 						MOBY::RDF::Predicates::MOBY_PREDICATES->hasa
 					),
-					$bnode
+					$container
 				)
 			);
 			$model->addStmt(
 				new RDF::Core::Statement(
-					$bnode,
-					$bnode->new(
+					$container,
+					$container->new(
 						MOBY::RDF::Predicates::MOBY_PREDICATES->articleName
 					),
-					new RDF::Core::Literal($object)
-				)
-			);
-			$model->addStmt(
-				new RDF::Core::Statement(
-					$bnode, $bnode->new( MOBY::RDF::Predicates::RDF->type ),
-					$container
+					new RDF::Core::Literal($articlename)
 				)
 			);
+			$self->_processISAs($model, $object);
+			
 		} if $relationship =~ m/.*\:hasa$/;
 
 		# add has container relationship
 		do {
-			my $bnode = new RDF::Core::NodeFactory()->newResource;
-			my $container = new RDF::Core::Resource( $self->{uri}, $object );
+			my $container = new RDF::Core::Resource( $self->{uri_comp}, $subject . "_" . $articlename );
+			$model->addStmt(
+				new RDF::Core::Statement(
+					$container, $container->new( MOBY::RDF::Predicates::RDF->type ),
+					new RDF::Core::Resource( $self->{uri}, $object )
+				)
+			);
+			
 			$model->addStmt(
 				new RDF::Core::Statement(
 					$resource,
 					$resource->new(
 						MOBY::RDF::Predicates::MOBY_PREDICATES->has
 					),
-					$bnode
+					$container
 				)
 			);
 			$model->addStmt(
 				new RDF::Core::Statement(
-					$bnode,
-					$bnode->new(
+					$container,
+					$container->new(
 						MOBY::RDF::Predicates::MOBY_PREDICATES->articleName
 					),
-					new RDF::Core::Literal($object)
-				)
-			);
-			$model->addStmt(
-				new RDF::Core::Statement(
-					$bnode, $bnode->new( MOBY::RDF::Predicates::RDF->type ),
-					$container
+					new RDF::Core::Literal($articlename)
 				)
 			);
+			$self->_processISAs($model, $object);
+			
 		} if $relationship =~ m/.*\:has$/;
-	}
-	$sth->finish();
-	$db->disconnect();
-
-	my $xml        = '';
-	my $serializer = new RDF::Core::Model::Serializer(
-		Model   => $model,
-		Output  => \$xml,
-		BaseURI => 'URI://BASE/',
-	);
-	$serializer->serialize;
-	return new MOBY::RDF::Utils->prettyPrintXML( { xml => $xml } ) unless $prettyPrint eq 'no';
-	return $xml;
 }
 
-=head2 createByName
-
-Return a string of RDF in XML that represents a specific datatype in the
- Objects ontology. This sub routine takes one argument, 'term', 
- that represents the ontology term that you would like to create RDF
- for. For example, the term 'DNASequence' would return RDF describing
- DNASequence and all of its parents and container relationships. 
- 
- This routine consumes a hash as input with keys:
-	term: the node to retrieve B<required>
-	prettyPrint: whether (yes) or not (no) to output 'pretty print' formatted XML. Defaults to 'yes'.
-
-=cut
+sub _processISAs {
+	my ( $self, $model, $term ) = @_;
 
-sub createByName {
-	my ( $self, $hash ) = @_;
-	die "No term specified!" unless $hash->{term};
-
-	# set up the term that we care about
-	my $term = $hash->{term};
-	my $prettyPrint = $hash->{prettyPrint} ? $hash->{prettyPrint} : 'yes';
-	
 	my $termExists = 0;
-
-	# set up an RDF model
-	my $storage = new RDF::Core::Storage::Memory;
-	my $model   = new RDF::Core::Model( Storage => $storage );
-
-	# add root of ontology
-	{
-		my $resource = new RDF::Core::Resource( $self->{uri}, "Object" );
-#		$model->addStmt(
-#			new RDF::Core::Statement(
-#				$resource,
-#				$resource->new( MOBY::RDF::Predicates::RDF->type ),
-#				new RDF::Core::Resource( MOBY::RDF::Predicates::OWL->Class )
-#			)
-#		);
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::RDFS->label ),
-				new RDF::Core::Literal("Object")
-			)
-		);
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::RDFS->comment ),
-				new RDF::Core::Literal(
-"a base object class consisting of a namespace and an identifier"
-				)
-			)
-		);
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::DC_PROTEGE->publisher ),
-				new RDF::Core::Literal("openinformatics.com")
-			)
-		);
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::DC_PROTEGE->identifier ),
-				new RDF::Core::Literal(
-"urn:lsid:biomoby.org:objectclass:Object:2001-09-21T16-00-00Z"
-				)
-			)
-		);
-		$model->addStmt(
-			new RDF::Core::Statement(
-				$resource,
-				$resource->new( MOBY::RDF::Predicates::DC_PROTEGE->creator ),
-				new RDF::Core::Literal("jason\@openinformatics.com")
-			)
-		);
-	}
-	my $node_factory = new RDF::Core::NodeFactory();
-
-	# add the datatype Object to the model
+		
 	do {
 		my $CONF = MOBY::Config->new;
 		my $adap = $CONF->getDataAdaptor( source => "mobyobject" );
@@ -417,155 +446,19 @@
 			my $lsid         = $$ref[5];
 			my $authority    = $$ref[6];
 			my $email        = $$ref[7];
-
 			my $resource = new RDF::Core::Resource( $self->{uri}, $subject );
-#			$model->addStmt(
-#				new RDF::Core::Statement(
-#					$resource,
-#					$resource->new( MOBY::RDF::Predicates::RDF->type ),
-#					new RDF::Core::Resource( MOBY::RDF::Predicates::OWL->Class )
-#				)
-#			);
-			$model->addStmt(
-				new RDF::Core::Statement(
-					$resource,
-					$resource->new( MOBY::RDF::Predicates::RDFS->label ),
-					new RDF::Core::Literal($subject)
-				)
-			);
-			$model->addStmt(
-				new RDF::Core::Statement(
-					$resource,
-					$resource->new( MOBY::RDF::Predicates::RDFS->comment ),
-					new RDF::Core::Literal($description)
-				)
-			);
-			$model->addStmt(
-				new RDF::Core::Statement(
-					$resource,
-					$resource->new(
-						MOBY::RDF::Predicates::DC_PROTEGE->publisher
-					),
-					new RDF::Core::Literal($authority)
-				)
-			);
-			$model->addStmt(
-				new RDF::Core::Statement(
-					$resource,
-					$resource->new(
-						MOBY::RDF::Predicates::DC_PROTEGE->identifier
-					),
-					new RDF::Core::Literal($lsid)
-				)
-			);
-			$model->addStmt(
-				new RDF::Core::Statement(
-					$resource,
-					$resource->new(
-						MOBY::RDF::Predicates::DC_PROTEGE->creator
-					),
-					new RDF::Core::Literal($email)
-				)
-			);
-
-			# add subclassof, if applicable
+			$self->_foo($model, $resource, $subject, $relationship, $object, $articlename, $description, $lsid, $authority, $email);
 			do {
-				my $parent = new RDF::Core::Resource( $self->{uri}, $object );
-				$model->addStmt(
-					new RDF::Core::Statement(
-						$resource,
-						$resource->new(
-							MOBY::RDF::Predicates::RDFS->subClassOf
-						),
-						$parent
-					)
-				);
 				$term = $object;
 			} if $relationship =~ m/.*\:isa$/;
 
-			# add hasa container relationships
-			do {
-				my $bnode     = $node_factory->newResource;
-				my $container =
-				  new RDF::Core::Resource( $self->{uri}, $object );
-				$model->addStmt(
-					new RDF::Core::Statement(
-						$resource,
-						$resource->new(
-							MOBY::RDF::Predicates::MOBY_PREDICATES->hasa
-						),
-						$bnode
-					)
-				);
-				$model->addStmt(
-					new RDF::Core::Statement(
-						$bnode,
-						$bnode->new(
-							MOBY::RDF::Predicates::MOBY_PREDICATES->articleName
-						),
-						new RDF::Core::Literal($articlename)
-					)
-				);
-				$model->addStmt(
-					new RDF::Core::Statement(
-						$bnode, $bnode->new( MOBY::RDF::Predicates::RDF->type ),
-						$container
-					)
-				);
-			} if $relationship =~ m/.*\:hasa$/;
-
-			# add has container relationship
-			do {
-				my $bnode     = $node_factory->newResource;
-				my $container =
-				  new RDF::Core::Resource( $self->{uri}, $object );
-				$model->addStmt(
-					new RDF::Core::Statement(
-						$resource,
-						$resource->new(
-							MOBY::RDF::Predicates::MOBY_PREDICATES->has
-						),
-						$bnode
-					)
-				);
-				$model->addStmt(
-					new RDF::Core::Statement(
-						$bnode,
-						$bnode->new(
-							MOBY::RDF::Predicates::MOBY_PREDICATES->articleName
-						),
-						new RDF::Core::Literal($articlename)
-					)
-				);
-				$model->addStmt(
-					new RDF::Core::Statement(
-						$bnode, $bnode->new( MOBY::RDF::Predicates::RDF->type ),
-						$container
-					)
-				);
-			} if $relationship =~ m/.*\:has$/;
-
 		}
 		$sth->finish();
 		$db->disconnect();
 
 	} while ( $term && $term ne '' );
-	my $xml        = '';
-	my $serializer = new RDF::Core::Model::Serializer(
-		Model   => $model,
-		Output  => \$xml,
-		BaseURI => 'URI://BASE/',
-	);
-	$serializer->serialize;
-	# dont output anything unless term exists!
-	unless ( $termExists > 0 ) {
-		$xml = <<END;
-	<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>
-END
-	}
-	return new MOBY::RDF::Utils->prettyPrintXML( { xml => $xml } ) unless $prettyPrint eq 'no';
-	return $xml;
 }
 
+
 1;
 __END__




More information about the MOBY-guts mailing list