From fafc707b60a1d093a8c26313cd7fc28ae6a54696 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 20 May 2011 10:57:47 +0000 Subject: model/:id/{predicted|dpendent} exposed through REST --- lazar.rb | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'lazar.rb') diff --git a/lazar.rb b/lazar.rb index ba85784..5ade3c6 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 -- cgit v1.2.3