Class: Wikipedia::VandalismDetection::Features::DigitRatio

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

Overview

This feature computes the digit to all letters ratio of the edit’s new revision inserted text.

Instance Method Summary collapse

Methods inherited from Base

#count

Instance Method Details

#calculate(edit) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/wikipedia/vandalism_detection/features/digit_ratio.rb', line 10

def calculate(edit)
  super

  text = edit.inserted_text
  return 0.0 if text.empty?

  all_letters_count = text.scan(/[[:alnum:]]/).size
  digit_count = text.scan(/[[:digit:]]/).size

  (1.0 + digit_count) / (1.0 + all_letters_count)
end