wikipedia-vandalism_detection 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +4 -0
- data/README.md +265 -0
- data/Rakefile +12 -0
- data/lib/java/LibSVM.jar +0 -0
- data/lib/java/SMOTE.jar +0 -0
- data/lib/java/balancedRandomForest.jar +0 -0
- data/lib/java/diffutils-1.3.0.jar +0 -0
- data/lib/java/libsvm.jar +0 -0
- data/lib/java/oneClassClassifier.jar +0 -0
- data/lib/java/realAdaBoost.jar +0 -0
- data/lib/java/swc-engine-1.1.0-jar-with-dependencies.jar +0 -0
- data/lib/java/sweble-wikitext-extractor.jar +0 -0
- data/lib/weka/classifiers/functions/lib_svm.rb +15 -0
- data/lib/weka/classifiers/meta/one_class_classifier.rb +25 -0
- data/lib/weka/classifiers/meta/real_ada_boost.rb +17 -0
- data/lib/weka/classifiers/trees/balanced_random_forest.rb +18 -0
- data/lib/weka/filters/supervised/instance/smote.rb +22 -0
- data/lib/wikipedia.rb +51 -0
- data/lib/wikipedia/vandalism_detection.rb +30 -0
- data/lib/wikipedia/vandalism_detection/algorithms.rb +18 -0
- data/lib/wikipedia/vandalism_detection/algorithms/kullback_leibler_divergence.rb +69 -0
- data/lib/wikipedia/vandalism_detection/classifier.rb +186 -0
- data/lib/wikipedia/vandalism_detection/configuration.rb +321 -0
- data/lib/wikipedia/vandalism_detection/diff.rb +27 -0
- data/lib/wikipedia/vandalism_detection/edit.rb +75 -0
- data/lib/wikipedia/vandalism_detection/evaluator.rb +606 -0
- data/lib/wikipedia/vandalism_detection/exceptions.rb +40 -0
- data/lib/wikipedia/vandalism_detection/feature_calculator.rb +89 -0
- data/lib/wikipedia/vandalism_detection/features.rb +67 -0
- data/lib/wikipedia/vandalism_detection/features/all_wordlists_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/all_wordlists_impact.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/anonymity.rb +19 -0
- data/lib/wikipedia/vandalism_detection/features/anonymity_previous.rb +29 -0
- data/lib/wikipedia/vandalism_detection/features/article_size.rb +18 -0
- data/lib/wikipedia/vandalism_detection/features/bad_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/bad_impact.rb +21 -0
- data/lib/wikipedia/vandalism_detection/features/base.rb +54 -0
- data/lib/wikipedia/vandalism_detection/features/biased_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/biased_impact.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/blanking.rb +25 -0
- data/lib/wikipedia/vandalism_detection/features/character_diversity.rb +25 -0
- data/lib/wikipedia/vandalism_detection/features/character_sequence.rb +19 -0
- data/lib/wikipedia/vandalism_detection/features/comment_bad_frequency.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/comment_biased_frequency.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/comment_length.rb +17 -0
- data/lib/wikipedia/vandalism_detection/features/comment_markup_frequency.rb +27 -0
- data/lib/wikipedia/vandalism_detection/features/comment_pronoun_frequency.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/comment_sex_frequency.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/comment_vulgarism_frequency.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/compressibility.rb +27 -0
- data/lib/wikipedia/vandalism_detection/features/contains_base.rb +18 -0
- data/lib/wikipedia/vandalism_detection/features/copyedit.rb +18 -0
- data/lib/wikipedia/vandalism_detection/features/digit_ratio.rb +24 -0
- data/lib/wikipedia/vandalism_detection/features/edits_per_user.rb +65 -0
- data/lib/wikipedia/vandalism_detection/features/emoticons_frequency.rb +27 -0
- data/lib/wikipedia/vandalism_detection/features/emoticons_impact.rb +29 -0
- data/lib/wikipedia/vandalism_detection/features/frequency_base.rb +20 -0
- data/lib/wikipedia/vandalism_detection/features/impact_base.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/inserted_character_distribution.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/inserted_external_links.rb +18 -0
- data/lib/wikipedia/vandalism_detection/features/inserted_internal_links.rb +18 -0
- data/lib/wikipedia/vandalism_detection/features/inserted_size.rb +20 -0
- data/lib/wikipedia/vandalism_detection/features/inserted_words.rb +18 -0
- data/lib/wikipedia/vandalism_detection/features/longest_word.rb +20 -0
- data/lib/wikipedia/vandalism_detection/features/markup_frequency.rb +27 -0
- data/lib/wikipedia/vandalism_detection/features/markup_impact.rb +27 -0
- data/lib/wikipedia/vandalism_detection/features/non_alphanumeric_ratio.rb +24 -0
- data/lib/wikipedia/vandalism_detection/features/personal_life.rb +18 -0
- data/lib/wikipedia/vandalism_detection/features/pronoun_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/pronoun_impact.rb +21 -0
- data/lib/wikipedia/vandalism_detection/features/removed_all_wordlists_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/removed_bad_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/removed_biased_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/removed_character_distribution.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/removed_emoticons_frequency.rb +27 -0
- data/lib/wikipedia/vandalism_detection/features/removed_markup_frequency.rb +28 -0
- data/lib/wikipedia/vandalism_detection/features/removed_pronoun_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/removed_sex_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/removed_size.rb +20 -0
- data/lib/wikipedia/vandalism_detection/features/removed_vulgarism_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/removed_words.rb +18 -0
- data/lib/wikipedia/vandalism_detection/features/replacement_similarity.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/reverted.rb +18 -0
- data/lib/wikipedia/vandalism_detection/features/revisions_character_distribution.rb +21 -0
- data/lib/wikipedia/vandalism_detection/features/same_editor.rb +29 -0
- data/lib/wikipedia/vandalism_detection/features/sex_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/sex_impact.rb +21 -0
- data/lib/wikipedia/vandalism_detection/features/size_increment.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/size_ratio.rb +26 -0
- data/lib/wikipedia/vandalism_detection/features/term_frequency.rb +25 -0
- data/lib/wikipedia/vandalism_detection/features/time_interval.rb +31 -0
- data/lib/wikipedia/vandalism_detection/features/time_of_day.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/upper_case_ratio.rb +24 -0
- data/lib/wikipedia/vandalism_detection/features/upper_case_words_ratio.rb +31 -0
- data/lib/wikipedia/vandalism_detection/features/upper_to_lower_case_ratio.rb +24 -0
- data/lib/wikipedia/vandalism_detection/features/user_reputation.rb +38 -0
- data/lib/wikipedia/vandalism_detection/features/vulgarism_frequency.rb +23 -0
- data/lib/wikipedia/vandalism_detection/features/vulgarism_impact.rb +22 -0
- data/lib/wikipedia/vandalism_detection/features/weekday.rb +21 -0
- data/lib/wikipedia/vandalism_detection/features/words_increment.rb +22 -0
- data/lib/wikipedia/vandalism_detection/instances.rb +130 -0
- data/lib/wikipedia/vandalism_detection/page.rb +88 -0
- data/lib/wikipedia/vandalism_detection/page_parser.rb +52 -0
- data/lib/wikipedia/vandalism_detection/revision.rb +69 -0
- data/lib/wikipedia/vandalism_detection/revision_parser.rb +43 -0
- data/lib/wikipedia/vandalism_detection/test_dataset.rb +367 -0
- data/lib/wikipedia/vandalism_detection/text.rb +18 -0
- data/lib/wikipedia/vandalism_detection/training_dataset.rb +303 -0
- data/lib/wikipedia/vandalism_detection/version.rb +5 -0
- data/lib/wikipedia/vandalism_detection/wikitext_extractor.rb +80 -0
- data/lib/wikipedia/vandalism_detection/word_lists.rb +19 -0
- data/lib/wikipedia/vandalism_detection/word_lists/bad.rb +12 -0
- data/lib/wikipedia/vandalism_detection/word_lists/biased.rb +21 -0
- data/lib/wikipedia/vandalism_detection/word_lists/emoticons.rb +22 -0
- data/lib/wikipedia/vandalism_detection/word_lists/markup.rb +12 -0
- data/lib/wikipedia/vandalism_detection/word_lists/pronouns.rb +15 -0
- data/lib/wikipedia/vandalism_detection/word_lists/sex.rb +12 -0
- data/lib/wikipedia/vandalism_detection/word_lists/vulgarism.rb +97 -0
- data/spec/factories/edit.rb +20 -0
- data/spec/factories/page.rb +13 -0
- data/spec/factories/revision.rb +51 -0
- data/spec/resources/config/config.yml +35 -0
- data/spec/resources/corpora/test/edits.csv +8 -0
- data/spec/resources/corpora/test/ground-truth.txt +3 -0
- data/spec/resources/corpora/test/revisions/part-1/326471754.txt +199 -0
- data/spec/resources/corpora/test/revisions/part-1/326873205.txt +137 -0
- data/spec/resources/corpora/test/revisions/part-1/328774035.txt +162 -0
- data/spec/resources/corpora/test/revisions/part-2/307084144.txt +137 -0
- data/spec/resources/corpora/test/revisions/part-2/326978767.txt +199 -0
- data/spec/resources/corpora/test/revisions/part-2/328774110.txt +162 -0
- data/spec/resources/corpora/training/annotations.csv +7 -0
- data/spec/resources/corpora/training/edits.csv +7 -0
- data/spec/resources/corpora/training/revisions/part-1/326471754.txt +199 -0
- data/spec/resources/corpora/training/revisions/part-1/326873205.txt +137 -0
- data/spec/resources/corpora/training/revisions/part-1/328774035.txt +162 -0
- data/spec/resources/corpora/training/revisions/part-2/307084144.txt +137 -0
- data/spec/resources/corpora/training/revisions/part-2/326978767.txt +199 -0
- data/spec/resources/corpora/training/revisions/part-2/328774110.txt +162 -0
- data/spec/resources/page_with_redirects.xml +85 -0
- data/spec/resources/redirect_page.xml +59 -0
- data/spec/resources/revision_simplified.xml +13 -0
- data/spec/resources/sample_revision.txt +137 -0
- data/spec/resources/sample_revision_clean_text.txt +1 -0
- data/spec/resources/sample_revision_plain_text.txt +183 -0
- data/spec/resources/vandalism_on_wikipedia.xml +234 -0
- data/spec/resources/vandalism_on_wikipedia_simplified.xml +119 -0
- data/spec/resources/wikipedia_tokens.txt +30 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/macros/file_reading.rb +7 -0
- data/spec/support/macros/test_configuration.rb +71 -0
- data/spec/vandalism_detection/algorithms/kullback_leibler_divergence_spec.rb +36 -0
- data/spec/vandalism_detection/classifier_spec.rb +317 -0
- data/spec/vandalism_detection/configuration_spec.rb +517 -0
- data/spec/vandalism_detection/diff_spec.rb +40 -0
- data/spec/vandalism_detection/edit_spec.rb +137 -0
- data/spec/vandalism_detection/evaluator_spec.rb +671 -0
- data/spec/vandalism_detection/feature_calculator_spec.rb +128 -0
- data/spec/vandalism_detection/features/all_wordlists_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/all_wordlists_impact_spec.rb +58 -0
- data/spec/vandalism_detection/features/anonymity_previous_spec.rb +61 -0
- data/spec/vandalism_detection/features/anonymity_spec.rb +23 -0
- data/spec/vandalism_detection/features/article_size_spec.rb +35 -0
- data/spec/vandalism_detection/features/bad_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/bad_impact_spec.rb +59 -0
- data/spec/vandalism_detection/features/base_spec.rb +49 -0
- data/spec/vandalism_detection/features/biased_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/biased_impact_spec.rb +58 -0
- data/spec/vandalism_detection/features/blanking_spec.rb +38 -0
- data/spec/vandalism_detection/features/character_diversity_spec.rb +35 -0
- data/spec/vandalism_detection/features/character_sequence_spec.rb +37 -0
- data/spec/vandalism_detection/features/comment_bad_frequency_spec.rb +34 -0
- data/spec/vandalism_detection/features/comment_biased_frequency_spec.rb +34 -0
- data/spec/vandalism_detection/features/comment_length_spec.rb +27 -0
- data/spec/vandalism_detection/features/comment_markup_frequency_spec.rb +34 -0
- data/spec/vandalism_detection/features/comment_pronoun_frequency_spec.rb +34 -0
- data/spec/vandalism_detection/features/comment_sex_frequency_spec.rb +34 -0
- data/spec/vandalism_detection/features/comment_vulgarism_frequency_spec.rb +34 -0
- data/spec/vandalism_detection/features/compressibility_spec.rb +42 -0
- data/spec/vandalism_detection/features/contains_base_spec.rb +33 -0
- data/spec/vandalism_detection/features/copyedit_spec.rb +33 -0
- data/spec/vandalism_detection/features/digit_ratio_spec.rb +35 -0
- data/spec/vandalism_detection/features/edits_per_user_spec.rb +49 -0
- data/spec/vandalism_detection/features/emoticons_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/emoticons_impact_spec.rb +51 -0
- data/spec/vandalism_detection/features/frequency_base_spec.rb +26 -0
- data/spec/vandalism_detection/features/impact_base_spec.rb +41 -0
- data/spec/vandalism_detection/features/inserted_character_distribution_spec.rb +46 -0
- data/spec/vandalism_detection/features/inserted_external_links_spec.rb +35 -0
- data/spec/vandalism_detection/features/inserted_internal_links_spec.rb +35 -0
- data/spec/vandalism_detection/features/inserted_size_spec.rb +35 -0
- data/spec/vandalism_detection/features/inserted_words_spec.rb +35 -0
- data/spec/vandalism_detection/features/longest_word_spec.rb +35 -0
- data/spec/vandalism_detection/features/markup_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/markup_impact_spec.rb +59 -0
- data/spec/vandalism_detection/features/non_alphanumeric_ratio_spec.rb +35 -0
- data/spec/vandalism_detection/features/personal_life_spec.rb +26 -0
- data/spec/vandalism_detection/features/pronoun_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/pronoun_impact_spec.rb +59 -0
- data/spec/vandalism_detection/features/removed_all_wordlists_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/removed_bad_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/removed_biased_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/removed_character_distribution_spec.rb +46 -0
- data/spec/vandalism_detection/features/removed_emoticons_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/removed_markup_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/removed_pronoun_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/removed_sex_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/removed_size_spec.rb +35 -0
- data/spec/vandalism_detection/features/removed_vulgarism_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/removed_words_spec.rb +35 -0
- data/spec/vandalism_detection/features/replacement_similarity_spec.rb +44 -0
- data/spec/vandalism_detection/features/reverted_spec.rb +28 -0
- data/spec/vandalism_detection/features/revisions_character_distribution_spec.rb +46 -0
- data/spec/vandalism_detection/features/same_editor_spec.rb +60 -0
- data/spec/vandalism_detection/features/sex_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/sex_impact_spec.rb +59 -0
- data/spec/vandalism_detection/features/size_increment_spec.rb +35 -0
- data/spec/vandalism_detection/features/size_ratio_spec.rb +57 -0
- data/spec/vandalism_detection/features/term_frequency_spec.rb +38 -0
- data/spec/vandalism_detection/features/time_interval_spec.rb +50 -0
- data/spec/vandalism_detection/features/time_of_day_spec.rb +22 -0
- data/spec/vandalism_detection/features/upper_case_ratio_spec.rb +35 -0
- data/spec/vandalism_detection/features/upper_case_words_ratio_spec.rb +37 -0
- data/spec/vandalism_detection/features/upper_to_lower_case_ratio_spec.rb +35 -0
- data/spec/vandalism_detection/features/user_reputation_spec.rb +52 -0
- data/spec/vandalism_detection/features/vulgarism_frequency_spec.rb +36 -0
- data/spec/vandalism_detection/features/vulgarism_impact_spec.rb +58 -0
- data/spec/vandalism_detection/features/weekday_spec.rb +22 -0
- data/spec/vandalism_detection/features/words_increment_spec.rb +35 -0
- data/spec/vandalism_detection/instances_spec.rb +156 -0
- data/spec/vandalism_detection/page_parser_spec.rb +184 -0
- data/spec/vandalism_detection/page_spec.rb +135 -0
- data/spec/vandalism_detection/revision_parser_spec.rb +53 -0
- data/spec/vandalism_detection/revision_spec.rb +115 -0
- data/spec/vandalism_detection/test_dataset_spec.rb +231 -0
- data/spec/vandalism_detection/text_spec.rb +29 -0
- data/spec/vandalism_detection/training_dataset_spec.rb +264 -0
- data/spec/vandalism_detection/wikitext_extractor_spec.rb +72 -0
- data/spec/weka/classifiers/functions/lib_svm_spec.rb +38 -0
- data/spec/weka/classifiers/meta/one_class_classifier_spec.rb +76 -0
- data/spec/weka/classifiers/meta/real_ada_boost_spec.rb +40 -0
- data/spec/weka/classifiers/trees/balanced_random_forest_spec.rb +40 -0
- data/spec/weka/filters/supervised/instance/smote_spec.rb +6 -0
- data/wikipedia-vandalism_detection.gemspec +30 -0
- metadata +512 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature returns whether the edit's is a blanking.
|
8
|
+
# size < 7, based on Mola Velasco 2010 implementation.
|
9
|
+
class Blanking < Base
|
10
|
+
|
11
|
+
BLANKING_THRESHOLD = 7
|
12
|
+
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
old_text_size = edit.old_revision.text.size
|
17
|
+
new_text_size = edit.new_revision.text.size
|
18
|
+
|
19
|
+
blanking = (old_text_size > new_text_size) && (new_text_size < BLANKING_THRESHOLD)
|
20
|
+
blanking ? 1.0 : 0.0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature computes the character diversity of the edit's new revision inserted text.
|
8
|
+
# I.e. how many unique characters are amongst all inserted?
|
9
|
+
#
|
10
|
+
# Random typing leads to less unique characters relative to full length =>
|
11
|
+
class CharacterDiversity < Base
|
12
|
+
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
inserted_letters = edit.inserted_text.scan(/[^\s]/)
|
17
|
+
all_letters_count = inserted_letters.size
|
18
|
+
unique_count = inserted_letters.uniq.size
|
19
|
+
|
20
|
+
all_letters_count ** (1.0 / unique_count)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature computes the length of the longest sequence of the same character in the inserted text.
|
8
|
+
class CharacterSequence < Base
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
sequence_hash = edit.inserted_text.scan(/((.)\2*)/).group_by{ |s, c| s.length }
|
14
|
+
sequence_hash.empty? ? 0 : sequence_hash.max.first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/frequency_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/bad'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes frequency of bad words in the comment of the edit's new revision.
|
9
|
+
class CommentBadFrequency < FrequencyBase
|
10
|
+
|
11
|
+
# Returns the percentage of bad words in the new revision's comment.
|
12
|
+
# Returns 0.0 if text is of zero length.
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
comment = edit.new_revision.comment.clean
|
17
|
+
frequency(comment, WordLists::BAD)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/frequency_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/biased'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes frequency of biased words in the comment of the edit's new revision.
|
9
|
+
class CommentBiasedFrequency < FrequencyBase
|
10
|
+
|
11
|
+
# Returns the percentage of biased words in the new revision's comment.
|
12
|
+
# Returns 0.0 if text is of zero length.
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
comment = edit.new_revision.comment.clean
|
17
|
+
frequency(comment, WordLists::BIASED)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature computes the byte length of the edit's new revision's comment.
|
8
|
+
class CommentLength < Base
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
edit.new_revision.comment.clean.bytesize
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/markup'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes frequency of markup words in the comment of the edit's new revision.
|
9
|
+
class CommentMarkupFrequency < Base
|
10
|
+
|
11
|
+
# Returns the percentage of markup words in the new revision's comment.
|
12
|
+
# Returns 0.0 if text is of zero length.
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
comment = edit.new_revision.comment
|
17
|
+
all_words_count = comment.split.count
|
18
|
+
|
19
|
+
regex = /(#{WordLists::MARKUP.join('|')})/
|
20
|
+
markup_words_count = comment.scan(regex).count
|
21
|
+
|
22
|
+
(all_words_count > 0) ? (markup_words_count.to_f) / (all_words_count.to_f) : 0.0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/frequency_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/pronouns'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes the frequency of pronouns in the comment of the new revision.
|
9
|
+
class CommentPronounFrequency < FrequencyBase
|
10
|
+
|
11
|
+
# Returns the percentage of pronoun words in the new revision's comment.
|
12
|
+
# Returns 0.0 if text is of zero length.
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
comment = edit.new_revision.comment.clean
|
17
|
+
frequency(comment, WordLists::PRONOUNS)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/frequency_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/sex'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes frequency of sex words in the comment of the edit's new revision.
|
9
|
+
class CommentSexFrequency < FrequencyBase
|
10
|
+
|
11
|
+
# Returns the percentage of sex words in the new revision's comment.
|
12
|
+
# Returns 0.0 if text is of zero length.
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
comment = edit.new_revision.comment.clean
|
17
|
+
frequency(comment, WordLists::SEX)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/frequency_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/vulgarism'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes frequency of vulgarism words in the comment of the edit's new revision.
|
9
|
+
class CommentVulgarismFrequency < FrequencyBase
|
10
|
+
|
11
|
+
# Returns the percentage of vulgarism words in the new revision's comment.
|
12
|
+
# Returns 0.0 if text is of zero length.
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
comment = edit.new_revision.comment.clean
|
17
|
+
frequency(comment, WordLists::VULGARISM)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'zlib'
|
3
|
+
require 'wikipedia/vandalism_detection/diff'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature describes compressibility ratio of compressed and uncompressed inserted text.
|
10
|
+
class Compressibility < Base
|
11
|
+
|
12
|
+
# Claculates the compressibility ratio of the inserted text.
|
13
|
+
# Values above 0.5 are higher compressed and therefor can stand for nonsense text as:
|
14
|
+
# 'AAAAAAAAAAAAAAAAAAAhhhhhhhhhhhhhhhh!' etc.
|
15
|
+
def calculate(edit)
|
16
|
+
super
|
17
|
+
|
18
|
+
inserted_text = edit.inserted_text
|
19
|
+
uncompressed_size = inserted_text.bytesize.to_f
|
20
|
+
compressed_size = Zlib::Deflate.deflate(inserted_text).bytesize.to_f
|
21
|
+
|
22
|
+
inserted_text.empty? ? 0.5 : (uncompressed_size / ( compressed_size + uncompressed_size))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
class ContainsBase < Base
|
8
|
+
|
9
|
+
# Returns whether the comment contains the given term.
|
10
|
+
# It returns 0 if term is not included, else 1.
|
11
|
+
def contains(comment, terms)
|
12
|
+
terms = terms.is_a?(Array) ? terms.join('|') : terms
|
13
|
+
(comment =~ /#{terms}/i) ? 1 : 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/contains_base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature returns whether the edit's comment includes reverted key words.
|
8
|
+
class Reverted < ContainsBase
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
contains(edit.new_revision.comment, ['rvt', 'rvv', 'revert'])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature computes the digit to all letters ratio of the edit's new revision inserted text.
|
8
|
+
class DigitRatio < Base
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
text = edit.inserted_text
|
14
|
+
return 0.0 if text.empty?
|
15
|
+
|
16
|
+
all_letters_count = text.scan(/[[:alnum:]]/).size
|
17
|
+
digit_count = text.scan(/[[:digit:]]/).size
|
18
|
+
|
19
|
+
(1.0 + digit_count) / (1.0 + all_letters_count)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
module Wikipedia
|
7
|
+
module VandalismDetection
|
8
|
+
module Features
|
9
|
+
|
10
|
+
# This feature calculates the number of submitted edits by the same editor (IP or ID) as the edit's editor.
|
11
|
+
class EditsPerUser < Base
|
12
|
+
|
13
|
+
# Returns the number of edits the edit's editor made in the same article.
|
14
|
+
# Attention! This is pretty time consuming (~2sec) due to the url request.
|
15
|
+
def calculate(edit)
|
16
|
+
super
|
17
|
+
|
18
|
+
revision = edit.new_revision
|
19
|
+
page = edit.page
|
20
|
+
|
21
|
+
if page && page.id
|
22
|
+
edits_count_from_page(edit)
|
23
|
+
else
|
24
|
+
edits_count_from_api_request(revision)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def edits_count_from_page(edit)
|
31
|
+
edit_revision = edit.new_revision
|
32
|
+
|
33
|
+
previous_count = edit.page.edits.reduce(0) do |count, page_edit|
|
34
|
+
page_revision = page_edit.new_revision
|
35
|
+
count += 1 if page_revision.contributor == edit_revision.contributor &&
|
36
|
+
time_diff_in_sec(page_revision.timestamp, edit_revision.timestamp) < 0
|
37
|
+
count
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def edits_count_from_api_request(revision)
|
42
|
+
xml = Wikipedia::api_request({list: 'usercontribs', ucuser: revision.contributor, ucprop: 'ids|timestamp'})
|
43
|
+
page_item = xml.xpath("//item[@revid='#{revision.id}']").first
|
44
|
+
|
45
|
+
if page_item
|
46
|
+
page_id = page_item.xpath("@pageid").text
|
47
|
+
|
48
|
+
# count only edits before current
|
49
|
+
count = xml.xpath("//item[@pageid='#{page_id}']").reduce(0) do |count, item|
|
50
|
+
time = item.attr('timestamp')
|
51
|
+
count += 1 if time_diff_in_sec(revision.timestamp, time) > 0
|
52
|
+
count
|
53
|
+
end
|
54
|
+
else
|
55
|
+
0
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def time_diff_in_sec(time1, time2)
|
60
|
+
((DateTime.parse(time1) - DateTime.parse(time2)) * 24 * 60 * 60).to_i
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/emoticons'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes frequency of emoticon words in the inserted text.
|
9
|
+
class EmoticonsFrequency < Base
|
10
|
+
|
11
|
+
# Returns the percentage of emoticon words in the inserted text.
|
12
|
+
# Returns 0.0 if inserted clean text is of zero length.
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
inserted_text = edit.inserted_text
|
17
|
+
regex = /(^|\s)(#{WordLists::EMOTICONS.join('|')})(?=\s|$|\Z|[\.,!?]\s|[\.!?]\Z)/
|
18
|
+
|
19
|
+
emoticons_count = inserted_text.scan(regex).flatten.reject { |c| c.size < 2 }.count
|
20
|
+
total_count = inserted_text.split.count
|
21
|
+
|
22
|
+
(total_count > 0) ? (emoticons_count.to_f) / (total_count.to_f) : 0.0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/emoticons'
|
3
|
+
require 'wikipedia/vandalism_detection/text'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature computes impact of emoticons words in the inserted text.
|
10
|
+
class EmoticonsImpact < Base
|
11
|
+
|
12
|
+
def calculate(edit)
|
13
|
+
super
|
14
|
+
|
15
|
+
old_text = edit.old_revision.text
|
16
|
+
new_text = edit.new_revision.text
|
17
|
+
|
18
|
+
regex = /(^|\s)(#{WordLists::EMOTICONS.join('|')})(?=\s|$|\Z|[\.,!?]\s|[\.!?]\Z)/
|
19
|
+
|
20
|
+
old_count = old_text.scan(regex).flatten.reject { |c| c.size < 2 }.count.to_f
|
21
|
+
new_count = new_text.scan(regex).flatten.reject { |c| c.size < 2 }.count.to_f
|
22
|
+
|
23
|
+
no_terms_in_both = (old_count == 0 && new_count == 0)
|
24
|
+
no_terms_in_both ? 0.5 : (old_count / (old_count + new_count))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|