From 2806bfff8a01f75351f31c5bd676b25b2fb36017 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Wed, 11 Aug 2010 08:46:45 +0200 Subject: add generic algorithm object --- lib/algorithm.rb | 19 +++++++++++++++++++ lib/model.rb | 5 ++--- lib/owl.rb | 4 ++-- 3 files changed, 23 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/algorithm.rb b/lib/algorithm.rb index cc06032..30a41e0 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -2,6 +2,25 @@ LOGGER.progname = File.expand_path(__FILE__) module OpenTox module Algorithm + + + class Generic + + attr_accessor :uri, :title, :date + + def self.find(uri) + owl = OpenTox::Owl.from_uri(uri, "Algorithm") + return self.new(owl) + end + + protected + def initialize(owl) + @title = owl.get("title") + @date = owl.get("date") + @uri = owl.uri + end + + end class Fminer diff --git a/lib/model.rb b/lib/model.rb index b6cef46..25266e3 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -21,9 +21,8 @@ module OpenTox protected def initialize(owl) - [:date, :creator, :title, :format, :algorithm, :dependentVariables, - :independentVariables, :predictedVariables, :trainingDataset].each do |a| - self.send("#{a.to_s}=".to_sym, owl.get(a.to_s)) + MODEL_ATTRIBS.each do |a| + self.send("#{a.to_s}=".to_sym, owl.get(a.to_s)) unless a==:uri end @uri = owl.uri if ENV['RACK_ENV'] =~ /test|debug/ diff --git a/lib/owl.rb b/lib/owl.rb index 7447ce6..245dcc7 100644 --- a/lib/owl.rb +++ b/lib/owl.rb @@ -233,7 +233,7 @@ module OpenTox unless owl.root_node types = [] owl.model.find(nil, RDF_TYPE, nil){ |s,p,o| types << o.to_s } - raise "root node for class '"+ot_class+"' not found (available type nodes: "+types.inspect+")" + raise "root node for class '"+owl.node(ot_class).to_s+"' not found (available type nodes: "+types.inspect+")" end raise "no uri in rdf: '"+owl.uri+"'" unless owl.uri and Utils.is_uri?(owl.uri) owl.ot_class = ot_class @@ -244,7 +244,7 @@ module OpenTox end def self.from_uri(uri, ot_class) - return from_data(RestClientWrapper.get(uri,:accept => "application/rdf+xml").to_s, uri, ot_class) + return from_data(RestClientWrapper.get(uri,:accept => "application/rdf+xml").to_s, uri, ot_class) end def rdf -- cgit v1.2.3