Class: Wikipedia::VandalismDetection::Features::FrequencyBase

Inherits:
Base
  • Object
show all
Defined in:
lib/wikipedia/vandalism_detection/features/frequency_base.rb

Instance Method Summary collapse

Methods inherited from Base

#calculate, #count

Instance Method Details

#frequency(text, terms) ⇒ Object

Returns the ratio of given numbers. For frequency calculation it returns 0.0 if total_count is zero.



11
12
13
14
15
16
# File 'lib/wikipedia/vandalism_detection/features/frequency_base.rb', line 11

def frequency(text, terms)
  total_count = text.split.count
  term_count = count terms, in: text

  (total_count > 0) ? (term_count.to_f) / (total_count.to_f) : 0.0
end