summaryrefslogtreecommitdiff
path: root/lib/dataset.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2010-05-07 15:36:40 +0200
committerChristoph Helma <helma@in-silico.ch>2010-05-07 15:36:40 +0200
commitd32c70ba0ccbd4b32a972258683c190f48fdbe07 (patch)
treea00cc32e79674de404df297ebf503b18a401754f /lib/dataset.rb
parentd262dbc79c9f5d8e2d74647df52a9c44e1af511d (diff)
parent2911ebe2c818a33513d263654f3a0c609e631404 (diff)
Initial changes from Martin merged
Diffstat (limited to 'lib/dataset.rb')
-rw-r--r--lib/dataset.rb27
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb
index 3cfe639..9304eec 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -12,13 +12,21 @@ module OpenTox
@compounds = []
end
- def self.find(uri)
+ def self.find(uri, accept_header=nil)
- #if uri.match(/webservices.in-silico.ch|localhost|ot.dataset.de|opentox.informatik.uni-freiburg.de/) # try to get YAML first
- d = YAML.load RestClientWrapper.get(uri.to_s.strip, :accept => 'application/x-yaml').to_s
+ unless accept_header
+ if uri.match(@@config[:services]["opentox-dataset"]) || uri=~ /188.40.32.88/
+ accept_header = 'text/x-yaml'
+ else
+ accept_header = "application/rdf+xml"
+ end
+ end
+
+ case accept_header
+ when "text/x-yaml"
+ d = YAML.load RestClientWrapper.get(uri.to_s.strip, :accept => 'text/x-yaml').to_s
d.uri = uri unless d.uri
-=begin
- else # get default rdf+xml
+ when "application/rdf+xml"
owl = OpenTox::Owl.from_uri(uri.to_s.strip, "Dataset")
d = Dataset.new
@@ -33,8 +41,9 @@ module OpenTox
d.compounds.uniq!
d.features.uniq!
+ else
+ raise "cannot get datset with accept header: "+accept_header.to_s
end
-=end
return d
end
@@ -42,6 +51,8 @@ module OpenTox
# returns uri of new dataset
def create_new_dataset( new_compounds, new_features, new_title, new_creator )
+ raise "no new compounds selected" unless new_compounds and new_compounds.size>0
+
# load require features
if ((defined? @dirty_features) && (@dirty_features - new_features).size > 0)
(@dirty_features - new_features).each{|f| load_feature_values(f)}
@@ -53,7 +64,7 @@ module OpenTox
dataset.features = new_features
dataset.compounds = new_compounds
- # Ccopy dataset data for compounds and features
+ # Copy dataset data for compounds and features
# PENDING: why storing feature values in an array?
new_compounds.each do |c|
data_c = []
@@ -161,7 +172,7 @@ module OpenTox
@features.uniq!
@compounds.uniq!
- 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
+ OpenTox::RestClientWrapper.post(@@config[:services]["opentox-dataset"],{:content_type => "text/x-yaml"},self.to_yaml).strip
end
=begin