Class: Wikipedia::VandalismDetection::Features::UserReputation
- Defined in:
- lib/wikipedia/vandalism_detection/features/user_reputation.rb
Overview
This feature calculates the average editor’s reputation on the current article.
Instance Method Summary collapse
-
#calculate(edit) ⇒ Object
Attention! This can be pretty time consuming (up to 2 sec) due to the url request.
Methods inherited from Base
Instance Method Details
#calculate(edit) ⇒ Object
Attention! This can be pretty time consuming (up to 2 sec) due to the url request.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wikipedia/vandalism_detection/features/user_reputation.rb', line 13 def calculate(edit) super revision = edit.new_revision page_id = edit.page.id || Wikipedia::api_request({ titles: edit.page.title }).xpath("//page/@pageid").first text = Wikipedia::wikitrust_request({ pageid: page_id, revid: revision.id }) contributions = text.scan(/(\{\{#t:\d+,\d+,#{revision.contributor}\}\})/) # {{#t:trust,revision_id,UserName}} trust = 0.0 unless contributions.empty? sum = contributions.reduce(0.0) do |sum, contribution| sum += contribution[0].split(',').first.split(':').last.to_f end trust = sum / contributions.count.to_f end trust end |