From d4eb231a35c23a5fdb36fd6220b5ab706e7528ba Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 14 Feb 2011 17:48:26 +0100 Subject: read from subjectcookie, fix read feature_type --- lib/feature.rb | 10 ++++++++-- lib/helper.rb | 3 +-- lib/model.rb | 22 +++++++++++++--------- lib/overwrite.rb | 2 +- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/feature.rb b/lib/feature.rb index be063dd..c0729a7 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -16,8 +16,14 @@ module OpenTox # provides domain (possible target values) of classification feature # @return [Array] list with possible target values def domain - #TODO derieve from metadata / ontology - return [true, false] + if metadata[OT.acceptValue] + raise "accept value found, remove hack and implement correctly" + else + if @uri=~/feature\/26221/ || @uri=~/feature\/221726/ + return ["mutagen" , "nonmutagen"] + end + return [true, false] + end end # provides feature type, possible types are "regression" or "classification" diff --git a/lib/helper.rb b/lib/helper.rb index 191b932..a1590d7 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -19,8 +19,6 @@ helpers do #Check Authorization for URI with method and subjectid. def authorized?(subjectid) - # hack for reports, address problem as soon as subjectid is not longer allowed as param - return true if request.env['REQUEST_URI'] =~ /validation\/report\/.*svg$/ request_method = request.env['REQUEST_METHOD'] uri = clean_uri("#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['REQUEST_URI']}") request_method = "GET" if request_method == "POST" && uri =~ /\/model\/\d+\/?$/ @@ -52,6 +50,7 @@ before do subjectid = session[:subjectid] if session[:subjectid] subjectid = params[:subjectid] if params[:subjectid] and !subjectid subjectid = request.env['HTTP_SUBJECTID'] if request.env['HTTP_SUBJECTID'] and !subjectid + subjectid = request.cookies["subjectid"] unless subjectid # see http://rack.rubyforge.org/doc/SPEC.html subjectid = CGI.unescape(subjectid) if subjectid.include?("%23") @subjectid = subjectid diff --git a/lib/model.rb b/lib/model.rb index 9622d65..74408d8 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -38,24 +38,28 @@ module OpenTox # provides feature type, possible types are "regression" or "classification" # @return [String] feature type, "unknown" if type could not be estimated def feature_type(subjectid=nil) + return @feature_type if @feature_type + # dynamically perform restcalls if necessary load_metadata(subjectid) if @metadata==nil or @metadata.size==0 or (@metadata.size==1 && @metadata.values[0]==@uri) - - @algorithm = OpenTox::Algorithm::Generic.find(@metadata[OT.algorithm], subjectid) unless @algorithm - algorithm_title = @algorithm ? @algorithm.metadata[DC.title] : nil - algorithm_type = @algorithm ? @algorithm.metadata[OT.isA] : nil - @dependentVariable = OpenTox::Feature.find( @metadata[OT.dependentVariables],subjectid ) unless @dependentVariable - type_indicators = [@dependentVariable.feature_type, @metadata[OT.isA], @metadata[DC.title], + algorithm = OpenTox::Algorithm::Generic.find(@metadata[OT.algorithm], subjectid) + algorithm_title = algorithm ? algorithm.metadata[DC.title] : nil + algorithm_type = algorithm ? algorithm.metadata[OT.isA] : nil + dependent_variable = OpenTox::Feature.find( @metadata[OT.dependentVariables],subjectid ) + dependent_variable_type = dependent_variable ? dependent_variable.feature_type : nil + type_indicators = [dependent_variable_type, @metadata[OT.isA], @metadata[DC.title], @uri, algorithm_type, algorithm_title] type_indicators.each do |type| case type when /(?i)classification/ - return "classification" + @feature_type = "classification" + break when /(?i)regression/ - return "regression" + @feature_type = "regression" end end - raise "unknown model "+type_indicators.inspect + raise "unknown model "+type_indicators.inspect unless @feature_type + @feature_type end end diff --git a/lib/overwrite.rb b/lib/overwrite.rb index 7b53122..29a2860 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -45,7 +45,7 @@ class Sinatra::Base response['Content-Type'] = "application/rdf+xml" halt code,task.to_rdfxml when /yaml/ - response['Content-Type'] = "application/rdf+xml" + response['Content-Type'] = "application/x-yaml" halt code,task.to_yaml # PENDING differs from task-webservice when /html/ response['Content-Type'] = "text/html" -- cgit v1.2.3