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,28 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/markup'
|
3
|
+
require 'wikipedia/vandalism_detection/text'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature computes the frequency of markup words in the removed text.
|
10
|
+
class RemovedMarkupFrequency < Base
|
11
|
+
|
12
|
+
# Returns the percentage of markup words in the removed text.
|
13
|
+
# Returns 0.0 if cleaned removed text is of zero length.
|
14
|
+
def calculate(edit)
|
15
|
+
super
|
16
|
+
|
17
|
+
text = edit.removed_text
|
18
|
+
all_words_count = edit.removed_words.count
|
19
|
+
|
20
|
+
regex = /(#{WordLists::MARKUP.join('|')})/
|
21
|
+
markup_words_count = text.scan(regex).count
|
22
|
+
|
23
|
+
(all_words_count > 0) ? (markup_words_count.to_f) / (all_words_count.to_f) : 0.0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/frequency_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/pronouns'
|
3
|
+
require 'wikipedia/vandalism_detection/text'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature computes the frequency of pronouns in the removed text.
|
10
|
+
class RemovedPronounFrequency < FrequencyBase
|
11
|
+
|
12
|
+
# Returns the percentage of pronoun words in the removed text.
|
13
|
+
# Returns 0.0 if cleaned removed text is of zero length.
|
14
|
+
def calculate(edit)
|
15
|
+
super
|
16
|
+
|
17
|
+
text = Text.new(edit.removed_words.join("\n")).clean
|
18
|
+
frequency(text, WordLists::PRONOUNS)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/frequency_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/sex'
|
3
|
+
require 'wikipedia/vandalism_detection/text'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature computes the frequency of sex words in the removed text.
|
10
|
+
class RemovedSexFrequency < FrequencyBase
|
11
|
+
|
12
|
+
# Returns the percentage of sex words in the removed text.
|
13
|
+
# Returns 0.0 if cleaned removed text is of zero length.
|
14
|
+
def calculate(edit)
|
15
|
+
super
|
16
|
+
|
17
|
+
text = Text.new(edit.removed_words.join("\n")).clean
|
18
|
+
frequency(text, WordLists::SEX)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature computes the size of removed text in the edit's new revision.
|
8
|
+
class RemovedSize < Base
|
9
|
+
|
10
|
+
# Returns the size of removed character in the new revision.
|
11
|
+
def calculate(edit)
|
12
|
+
super
|
13
|
+
|
14
|
+
size = edit.removed_text.size
|
15
|
+
size >= 0 ? size : 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/frequency_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/vulgarism'
|
3
|
+
require 'wikipedia/vandalism_detection/text'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature computes frequency of vulgarism words in the removed text.
|
10
|
+
class RemovedVulgarismFrequency < FrequencyBase
|
11
|
+
|
12
|
+
# Returns the percentage of vulgarism words in the removed text.
|
13
|
+
# Returns 0.0 if removed clean text is of zero length.
|
14
|
+
def calculate(edit)
|
15
|
+
super
|
16
|
+
|
17
|
+
text = Text.new(edit.removed_words.join("\n")).clean
|
18
|
+
frequency(text, WordLists::VULGARISM)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature computes the number of removed words in the edit's new revision.
|
8
|
+
class RemovedWords < Base
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
edit.removed_words.count
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'wikipedia/vandalism_detection/diff'
|
3
|
+
require 'hotwater'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature computes the similarity of deleted to inserted text.
|
10
|
+
# As similarity measure the Jaro-Winkler distance is used.
|
11
|
+
# See: http://courses.cs.washington.edu/courses/cse590q/04au/papers/Winkler99.pdf
|
12
|
+
class ReplacementSimilarity < Base
|
13
|
+
|
14
|
+
def calculate(edit)
|
15
|
+
super
|
16
|
+
|
17
|
+
::Hotwater.jaro_winkler_distance(edit.removed_text, edit.inserted_text)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
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 'copyedit'.
|
8
|
+
class Copyedit < ContainsBase
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
contains(edit.new_revision.comment, ['copyedit', 'copy edit'])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'wikipedia/vandalism_detection/algorithms'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes the Kullback-Leibler Divergence of the old and new text's character distribution.
|
9
|
+
# The smaller the divergence, the higher the similarity of the distributions and conversely.
|
10
|
+
class RevisionsCharacterDistribution < Base
|
11
|
+
include Algorithms
|
12
|
+
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
kullback_leibler_divergence(edit.old_revision.text, edit.new_revision.text)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature describes whether the contributor of the new revision is the same as the editor
|
8
|
+
# of the old revision.
|
9
|
+
class SameEditor < Base
|
10
|
+
|
11
|
+
def calculate(edit)
|
12
|
+
super
|
13
|
+
|
14
|
+
old_revision = edit.old_revision
|
15
|
+
|
16
|
+
if old_revision.contributor.blank?
|
17
|
+
xml = Wikipedia::api_request({ prop: 'revisions', rvprop: 'user',revids: old_revision.id })
|
18
|
+
contributor = xml.xpath('//rev/@user').text
|
19
|
+
return Features::MISSING_VALUE if contributor.blank?
|
20
|
+
|
21
|
+
old_revision.contributor = contributor
|
22
|
+
end
|
23
|
+
|
24
|
+
(old_revision.contributor == edit.new_revision.contributor) ? 1 : 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/frequency_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/sex'
|
3
|
+
require 'wikipedia/vandalism_detection/text'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature computes frequency of bad words in the inserted text.
|
10
|
+
class SexFrequency < FrequencyBase
|
11
|
+
|
12
|
+
# Returns the percentage of biased words in the inserted text.
|
13
|
+
# Returns 0.0 if inserted clean text is of zero length.
|
14
|
+
def calculate(edit)
|
15
|
+
super
|
16
|
+
|
17
|
+
text = Text.new(edit.inserted_words.join("\n")).clean
|
18
|
+
frequency(text, WordLists::SEX)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/impact_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists/sex'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes the percentage by which the edit increases the number of sex words in the text.
|
9
|
+
class SexImpact < ImpactBase
|
10
|
+
|
11
|
+
def calculate(edit)
|
12
|
+
super
|
13
|
+
old_text = edit.old_revision.text.clean
|
14
|
+
new_text = edit.new_revision.text.clean
|
15
|
+
|
16
|
+
impact(old_text, new_text, WordLists::SEX)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature computes the increment of the edit's revisions text length.
|
8
|
+
class SizeIncrement < Base
|
9
|
+
|
10
|
+
# computation: |new| - |old|
|
11
|
+
def calculate(edit)
|
12
|
+
super
|
13
|
+
|
14
|
+
old_size = edit.old_revision.text.size
|
15
|
+
new_size = edit.new_revision.text.size
|
16
|
+
|
17
|
+
new_size - old_size
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
# This feature computes the ratio of the edit's revisions text length.
|
8
|
+
class SizeRatio < Base
|
9
|
+
|
10
|
+
# Returns the ration of new text length to old text length:
|
11
|
+
# returns 0.0 for empty old revision text,
|
12
|
+
# returns 1.0 for empty new revision text,
|
13
|
+
# returns 0.5 for both revision texts empty or same size
|
14
|
+
# computation: old / old + new
|
15
|
+
def calculate(edit)
|
16
|
+
super
|
17
|
+
|
18
|
+
old_size = edit.old_revision.text.size.to_f
|
19
|
+
new_size = edit.new_revision.text.size.to_f
|
20
|
+
|
21
|
+
(old_size == 0 && new_size == 0) ? 0.5 : old_size / (old_size + new_size)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'wikipedia/vandalism_detection/text'
|
3
|
+
require 'wikipedia/vandalism_detection/diff'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature computes average frequency of words inserted in the new revision
|
10
|
+
# relative to the words in the old revision.
|
11
|
+
class TermFrequency < FrequencyBase
|
12
|
+
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
new_text = edit.new_revision.text
|
17
|
+
inserted_terms = Text.new(edit.inserted_words.join("\n")).clean.gsub(/[^\w\s]/, '').split.uniq
|
18
|
+
summed_frequencies = inserted_terms.reduce(0) { |count, term| count + frequency(new_text.clean, term) }
|
19
|
+
|
20
|
+
(inserted_terms.count > 0) ? (summed_frequencies / inserted_terms.count) : 0.0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes the time interval in days between old and new revision.
|
9
|
+
class TimeInterval < Base
|
10
|
+
|
11
|
+
def calculate(edit)
|
12
|
+
super
|
13
|
+
|
14
|
+
new_time = DateTime.parse(edit.new_revision.timestamp)
|
15
|
+
|
16
|
+
if edit.old_revision.timestamp.blank?
|
17
|
+
xml = Wikipedia::api_request({ prop: 'revisions', rvprop: 'timestamp', revids: edit.old_revision.id })
|
18
|
+
timestamp = xml.xpath('//rev/@timestamp').text
|
19
|
+
return Features::MISSING_VALUE if timestamp.blank?
|
20
|
+
|
21
|
+
old_time = DateTime.parse(timestamp)
|
22
|
+
else
|
23
|
+
old_time = DateTime.parse(edit.old_revision.timestamp)
|
24
|
+
end
|
25
|
+
|
26
|
+
(new_time - old_time).to_f.abs
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature calculates the time of day of new revision edit as decimal value .
|
9
|
+
class TimeOfDay < Base
|
10
|
+
|
11
|
+
def calculate(edit)
|
12
|
+
super
|
13
|
+
|
14
|
+
timestamp = edit.new_revision.timestamp
|
15
|
+
time = DateTime.parse(timestamp)
|
16
|
+
|
17
|
+
time.hour.to_f + (time.min / 60.0) + (time.sec / 360.0)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
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 uppercase to all letters ratio of the edit's new revision inserted text.
|
8
|
+
class UpperCaseRatio < Base
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
text = edit.inserted_text
|
14
|
+
return 0.0 if text.empty?
|
15
|
+
|
16
|
+
uppercase_count = text.scan(/[[:upper:]]/).size
|
17
|
+
all_letters_count = text.scan(/[[:alpha:]]/).size
|
18
|
+
|
19
|
+
(1.0 + uppercase_count) / (1.0 + all_letters_count)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|