summaryrefslogtreecommitdiff
path: root/application.rb
blob: d58c7a79e2cf149e526386b0f42c14b770679a9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
include RDF

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
      
    end
  end
end