summaryrefslogtreecommitdiff
path: root/lazar.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2010-03-18 20:54:25 +0100
committerChristoph Helma <helma@in-silico.de>2010-03-18 20:54:25 +0100
commitec441343dd0482a94978ea3e10d5056d749bceba (patch)
treeb922c136355c84d50b69ec417f15f88f2c637a7d /lazar.rb
parent00845f15fa41b921fb7d16100a74553aaf61d62d (diff)
more detailed model information in toxcreate
Diffstat (limited to 'lazar.rb')
-rw-r--r--lazar.rb56
1 files changed, 49 insertions, 7 deletions
diff --git a/lazar.rb b/lazar.rb
index bef367a..8c8c018 100644
--- a/lazar.rb
+++ b/lazar.rb
@@ -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