summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2011-05-20 11:00:05 +0000
committerChristoph Helma <helma@in-silico.ch>2011-05-20 11:00:05 +0000
commit3ed74a342d389e4fa6f8507a983d29a1ac95862a (patch)
tree597cbbfea755934db8d7aed8b916c4b2fc7a2b92
parent0b64779ad95c7db741ef68a36a58b1fa3f7f5cac (diff)
parentfafc707b60a1d093a8c26313cd7fc28ae6a54696 (diff)
Merge branch 'hotfix/rest_predicted_dependent' into development
-rw-r--r--application.rb1
-rw-r--r--lazar.rb44
2 files changed, 40 insertions, 5 deletions
diff --git a/application.rb b/application.rb
index ba3c1a1..8c241b4 100644
--- a/application.rb
+++ b/application.rb
@@ -16,6 +16,7 @@ end
before do
@accept = request.env['HTTP_ACCEPT']
@accept = 'application/rdf+xml' if @accept == '*/*' or @accept == '' or @accept.nil?
+ response['Content-Type'] = @accept
@id = request.path_info.match(/^\/\d+/)
unless @id.nil?
@id = @id.to_s.sub(/\//,'').to_i
diff --git a/lazar.rb b/lazar.rb
index 617ec73..d297ccf 100644
--- a/lazar.rb
+++ b/lazar.rb
@@ -4,18 +4,14 @@ require "haml"
# @return [application/rdf+xml,application/x-yaml] Model representation
get '/:id/?' do
halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file
- response['Content-Type'] = @accept
case @accept
when /application\/rdf\+xml/
s = OpenTox::Serializer::Owl.new
s.add_model(@uri,YAML.load_file(@yaml_file).metadata)
- response['Content-Type'] = 'application/rdf+xml'
s.to_rdfxml
when /yaml/
- response['Content-Type'] = 'application/x-yaml'
File.read @yaml_file
when /html/
- response['Content-Type'] = 'text/html'
OpenTox.text_to_html File.read(@yaml_file)
else
halt 400, "Unsupported MIME type '#{@accept}'"
@@ -23,8 +19,8 @@ get '/:id/?' do
end
get '/:id/metadata.?:ext?' do
+ halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file
metadata = YAML.load_file(@yaml_file).metadata
- response['Content-Type'] = @accept
case @accept
when /yaml/
metadata.to_yaml
@@ -35,6 +31,44 @@ get '/:id/metadata.?:ext?' do
end
end
+get '/:id/dependent' do
+ halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file
+ feature_uri = YAML.load_file(@yaml_file).metadata[OT.dependentVariables]
+ case @accept
+ when /yaml/
+ OpenTox::Feature.find(feature_uri).to_yaml
+ when "text/uri-list"
+ feature_uri
+ when /rdf/
+ OpenTox::Feature.find(feature_uri).to_rdfxml
+ when /html/
+ OpenTox.text_to_html OpenTox::Feature.find(feature_uri).to_yaml
+ else
+ halt 400, "Unsupported MIME type '#{@accept}'"
+ end
+end
+
+get '/:id/predicted' do
+ halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file
+ return feature_uri if @accept == "text/uri-list"
+ predicted = OpenTox::Feature.new(File.join @uri,"predicted")
+ dependent = OpenTox::Feature.find(YAML.load_file(@yaml_file).metadata[OT.dependentVariables])
+ predicted.metadata[RDF.type] = dependent.metadata[RDF.type]
+ #predicted.metadata[OT.hasSource] = @uri
+ #predicted.metadata[DC.creator] = @uri
+ predicted.metadata[DC.title] = dependent.metadata[DC.title]
+ case @accept
+ when /yaml/
+ predicted.to_yaml
+ when /rdf/
+ predicted.to_rdfxml
+ when /html/
+ OpenTox.text_to_html predicted.to_yaml
+ else
+ halt 400, "Unsupported MIME type '#{@accept}'"
+ end
+end
+
# Store a lazar model. This method should not be called directly, use OpenTox::Algorithm::Lazr to create a lazar model
# @param [Body] lazar Model representation in YAML format
# @return [String] Model URI