diff options
author | mguetlein <martin.guetlein@gmail.com> | 2010-06-09 12:13:25 +0200 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2010-06-09 12:13:25 +0200 |
commit | 2ee258935818fa3dcc9b863216f383969807c191 (patch) | |
tree | 3c4cce04edd2e50270c5b7fbb6ee0fd3f5e8a048 /lib | |
parent | bef6b090942db1e51c88b3b4063e8bf7a16bebeb (diff) |
report persistance, modify val persistance (serialize hashes, rename uri)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rdf_provider.rb | 54 | ||||
-rw-r--r-- | lib/validation_db.rb | 33 |
2 files changed, 54 insertions, 33 deletions
diff --git a/lib/rdf_provider.rb b/lib/rdf_provider.rb index e9d0f2f..5894cb1 100644 --- a/lib/rdf_provider.rb +++ b/lib/rdf_provider.rb @@ -1,4 +1,13 @@ +class String + def convert_underscore + gsub(/_./) do |m| + m.gsub!(/^_/,"") + m.upcase + end + end +end + module Lib module RDFProvider @@ -25,29 +34,42 @@ module Lib raise "not implemented" end - def literal?( property ) - raise "not yet implemented" + def to_yaml + get_content_as_hash.to_yaml end - def literal_name( property ) - raise "not yet implemented" + def rdf_ignore?( prop ) + self.class::IGNORE.index( prop ) != nil end - def object_property?( property ) - raise "not yet implemented" + def literal?( prop ) + self.class::LITERALS.index( prop ) != nil end - def object_property_name( property ) - raise "not yet implemented" + def literal_name( prop ) + if self.class::LITERAL_NAMES.has_key?(prop) + self.class::LITERAL_NAMES[prop] + else + OT[prop.to_s.convert_underscore] + end end - - def class?( property ) - raise "not yet implemented" + + def object_property?( prop ) + self.class::OBJECT_PROPERTIES.has_key?( prop ) + end + + def object_property_name( prop ) + return self.class::OBJECT_PROPERTIES[ prop ] end - def class_name( property ) - raise "not yet implemented" + def class?(prop) + self.class::CLASSES.has_key?( prop ) end + + def class_name( prop ) + return self.class::CLASSES[ prop ] + end + end class HashToOwl @@ -82,7 +104,9 @@ module Lib LOGGER.warn "skipping nil value: "+k.to_s next end - if v.is_a?(Hash) + if @rdf_provider.rdf_ignore?(k) + #do nothing + elsif v.is_a?(Hash) new_node = add_class( k, node ) recursiv_add_content( v, new_node ) elsif v.is_a?(Array) @@ -98,8 +122,6 @@ module Lib set_literal( k, v, node) elsif @rdf_provider.object_property?(k) add_object_property( k, v, node) - elsif [ :uri, :id ].index(k)!=nil - #skip else raise "illegal value k:"+k.to_s+" v:"+v.to_s end diff --git a/lib/validation_db.rb b/lib/validation_db.rb index a3c9593..b7cafd8 100644 --- a/lib/validation_db.rb +++ b/lib/validation_db.rb @@ -2,28 +2,31 @@ [ 'rubygems', 'datamapper' ].each do |lib| require lib end - require "lib/merge.rb" require 'active_record' -ActiveRecord::Base.establish_connection( - :adapter => @@config[:database][:adapter], - :host => @@config[:database][:host], - :database => @@config[:database][:database], - :username => @@config[:database][:username], - :password => @@config[:database][:password] -) +require 'ar-extensions' +unless ActiveRecord::Base.connected? + ActiveRecord::Base.establish_connection( + :adapter => @@config[:database][:adapter], + :host => @@config[:database][:host], + :database => @@config[:database][:database], + :username => @@config[:database][:username], + :password => @@config[:database][:password] + ) + ActiveRecord::Base.logger = Logger.new("/dev/null") +end module Lib - VAL_PROPS_GENERAL = [ :id, :uri, :model_uri, :algorithm_uri, :training_dataset_uri, :prediction_feature, + VAL_PROPS_GENERAL = [ :validation_uri, :model_uri, :algorithm_uri, :training_dataset_uri, :prediction_feature, :test_dataset_uri, :test_target_dataset_uri, :prediction_dataset_uri, :created_at ] VAL_PROPS_SUM = [ :num_instances, :num_without_class, :num_unpredicted ] VAL_PROPS_AVG = [:real_runtime, :percent_without_class, :percent_unpredicted ] VAL_PROPS = VAL_PROPS_GENERAL + VAL_PROPS_SUM + VAL_PROPS_AVG # :crossvalidation_info - VAL_CV_PROPS = [ :crossvalidation_id, :crossvalidation_fold ] + VAL_CV_PROPS = [ :crossvalidation_id, :crossvalidation_uri, :crossvalidation_fold ] # :classification_statistics VAL_CLASS_PROPS_SINGLE_SUM = [ :num_correct, :num_incorrect, :confusion_matrix ] @@ -48,7 +51,7 @@ module Lib VAL_REGR_PROPS = [ :root_mean_squared_error, :mean_absolute_error, :r_square, :target_variance_actual, :target_variance_predicted ] CROSS_VAL_PROPS = [:dataset_uri, :num_folds, :stratified, :random_seed] - CROSS_VAL_PROPS_REDUNDANT = [:algorithm_uri, :created_at] + CROSS_VAL_PROPS + CROSS_VAL_PROPS_REDUNDANT = [:crossvalidation_uri, :algorithm_uri, :created_at] + CROSS_VAL_PROPS ALL_PROPS = VAL_PROPS + VAL_CV_PROPS + VAL_CLASS_PROPS_EXTENDED + VAL_REGR_PROPS + CROSS_VAL_PROPS @@ -57,14 +60,10 @@ module Lib VAL_MERGE_AVG = VAL_PROPS_AVG + VAL_CLASS_PROPS_SINGLE_AVG + VAL_CLASS_PROPS_PER_CLASS_AVG + VAL_REGR_PROPS class Validation < ActiveRecord::Base - def uri - self.validation_uri - end + serialize :classification_statistics + serialize :regression_statistics end class Crossvalidation < ActiveRecord::Base - def uri - self.crossvalidation_uri - end end end |