From 0b64779ad95c7db741ef68a36a58b1fa3f7f5cac Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 16 May 2011 14:50:55 +0000 Subject: typo in error message Model not found fixed --- application.rb | 2 +- lazar.rb | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/application.rb b/application.rb index 866a267..ba3c1a1 100644 --- a/application.rb +++ b/application.rb @@ -22,7 +22,7 @@ before do @uri = uri @id @yaml_file = "public/#{@id}.yaml" - halt 404, "Dataset #{@id} not found." unless File.exists? @yaml_file + halt 404, "Model #{@id} not found." unless File.exists? @yaml_file end # make sure subjectid is not included in params, subjectid is set as member variable diff --git a/lazar.rb b/lazar.rb index 9c76bbb..617ec73 100644 --- a/lazar.rb +++ b/lazar.rb @@ -68,13 +68,17 @@ post '/:id/?' do if compound_uri cache = PredictionCache.find(:model_uri => @lazar.uri, :compound_uri => compound_uri).first return cache.dataset_uri if cache and uri_available?(cache.dataset_uri) - begin - prediction_uri = @lazar.predict(compound_uri,true,@subjectid).uri - PredictionCache.create(:model_uri => @lazar.uri, :compound_uri => compound_uri, :dataset_uri => prediction_uri) - prediction_uri - rescue - LOGGER.error "Lazar prediction failed for #{compound_uri} with #{$!} " - halt 500, "Prediction of #{compound_uri} with #{@lazar.uri} failed." + if cache and uri_available?(cache.dataset_uri) + return cache.dataset_uri + else + begin + prediction_uri = @lazar.predict(compound_uri,true,@subjectid).uri + PredictionCache.create(:model_uri => @lazar.uri, :compound_uri => compound_uri, :dataset_uri => prediction_uri) + prediction_uri + rescue + LOGGER.error "Lazar prediction failed for #{compound_uri} with #{$!} " + halt 500, "Prediction of #{compound_uri} with #{@lazar.uri} failed." + end end elsif dataset_uri task = OpenTox::Task.create("Predict dataset",url_for("/#{@lazar.id}", :full)) do |task| -- cgit v1.2.3 From a3d2867681dd728fdf88039b9b29ca6d5d8a7097 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 23 May 2011 14:09:52 +0000 Subject: owl-dl fixed for model and prediction datasets --- lazar.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lazar.rb b/lazar.rb index d297ccf..7a1494a 100644 --- a/lazar.rb +++ b/lazar.rb @@ -7,7 +7,8 @@ get '/:id/?' do case @accept when /application\/rdf\+xml/ s = OpenTox::Serializer::Owl.new - s.add_model(@uri,YAML.load_file(@yaml_file).metadata) + metadata = YAML.load_file(@yaml_file).metadata + s.add_model(@uri,metadata) s.to_rdfxml when /yaml/ File.read @yaml_file @@ -20,6 +21,7 @@ end get '/:id/metadata.?:ext?' do halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + @accept = "application/x-yaml" if params[:ext] and params[:ext].match?(/yaml/) metadata = YAML.load_file(@yaml_file).metadata case @accept when /yaml/ @@ -31,8 +33,9 @@ get '/:id/metadata.?:ext?' do end end -get '/:id/dependent' do +get '/:id/dependent.?:ext?' do halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + @accept = "application/x-yaml" if params[:ext].match?(/yaml/) feature_uri = YAML.load_file(@yaml_file).metadata[OT.dependentVariables] case @accept when /yaml/ @@ -48,8 +51,9 @@ get '/:id/dependent' do end end -get '/:id/predicted' do +get '/:id/predicted.?:ext?' do halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + @accept = "application/x-yaml" if params[:ext].match?(/yaml/) return feature_uri if @accept == "text/uri-list" predicted = OpenTox::Feature.new(File.join @uri,"predicted") dependent = OpenTox::Feature.find(YAML.load_file(@yaml_file).metadata[OT.dependentVariables]) -- cgit v1.2.3 From 54ba82b457262cc97852bc176d5d735c1aadd160 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Tue, 24 May 2011 11:56:01 +0200 Subject: fix content type for get model request --- lazar.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lazar.rb b/lazar.rb index 7a1494a..019a0b2 100644 --- a/lazar.rb +++ b/lazar.rb @@ -6,13 +6,16 @@ get '/:id/?' do halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file case @accept when /application\/rdf\+xml/ + response['Content-Type'] = 'application/rdf+xml' s = OpenTox::Serializer::Owl.new metadata = YAML.load_file(@yaml_file).metadata s.add_model(@uri,metadata) s.to_rdfxml when /yaml/ + response['Content-Type'] = 'application/x-yaml' File.read @yaml_file when /html/ + response['Content-Type'] = 'text/html' OpenTox.text_to_html File.read(@yaml_file) else halt 400, "Unsupported MIME type '#{@accept}'" -- cgit v1.2.3 From 18893781c93041a2f750814ed5bd2fff3e76addf Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 26 May 2011 20:32:10 +0000 Subject: /model/:id/predicted/[value|confidence] added --- lazar.rb | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/lazar.rb b/lazar.rb index 019a0b2..e1fa05e 100644 --- a/lazar.rb +++ b/lazar.rb @@ -24,7 +24,7 @@ end get '/:id/metadata.?:ext?' do halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file - @accept = "application/x-yaml" if params[:ext] and params[:ext].match?(/yaml/) + @accept = "application/x-yaml" if params[:ext] and params[:ext].match(/yaml/) metadata = YAML.load_file(@yaml_file).metadata case @accept when /yaml/ @@ -38,7 +38,7 @@ end get '/:id/dependent.?:ext?' do halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file - @accept = "application/x-yaml" if params[:ext].match?(/yaml/) + @accept = "application/x-yaml" if params[:ext] and params[:ext].match(/yaml/) feature_uri = YAML.load_file(@yaml_file).metadata[OT.dependentVariables] case @accept when /yaml/ @@ -54,23 +54,41 @@ get '/:id/dependent.?:ext?' do end end +get '/:id/predicted/:prop' do + halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + if params[:prop] == "value" or params[:prop] == "confidence" + feature = eval "YAML.load_file(@yaml_file).prediction_#{params[:prop]}_feature" + case @accept + when /yaml/ + feature.to_yaml + when /rdf/ + feature.to_rdfxml + when /html/ + OpenTox.text_to_html feature.to_yaml + else + halt 400, "Unsupported MIME type '#{@accept}'" + end + else + halt 400, "Unknown URI #{@uri}" + end +end + get '/:id/predicted.?:ext?' do halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file - @accept = "application/x-yaml" if params[:ext].match?(/yaml/) - return feature_uri if @accept == "text/uri-list" - predicted = OpenTox::Feature.new(File.join @uri,"predicted") - dependent = OpenTox::Feature.find(YAML.load_file(@yaml_file).metadata[OT.dependentVariables]) - predicted.metadata[RDF.type] = dependent.metadata[RDF.type] - #predicted.metadata[OT.hasSource] = @uri - #predicted.metadata[DC.creator] = @uri - predicted.metadata[DC.title] = dependent.metadata[DC.title] + @accept = "application/x-yaml" if params[:ext] and params[:ext].match(/yaml/) + features = YAML.load_file(@yaml_file).prediction_features case @accept + when "text/uri-list" + "#{features.collect{|f| f.uri}.join("\n")}\n" when /yaml/ - predicted.to_yaml + features.to_yaml when /rdf/ - predicted.to_rdfxml + serializer = OpenTox::Serializer::Owl.new + features.each{|f| serializer.add_feature(f.uri,f.metadata)} + serializer.to_rdfxml + #feature.to_rdfxml when /html/ - OpenTox.text_to_html predicted.to_yaml + OpenTox.text_to_html features.to_yaml else halt 400, "Unsupported MIME type '#{@accept}'" end @@ -86,6 +104,9 @@ post '/?' do # create model @yaml_file = "public/#{@id}.yaml" lazar = YAML.load request.env["rack.input"].read lazar.uri = @uri + value_feature_uri = File.join( @uri, "predicted", "value") + confidence_feature_uri = File.join( @uri, "predicted", "confidence") + lazar.metadata[OT.predictedVariables] = [value_feature_uri, confidence_feature_uri] File.open(@yaml_file,"w+"){|f| f.puts lazar.to_yaml} OpenTox::Authorization.check_policy(@uri, @subjectid) if File.exists? @yaml_file response['Content-Type'] = 'text/uri-list' -- cgit v1.2.3 From 2e902d818ac6dc7dff9496f30f1ac7b5acc6ce80 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 27 May 2011 09:57:49 +0200 Subject: fix predicted model features: return metadata isntead of feature itself as yaml, set content type --- lazar.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lazar.rb b/lazar.rb index e1fa05e..65aff16 100644 --- a/lazar.rb +++ b/lazar.rb @@ -60,11 +60,14 @@ get '/:id/predicted/:prop' do feature = eval "YAML.load_file(@yaml_file).prediction_#{params[:prop]}_feature" case @accept when /yaml/ - feature.to_yaml - when /rdf/ + content_type "application/x-yaml" + feature.metadata.to_yaml + when /rdf/ + content_type "application/rdf+xml" feature.to_rdfxml when /html/ - OpenTox.text_to_html feature.to_yaml + content_type "text/html" + OpenTox.text_to_html feature.metadata.to_yaml else halt 400, "Unsupported MIME type '#{@accept}'" end -- cgit v1.2.3 From 83d51d8a56e138d6509b7d25e48eb6576fcd4b56 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 30 May 2011 10:12:56 +0000 Subject: cached predictions fixed --- lazar.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lazar.rb b/lazar.rb index 65aff16..9b3d07b 100644 --- a/lazar.rb +++ b/lazar.rb @@ -132,7 +132,6 @@ post '/:id/?' do if compound_uri cache = PredictionCache.find(:model_uri => @lazar.uri, :compound_uri => compound_uri).first - return cache.dataset_uri if cache and uri_available?(cache.dataset_uri) if cache and uri_available?(cache.dataset_uri) return cache.dataset_uri else -- cgit v1.2.3 From a1e196ecbfcd40adbe6221c264adcf653a388d57 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 6 Jun 2011 16:54:56 +0000 Subject: halts (partially) substituted by OpenTox errors --- application.rb | 4 ++-- lazar.rb | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/application.rb b/application.rb index 6e1dcd7..c03d1b7 100644 --- a/application.rb +++ b/application.rb @@ -23,7 +23,7 @@ before do @uri = uri @id @yaml_file = "public/#{@id}.yaml" - halt 404, "Model #{@id} not found." unless File.exists? @yaml_file + raise OpenTox::NotFoundError.new "Model #{@id} not found." unless File.exists? @yaml_file end # make sure subjectid is not included in params, subjectid is set as member variable @@ -77,7 +77,7 @@ delete '/:id/?' do response['Content-Type'] = 'text/plain' "Model #{@id} deleted." rescue - halt 404, "Model #{@id} does not exist." + raise OpenTox::NotFoundError.new "Model #{@id} does not exist." end end diff --git a/lazar.rb b/lazar.rb index 9b3d07b..fa54ed6 100644 --- a/lazar.rb +++ b/lazar.rb @@ -3,7 +3,7 @@ require "haml" # Get model representation # @return [application/rdf+xml,application/x-yaml] Model representation get '/:id/?' do - halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + raise OpenTox::NotFoundError.new "Model #{params[:id]} not found." unless File.exists? @yaml_file case @accept when /application\/rdf\+xml/ response['Content-Type'] = 'application/rdf+xml' @@ -18,12 +18,12 @@ get '/:id/?' do response['Content-Type'] = 'text/html' OpenTox.text_to_html File.read(@yaml_file) else - halt 400, "Unsupported MIME type '#{@accept}'" + raise OpenTox::BadRequestError.new "Unsupported MIME type '#{@accept}'" end end get '/:id/metadata.?:ext?' do - halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + raise OpenTox::NotFoundError.new "Model #{params[:id]} not found." unless File.exists? @yaml_file @accept = "application/x-yaml" if params[:ext] and params[:ext].match(/yaml/) metadata = YAML.load_file(@yaml_file).metadata case @accept @@ -37,7 +37,7 @@ get '/:id/metadata.?:ext?' do end get '/:id/dependent.?:ext?' do - halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + raise OpenTox::NotFoundError.new "Model #{params[:id]} not found." unless File.exists? @yaml_file @accept = "application/x-yaml" if params[:ext] and params[:ext].match(/yaml/) feature_uri = YAML.load_file(@yaml_file).metadata[OT.dependentVariables] case @accept @@ -50,12 +50,12 @@ get '/:id/dependent.?:ext?' do when /html/ OpenTox.text_to_html OpenTox::Feature.find(feature_uri).to_yaml else - halt 400, "Unsupported MIME type '#{@accept}'" + raise OpenTox::BadRequestError.new "Unsupported MIME type '#{@accept}'" end end get '/:id/predicted/:prop' do - halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + raise OpenTox::NotFoundError.new "Model #{params[:id]} not found." unless File.exists? @yaml_file if params[:prop] == "value" or params[:prop] == "confidence" feature = eval "YAML.load_file(@yaml_file).prediction_#{params[:prop]}_feature" case @accept @@ -69,15 +69,15 @@ get '/:id/predicted/:prop' do content_type "text/html" OpenTox.text_to_html feature.metadata.to_yaml else - halt 400, "Unsupported MIME type '#{@accept}'" + raise OpenTox::BadRequestError.new "Unsupported MIME type '#{@accept}'" end else - halt 400, "Unknown URI #{@uri}" + raise OpenTox::BadRequestError.new "Unknown URI #{@uri}" end end get '/:id/predicted.?:ext?' do - halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + raise OpenTox::NotFoundError.new "Model #{params[:id]} not found." unless File.exists? @yaml_file @accept = "application/x-yaml" if params[:ext] and params[:ext].match(/yaml/) features = YAML.load_file(@yaml_file).prediction_features case @accept @@ -93,7 +93,7 @@ get '/:id/predicted.?:ext?' do when /html/ OpenTox.text_to_html features.to_yaml else - halt 400, "Unsupported MIME type '#{@accept}'" + raise OpenTox::BadRequestError.new "Unsupported MIME type '#{@accept}'" end end @@ -101,7 +101,7 @@ end # @param [Body] lazar Model representation in YAML format # @return [String] Model URI post '/?' do # create model - halt 400, "MIME type \"#{request.content_type}\" not supported." unless request.content_type.match(/yaml/) + raise OpenTox::BadRequestError.new "MIME type \"#{request.content_type}\" not supported." unless request.content_type.match(/yaml/) @id = next_id @uri = uri @id @yaml_file = "public/#{@id}.yaml" @@ -123,9 +123,9 @@ end # @return [text/uri-list] URI of prediction task (dataset prediction) or prediction dataset (compound prediction) post '/:id/?' do - halt 404, "Model #{params[:id]} does not exist." unless File.exists? @yaml_file + raise OpenTox::NotFoundError.new "Model #{params[:id]} does not exist." unless File.exists? @yaml_file - halt 404, "No compound_uri or dataset_uri parameter." unless compound_uri = params[:compound_uri] or dataset_uri = params[:dataset_uri] + raise OpenTox::NotFoundError.new "No compound_uri or dataset_uri parameter." unless compound_uri = params[:compound_uri] or dataset_uri = params[:dataset_uri] @lazar = YAML.load_file @yaml_file response['Content-Type'] = 'text/uri-list' @@ -141,14 +141,14 @@ post '/:id/?' do prediction_uri rescue LOGGER.error "Lazar prediction failed for #{compound_uri} with #{$!} " - halt 500, "Prediction of #{compound_uri} with #{@lazar.uri} failed." + raise "Prediction of #{compound_uri} with #{@lazar.uri} failed." end end elsif dataset_uri task = OpenTox::Task.create("Predict dataset",url_for("/#{@lazar.id}", :full)) do |task| @lazar.predict_dataset(dataset_uri, @subjectid, task).uri end - halt 503,task.uri+"\n" if task.status == "Cancelled" + raise OpenTox::ServiceUnavailableError.newtask.uri+"\n" if task.status == "Cancelled" halt 202,task.uri end -- cgit v1.2.3 From 400f8a894bbd0f781735fd94e9707ef8ff8fc577 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 23 Jun 2011 13:16:12 +0000 Subject: lazar predictions fixed --- application.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application.rb b/application.rb index c03d1b7..7d3de38 100644 --- a/application.rb +++ b/application.rb @@ -69,9 +69,9 @@ delete '/:id/?' do if @subjectid and !File.exists? @yaml_file and @uri begin res = OpenTox::Authorization.delete_policies_from_uri(@uri, @subjectid) - LOGGER.debug "Policy deleted for Dataset URI: #{@uri} with result: #{res}" + LOGGER.debug "Policy deleted for Model URI: #{@uri} with result: #{res}" rescue - LOGGER.warn "Policy delete error for Dataset URI: #{@uri}" + LOGGER.warn "Policy delete error for Model URI: #{@uri}" end end response['Content-Type'] = 'text/plain' -- cgit v1.2.3