Class: Wikipedia::VandalismDetection::Features::EmoticonsImpact

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

Overview

This feature computes impact of emoticons words in the inserted text.

Instance Method Summary collapse

Methods inherited from Base

#count

Instance Method Details

#calculate(edit) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wikipedia/vandalism_detection/features/emoticons_impact.rb', line 12

def calculate(edit)
  super

  old_text = edit.old_revision.text
  new_text = edit.new_revision.text

  regex = /(^|\s)(#{WordLists::EMOTICONS.join('|')})(?=\s|$|\Z|[\.,!?]\s|[\.!?]\Z)/

  old_count = old_text.scan(regex).flatten.reject { |c| c.size < 2 }.count.to_f
  new_count = new_text.scan(regex).flatten.reject { |c| c.size < 2 }.count.to_f

  no_terms_in_both = (old_count == 0 && new_count == 0)
  no_terms_in_both ? 0.5 : (old_count / (old_count + new_count))
end