summaryrefslogtreecommitdiff
path: root/lib/feature.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2013-03-26 10:56:04 +0100
committerChristoph Helma <helma@in-silico.ch>2013-03-26 10:56:04 +0100
commita54db46684680d98311631804eca367cc949a715 (patch)
tree283b8c5f256e8605131cbfeae2217a77d0288ca7 /lib/feature.rb
parent4ba2cc9849473f97baf75195bb36c5057f1c58d4 (diff)
code cleanup and refactoring.
Diffstat (limited to 'lib/feature.rb')
-rw-r--r--lib/feature.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/feature.rb b/lib/feature.rb
new file mode 100644
index 0000000..5d3d962
--- /dev/null
+++ b/lib/feature.rb
@@ -0,0 +1,37 @@
+module OpenTox
+
+ class Feature
+
+ # Find out feature type
+ # Classification takes precedence
+ # @return [String] Feature type
+ def feature_type
+ if self[RDF.type].include?(RDF::OT.NominalFeature)
+ "classification"
+ elsif self[RDF.type].include?(RDF::OT.NumericFeature)
+ "regression"
+ else
+ "unknown"
+ end
+ end
+
+ # Get accept values
+ #
+ # @return[Array] Accept values
+ def accept_values
+ self[RDF::OT.acceptValue] ? self[RDF::OT.acceptValue].sort : nil
+ end
+
+ # Create value map
+ # @param [OpenTox::Feature] Feature
+ # @return [Hash] A hash with keys 1...feature.training_classes.size and values training classes
+ def value_map
+ unless defined? @value_map
+ accept_values ? @value_map = accept_values.each_index.inject({}) { |h,idx| h[idx+1]=accept_values[idx]; h } : @value_map = nil
+ end
+ @value_map
+ end
+
+ end
+
+end