summaryrefslogtreecommitdiff
path: root/lib/dataset.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2010-03-10 19:17:46 +0100
committerChristoph Helma <helma@in-silico.de>2010-03-10 19:17:46 +0100
commite1cb8e39ca0331ea2db7e633c3bc708aa691b0b3 (patch)
tree7cc0efea1b83c1455b375ac57d800f385d284237 /lib/dataset.rb
parent711234e3f7926231550e9f05cf35921b54056a06 (diff)
owl-dl (temporarily) removed, switched to YAML representation
Diffstat (limited to 'lib/dataset.rb')
-rw-r--r--lib/dataset.rb79
1 files changed, 41 insertions, 38 deletions
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