diff options
author | mguetlein <martin.guetlein@gmail.com> | 2010-05-06 11:32:05 +0200 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2010-05-06 11:32:05 +0200 |
commit | 9e356d0d94ea4fe210ea7cefce5d4c1179cb63cd (patch) | |
tree | 486bd97d9e968c56c755dfa69331a8cabc70895f /lib/model.rb | |
parent | 8439bb9b337bded4a54018c03500a15082bce6b0 (diff) |
major change: using literal datatypes in owl
Diffstat (limited to 'lib/model.rb')
-rw-r--r-- | lib/model.rb | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/lib/model.rb b/lib/model.rb index dfd5886..684873b 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -3,13 +3,22 @@ module OpenTox class Generic - attr_accessor :uri, :title, :creator, :date, :format, :predictedVariables, :independentVariables, :dependentVariables, :trainingDataset, :feature_dataset_uri, :effects, :activities, :p_values, :fingerprints, :features, :algorithm + MODEL_ATTRIBS = [:uri, :title, :creator, :date, :format, :predictedVariables, :independentVariables, :dependentVariables, :trainingDataset, :algorithm] + MODEL_ATTRIBS.each{ |a| attr_accessor(a) } def self.find(uri) owl = OpenTox::Owl.from_uri(uri, "Model") return self.new(owl) end + def self.to_rdf(model) + owl = OpenTox::Owl.create 'Model', model.uri + (MODEL_ATTRIBS - [:uri]).each do |a| + owl.set(a.to_s,model.send(a.to_s)) + end + owl.rdf + end + protected def initialize(owl) [:date, :creator, :title, :format, :algorithm, :dependentVariables, @@ -17,9 +26,17 @@ module OpenTox self.send("#{a.to_s}=".to_sym, owl.get(a.to_s)) end @uri = owl.uri - RestClientWrapper.raise_uri_error "invalid model:\n"+ - self.to_yaml+"\n",@uri.to_s unless (Utils.is_uri?(@uri) and - @dependentVariables and @independentVariables and @predictedVariables) if ENV['RACK_ENV'] =~ /test|debug/ + if ENV['RACK_ENV'] =~ /test|debug/ + begin + raise "uri invalid" unless Utils.is_uri?(@uri) + raise "no algorithm" unless @algorithm and @algorithm.size>0 + raise "no dependent variables" unless @dependentVariables and @dependentVariables.size>0 + raise "no indenpendent variables" unless @independentVariables + raise "no predicted variables" unless @predictedVariables and @predictedVariables.size>0 + rescue => ex + RestClientWrapper.raise_uri_error "invalid model: '"+ex.message+"'\n"+self.to_yaml+"\n",@uri.to_s + end + end end end @@ -35,6 +52,7 @@ module OpenTox LOGGER.debug "Build model, algorithm_uri:"+algorithm_uri.to_s+", algorithm_parms: "+algorithm_params.inspect.to_s uri = OpenTox::RestClientWrapper.post(algorithm_uri,algorithm_params).to_s + LOGGER.debug "Build model done: "+uri.to_s RestClientWrapper.raise_uri_error("Invalid build model result: '"+uri.to_s+"'", algorithm_uri, algorithm_params ) unless Utils.model_uri?(uri) return PredictionModel.find(uri) end @@ -57,6 +75,8 @@ module OpenTox return false elsif @uri =~/ambit2/ and @title =~ /pKa/ return false + elsif @uri =~/majority/ + return @uri =~ /class/ else raise "unknown model, uri:'"+@uri.to_s+"' title:'"+@title.to_s+"'" end @@ -65,7 +85,9 @@ module OpenTox class Lazar < Generic - + + attr_accessor :feature_dataset_uri, :effects, :activities, :p_values, :fingerprints, :features + def initialize @source = "http://github.com/helma/opentox-model" @algorithm = File.join(@@config[:services]["opentox-algorithm"],"lazar") @@ -80,11 +102,11 @@ module OpenTox def save @features.uniq! resource = RestClient::Resource.new(@@config[:services]["opentox-model"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0]) - resource.post(self.to_yaml, :content_type => "application/x-yaml").chomp.to_s + resource.post(self.to_yaml, :content_type => "text/x-yaml").chomp.to_s end def self.find_all - RestClient.get(@@config[:services]["opentox-model"]).chomp.split("\n") + RestClientWrapper.get(@@config[:services]["opentox-model"]).chomp.split("\n") end =begin @@ -101,7 +123,7 @@ module OpenTox def self.create(data) resource = RestClient::Resource.new(@@config[:services]["opentox-model"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0]) - resource.post(data, :content_type => "application/x-yaml").chomp.to_s + resource.post(data, :content_type => "text/x-yaml").chomp.to_s end def delete @@ -116,7 +138,7 @@ module OpenTox # end # def yaml=(data) -# RestClient.put(@@uri, data, :content_type => "application/x-yaml").to_s +# RestClient.put(@@uri, data, :content_type => "text/x-yaml").to_s # end def endpoint |