Class: Wikipedia::VandalismDetection::Features::UpperCaseRatio

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

Overview

This feature computes the uppercase 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/upper_case_ratio.rb', line 10

def calculate(edit)
  super

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

  uppercase_count = text.scan(/[[:upper:]]/).size
  all_letters_count = text.scan(/[[:alpha:]]/).size

  (1.0 + uppercase_count) / (1.0 + all_letters_count)
end