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 fafc707b60a1d093a8c26313cd7fc28ae6a54696 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 20 May 2011 10:57:47 +0000 Subject: model/:id/{predicted|dpendent} exposed through REST --- application.rb | 1 + lazar.rb | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/application.rb b/application.rb index 866a267..72e4254 100644 --- a/application.rb +++ b/application.rb @@ -16,6 +16,7 @@ end before do @accept = request.env['HTTP_ACCEPT'] @accept = 'application/rdf+xml' if @accept == '*/*' or @accept == '' or @accept.nil? + response['Content-Type'] = @accept @id = request.path_info.match(/^\/\d+/) unless @id.nil? @id = @id.to_s.sub(/\//,'').to_i diff --git a/lazar.rb b/lazar.rb index ba85784..5ade3c6 100644 --- a/lazar.rb +++ b/lazar.rb @@ -4,18 +4,14 @@ require "haml" # @return [application/rdf+xml,application/x-yaml] Model representation get '/:id/?' do halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file - response['Content-Type'] = @accept case @accept when /application\/rdf\+xml/ s = OpenTox::Serializer::Owl.new s.add_model(@uri,YAML.load_file(@yaml_file).metadata) - response['Content-Type'] = 'application/rdf+xml' 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}'" @@ -23,8 +19,8 @@ get '/:id/?' do end get '/:id/metadata.?:ext?' do + halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file metadata = YAML.load_file(@yaml_file).metadata - response['Content-Type'] = @accept case @accept when /yaml/ metadata.to_yaml @@ -35,6 +31,44 @@ get '/:id/metadata.?:ext?' do end end +get '/:id/dependent' do + halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + feature_uri = YAML.load_file(@yaml_file).metadata[OT.dependentVariables] + case @accept + when /yaml/ + OpenTox::Feature.find(feature_uri).to_yaml + when "text/uri-list" + feature_uri + when /rdf/ + OpenTox::Feature.find(feature_uri).to_rdfxml + when /html/ + OpenTox.text_to_html OpenTox::Feature.find(feature_uri).to_yaml + else + halt 400, "Unsupported MIME type '#{@accept}'" + end +end + +get '/:id/predicted' do + halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file + 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] + case @accept + when /yaml/ + predicted.to_yaml + when /rdf/ + predicted.to_rdfxml + when /html/ + OpenTox.text_to_html predicted.to_yaml + else + halt 400, "Unsupported MIME type '#{@accept}'" + end +end + # Store a lazar model. This method should not be called directly, use OpenTox::Algorithm::Lazr to create a lazar model # @param [Body] lazar Model representation in YAML format # @return [String] Model URI -- cgit v1.2.3