From e1cb8e39ca0331ea2db7e633c3bc708aa691b0b3 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 10 Mar 2010 19:17:46 +0100 Subject: owl-dl (temporarily) removed, switched to YAML representation --- lib/dataset.rb | 79 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 38 deletions(-) (limited to 'lib/dataset.rb') diff --git a/lib/dataset.rb b/lib/dataset.rb index b5b2e06..5caaa2c 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -3,12 +3,47 @@ LOGGER.progname = File.expand_path(__FILE__) module OpenTox class Dataset - include Owl + #include Owl + + attr_accessor :uri, :title, :source, :identifier, :data, :features, :compounds def initialize - super + @data = {} + @features = [] + @compounds = [] + #super + end + + def self.find(uri) + #dataset = Dataset.new + LOGGER.debug "Getting data from #{uri}" + YAML.load RestClient.get(uri, :accept => 'application/x-yaml').to_s # unclear why this does not work for complex uris, Dataset.find works from irb + #data = `curl "#{uri}"` + #LOGGER.debug data + #dataset.rdf = data + #dataset + end + + + def save + LOGGER.debug "Saving dataset" + @features.uniq! + @compounds.uniq! + #task_uri = RestClient.post(@@config[:services]["opentox-dataset"], self.rdf, :content_type => "application/rdf+xml").to_s + task_uri = RestClient::Resource.new(@@config[:services]["opentox-dataset"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0]).post(self.to_yaml, :content_type => "application/x-yaml").chomp.to_s + task = OpenTox::Task.find(task_uri) + LOGGER.debug "Waiting for task #{task_uri}" + task.wait_for_completion + LOGGER.debug "Dataset task #{task_uri} completed" + if task.failed? + LOGGER.error "Saving dataset failed" + task.failed + exit + end + task.resource end +=begin # create/add to entry from uris or Redland::Resources def add(compound,feature,value) compound = self.find_or_create_compound compound unless compound.class == Redland::Resource @@ -87,17 +122,7 @@ module OpenTox resource = RestClient::Resource.new(@@config[:services]["opentox-dataset"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0]) uri = resource.post data, :content_type => content_type dataset = Dataset.new - dataset.read uri.to_s - dataset - end - - def self.find(uri) - dataset = Dataset.new - LOGGER.debug "Getting data from #{uri}" - data = `curl "#{uri}"` - #LOGGER.debug data - #data = RestClient.get(uri, :accept => 'application/rdf+xml') # unclear why this does not work for complex uris, Dataset.find works from irb - dataset.rdf = data + dataset.read uri.chomp.to_s dataset end @@ -165,35 +190,13 @@ module OpenTox resource.delete end - def save - LOGGER.debug "Saving dataset" - #task_uri = RestClient.post(@@config[:services]["opentox-dataset"], self.rdf, :content_type => "application/rdf+xml").to_s - task_uri = RestClient::Resource.new(@@config[:services]["opentox-dataset"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0]).post(self.rdf, :content_type => "application/rdf+xml").to_s - task = OpenTox::Task.find(task_uri) - LOGGER.debug "Waiting for task #{task_uri}" - task.wait_for_completion - LOGGER.debug "Dataset task #{task_uri} completed" - if task.failed? - LOGGER.error "Saving dataset failed" - task.failed - exit - end - task.resource + def to_owl end - def to_yaml - { - :uri => self.uri, - :opentox_class => self.owl_class, - :title => self.title, - :source => self.source, - :identifier => self.identifier, - :compounds => self.compounds.collect{|c| c.to_s.to_s.sub(/^\[(.*)\]$/,'\1')}, - :features => self.features.collect{|f| f.to_s }, - :data => self.data - }.to_yaml + def from_owl end +=end end end -- cgit v1.2.3