summaryrefslogtreecommitdiff
path: root/application.rb
diff options
context:
space:
mode:
authorAndreas Maunz <andreas@maunz.de>2012-09-07 11:07:14 +0200
committerAndreas Maunz <andreas@maunz.de>2012-09-07 11:07:14 +0200
commit921810f6ba002e58755214cafec97d124b8fd1f2 (patch)
treeb68a72fe171e7a20ffb2038d46eb5820f8813c2d /application.rb
parenta161cb27cfa87f383fe67a20de374dd19988d610 (diff)
Added model POST
Diffstat (limited to 'application.rb')
-rw-r--r--application.rb34
1 files changed, 27 insertions, 7 deletions
diff --git a/application.rb b/application.rb
index 5f38ef8..52475dc 100644
--- a/application.rb
+++ b/application.rb
@@ -1,14 +1,34 @@
+include RDF
+
module OpenTox
class Application < Service
+
post "/model/:id/?" do
- [RDF::OT.featureCalculationAlgorithm, RDF::OT.predictionAlgorithm, RDF::OT.similarityAlgorithm, RDF::OT.trainingDataset , RDF::OT.dependentVariables , RDF::OT.featureDataset].each do |param|
- query = "SELECT ?uri FROM <#{@uri}> WHERE {<#{@uri}> <#{param.to_s}> ?uri}"
- param_uri = FourStore.query query, "text/uri-list"
- param_name = param.to_s.split("#").last.underscore
- params[param_name] = param_uri
- end
- #puts params.inspect
+
+ # 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
+ params = res.inject({}) { |h,p|
+ h[p.name.to_s] = p.value.to_s
+ h
+ }
+
+ # Make prediction
RestClientWrapper.post File.join($algorithm[:uri],"lazar","predict"), params
+
end
end
end