diff options
author | Christoph Helma <helma@in-silico.de> | 2010-03-18 20:54:25 +0100 |
---|---|---|
committer | Christoph Helma <helma@in-silico.de> | 2010-03-18 20:54:25 +0100 |
commit | ec441343dd0482a94978ea3e10d5056d749bceba (patch) | |
tree | b922c136355c84d50b69ec417f15f88f2c637a7d | |
parent | 00845f15fa41b921fb7d16100a74553aaf61d62d (diff) |
more detailed model information in toxcreate
-rw-r--r-- | application.rb | 2 | ||||
-rw-r--r-- | lazar.rb | 56 |
2 files changed, 50 insertions, 8 deletions
diff --git a/application.rb b/application.rb index 14c4aa6..75f2271 100644 --- a/application.rb +++ b/application.rb @@ -7,7 +7,7 @@ class Model include DataMapper::Resource property :id, Serial property :uri, String, :length => 255 - #property :owl, Text, :length => 2**32-1 + property :owl, Text, :length => 2**32-1 property :yaml, Text, :length => 2**32-1 property :created_at, DateTime end @@ -74,25 +74,52 @@ class Lazar < Model def to_owl data = YAML.load(yaml) + activity_dataset = YAML.load(RestClient.get(data.activity_dataset_uri, :accept => 'application/x-yaml').to_s) + feature_dataset = YAML.load(RestClient.get(data.feature_dataset_uri, :accept => 'application/x-yaml').to_s) owl = OpenTox::Owl.new 'Model', uri owl.source = "http://github.com/helma/opentox-model" - #owl.algorithm = data.algorithm - owl.dependentVariable = data.activity_dataset_uri - owl.independentVariables = data.feature_dataset_uri + owl.title = "#{URI.decode(activity_dataset.title)} lazar classification" + owl.date = created_at.to_s + owl.algorithm = data.algorithm + owl.dependentVariables = activity_dataset.features.join(', ') + owl.independentVariables = feature_dataset.features.join(', ') + owl.predictedVariables = activity_dataset.features.join(', ') + "_lazar_classification" + owl.parameters = { + "Dataset URI" => + { :scope => "mandatory", :value => data.activity_dataset_uri }, + "Feature URI for dependent variable" => + { :scope => "mandatory", :value => activity_dataset.features.join(', ')}, + "Feature generation URI" => + { :scope => "mandatory", :value => feature_dataset.source } + } + owl.trainingDataset = data.activity_dataset_uri owl.rdf end end get '/:id/?' do - model = Lazar.get(params[:id]) - halt 404, "Model #{uri} not found." unless model accept = request.env['HTTP_ACCEPT'] - accept = "application/rdf+xml" if accept == '*/*' or accept =~ /html/ or accept == '' or accept.nil? + accept = "application/rdf+xml" if accept == '*/*' or accept == '' or accept.nil? + # workaround for browser links + case params[:id] + when /.yaml$/ + params[:id].sub!(/.yaml$/,'') + accept = 'application/x-yaml' + when /.rdf$/ + params[:id].sub!(/.rdf$/,'') + accept = 'application/rdf+xml' + end + model = Lazar.get(params[:id]) + halt 404, "Model #{params[:id]} not found." unless model case accept when "application/rdf+xml" response['Content-Type'] = 'application/rdf+xml' - model.to_owl + unless model.owl # lazy owl creation + model.owl = model.to_owl + model.save + end + model.owl when /yaml/ response['Content-Type'] = 'application/x-yaml' model.yaml @@ -101,6 +128,21 @@ get '/:id/?' do end end +get '/:id/algorithm/?' do + response['Content-Type'] = 'text/plain' + YAML.load(Lazar.get(params[:id]).yaml).algorithm +end + +get '/:id/training_dataset/?' do + response['Content-Type'] = 'text/plain' + YAML.load(Lazar.get(params[:id]).yaml).activity_dataset_uri +end + +get '/:id/feature_dataset/?' do + response['Content-Type'] = 'text/plain' + YAML.load(Lazar.get(params[:id]).yaml).feature_dataset_uri +end + post '/?' do # create model halt 400, "MIME type \"#{request.content_type}\" not supported." unless request.content_type.match(/yaml/) model = Lazar.new |