class Scoruby::Predicates::SimplePredicate
Constants
- EQUAL
- GREATER_OR_EQUAL
- GREATER_THAN
- IS_MISSING
- LESS_OR_EQUAL
- LESS_THAN
- MATH_OPS
Attributes
field[R]
Public Class Methods
new(pred_xml)
click to toggle source
# File lib/scoruby/predicates/simple_predicate.rb, line 19 def initialize(pred_xml) attributes = pred_xml.attributes @field = attributes['field'].value.to_sym @operator = attributes['operator'].value return if @operator == IS_MISSING @value = attributes['value'].value end
Public Instance Methods
missing?(features)
click to toggle source
# File lib/scoruby/predicates/simple_predicate.rb, line 34 def missing?(features) !features.keys.include?(@field) end
true?(features)
click to toggle source
# File lib/scoruby/predicates/simple_predicate.rb, line 28 def true?(features) return num_true?(features) if MATH_OPS.include?(@operator) return features[@field] == @value if @operator == EQUAL features[field].nil? || !features.key?(field) if @operator == IS_MISSING end
Private Instance Methods
compare(curr_value, value)
click to toggle source
# File lib/scoruby/predicates/simple_predicate.rb, line 45 def compare(curr_value, value) return curr_value > value if @operator == GREATER_THAN return curr_value < value if @operator == LESS_THAN return curr_value <= value if @operator == LESS_OR_EQUAL curr_value >= value if @operator == GREATER_OR_EQUAL end
num_true?(features)
click to toggle source
# File lib/scoruby/predicates/simple_predicate.rb, line 40 def num_true?(features) return false unless features[@field] compare(Float(features[@field]), Float(@value)) end