Class: Bors::Example

Inherits:
Object
  • Object
show all
Includes:
Math
Defined in:
lib/bors/example.rb,
lib/bors/example/feature.rb

Defined Under Namespace

Classes: Feature

Instance Method Summary collapse

Methods included from Math

#is_number?, #is_real_number?

Constructor Details

#initialize(options) ⇒ Example



9
10
11
# File 'lib/bors/example.rb', line 9

def initialize(options)
  @options = options
end

Instance Method Details

#featuresObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bors/example.rb', line 39

def features
  if @options[:namespaces] && @options[:namespaces].length > 0
    @options[:namespaces].map do |name, options|
      raise Exceptions::ArgumentError.new('Incorrect format for namescape, must be defined as a Hash') unless options.kind_of? Hash
      returning = "|#{name}"
      returning += ":#{options[:value]}" if options[:value]
      returning += create_features_from_array(options[:features])
      returning += " "
    end.join.strip
  else
    returning = "|"
    returning += create_features_from_array(@options[:features])
    returning += " "
  end
end

#importanceObject



21
22
23
# File 'lib/bors/example.rb', line 21

def importance
  return_options_key_if_valid_real_number :importance
end

#initial_predictionObject



25
26
27
# File 'lib/bors/example.rb', line 25

def initial_prediction
  return_options_key_if_valid_real_number :initial_prediction
end

#labelObject



17
18
19
# File 'lib/bors/example.rb', line 17

def label
  return_options_key_if_valid_number :label
end

#tagObject



29
30
31
32
33
34
35
36
37
# File 'lib/bors/example.rb', line 29

def tag
  if @options[:tag]
    raise Exceptions::ArgumentError.new('Tag must not contain spaces') unless @options[:tag].to_s.match(/\s/).nil?
    raise Exceptions::ArgumentError.new('Tag must be A-z-0-9') unless @options[:tag].to_s.match(/\W/).nil?
    @options[:tag]
  else
    ""
  end
end

#to_sObject



13
14
15
# File 'lib/bors/example.rb', line 13

def to_s
  "#{label} #{importance} #{initial_prediction} #{tag}#{features}".squeeze(' ')
end