Class: Wikipedia::VandalismDetection::Features::MarkupFrequency

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

Overview

This feature computes frequency of bad words in the inserted text.

Instance Method Summary collapse

Methods inherited from Base

#count

Instance Method Details

#calculate(edit) ⇒ Object

Returns the percentage of markup related words in the inserted text. Returns 0.0 if inserted clean text is of zero length.



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

def calculate(edit)
  super

  text = edit.inserted_text
  all_words_count = edit.inserted_words.count

  regex = /(#{WordLists::MARKUP.join('|')})/
  markup_words_count = text.scan(regex).count

  (all_words_count > 0) ? (markup_words_count.to_f) / (all_words_count.to_f) : 0.0
end