summaryrefslogtreecommitdiff
path: root/application.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2013-03-26 10:55:00 +0100
committerChristoph Helma <helma@in-silico.ch>2013-03-26 10:55:00 +0100
commit8d6dbd5dbad301cd3aa45bbfb82762dab3d26a82 (patch)
tree89de31b8151bb2bfa84b64416c210257a5f28d23 /application.rb
parentd15bf6a9b5c97f63c49b368ed56e43a3c2eb8fd6 (diff)
code cleanup and refactoring.
Diffstat (limited to 'application.rb')
-rw-r--r--application.rb44
1 files changed, 17 insertions, 27 deletions
diff --git a/application.rb b/application.rb
index d58c7a7..8c074ef 100644
--- a/application.rb
+++ b/application.rb
@@ -4,33 +4,23 @@ module OpenTox
class Application < Service
post "/model/:id/?" do
-
- # Read turtle
- rdfstr = FourStore.get(@uri, "text/turtle")
- graph = RDF::Graph.new
- graph << RDF::Reader.for(:content_type=> "text/turtle").new(rdfstr) # in-memory model of turtle
-
- # Define query
- query = RDF::Query.new({
- :model_params => { # identifier / container
- RDF.type => RDF::OT.Parameter, # Right side fixed (retrieve all parameters)
- RDF::DC.title => :name, # Right side will be filled (=the data we need)
- RDF::OT.paramValue => :value # Right side will be filled (=the data we need)
- }
- })
- res = query.execute(graph)
-
- # Gather hash
- m_params = res.inject({}) { |h,p|
- h[p.name.to_s] = p.value.to_s
- h
- }
- m_params[:compound_uri] = params[:compound_uri] if params[:compound_uri]
- m_params[:dataset_uri] = params[:dataset_uri] if params[:dataset_uri]
-
- # Make prediction
- RestClientWrapper.post File.join($algorithm[:uri],"lazar","predict"), m_params
-
+ if ( (params[:compound_uri] and params[:dataset_uri]) or
+ (!params[:compound_uri] and !params[:dataset_uri])
+ )
+ bad_request_error "Please submit either a compound_uri or a dataset_uri parameter."
+ end
+ sparql = "SELECT ?t ?v FROM <#{@uri}> WHERE {
+ ?p <#{RDF.type}> <#{RDF::OT.Parameter}> ;
+ <#{RDF::DC.title}> ?t ;
+ <#{RDF::OT.paramValue}> ?v . }"
+ parameters = Hash[FourStore.query(sparql, "text/uri-list").split("\n").collect{|row| row.split("\t")}]
+ parameters.each{|k,v| v.sub!(/\^\^.*$/,'')} # remove type information
+ parameters[:compound_uri] = params[:compound_uri] if params[:compound_uri]
+ parameters[:dataset_uri] = params[:dataset_uri] if params[:dataset_uri]
+ parameters[:model_uri] = @uri
+ # pass parameters instead of model_uri, because model service is blocked by incoming call
+ # TODO: check if this can be done with redirects (unlikely)
+ OpenTox::Algorithm.new(File.join($algorithm[:uri],"lazar","predict"), @subjectid).run parameters
end
end
end