<commit_before>class SimplePredicate

  GREATER_THAN = 'greaterThan'
  LESS_OR_EQUAL = 'lessOrEqual'
  EQUAL = 'equal'
  IS_MISSING = 'isMissing'

  attr_reader :field

  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

  def true?(features)
    return num_true?(features) if [GREATER_THAN, LESS_OR_EQUAL].include?(@operator)

    return features[@field] == @value if @operator == EQUAL
    features[field].nil? || !features.has_key?(field) if @operator == IS_MISSING
  end

  def num_true?(features)
    curr_value = Float(features[@field])
    value = Float(@value)
    return curr_value > value if @operator == GREATER_THAN
    curr_value < value if @operator == LESS_OR_EQUAL
  end
end<commit_msg>support more math compare ops<commit_after>class SimplePredicate

  GREATER_THAN = 'greaterThan'
  LESS_THAN = 'lessThan'
  LESS_OR_EQUAL = 'lessOrEqual'
  GREATER_OR_EQUAL = 'greaterOrEqual'
  MATH_OPS = [GREATER_THAN, LESS_THAN, LESS_OR_EQUAL, GREATER_OR_EQUAL]
  EQUAL = 'equal'
  IS_MISSING = 'isMissing'

  attr_reader :field

  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

  def true?(features)
    return num_true?(features) if MATH_OPS.include?(@operator)

    return features[@field] == @value if @operator == EQUAL
    features[field].nil? || !features.has_key?(field) if @operator == IS_MISSING
  end

  def num_true?(features)
    curr_value = Float(features[@field])
    value = Float(@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
end
{'fraction_non_alphanumeric': 0.11067388096409247, 'fraction_numerical': 0.0, 'mean_word_length': 4.296875, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '958900', 'n_tokens_mistral': 698, 'n_tokens_neox': 658, 'n_words': 153}