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,128 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wikipedia::VandalismDetection::FeatureCalculator do
|
4
|
+
|
5
|
+
it "raises NoFeaturesConfiguredError when no features are configured" do
|
6
|
+
configuration = Wikipedia::VandalismDetection::Configuration.send(:new)
|
7
|
+
configuration.instance_variable_set :@features, nil
|
8
|
+
|
9
|
+
use_configuration(configuration)
|
10
|
+
|
11
|
+
expect { Wikipedia::VandalismDetection::FeatureCalculator.new }.to raise_error \
|
12
|
+
Wikipedia::VandalismDetection::FeaturesNotConfiguredError
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
use_test_configuration
|
17
|
+
@calculator = Wikipedia::VandalismDetection::FeatureCalculator.new
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe "#calculate_features_for" do
|
22
|
+
before do
|
23
|
+
@edit = build :edit
|
24
|
+
end
|
25
|
+
|
26
|
+
it { should respond_to :calculate_features_for }
|
27
|
+
|
28
|
+
it "takes an edit as parameter" do
|
29
|
+
expect { @calculator.calculate_features_for(@edit) }.not_to raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises an error if called with wrong parameter type" do
|
33
|
+
revision = build :empty_revision
|
34
|
+
expect { @calculator.calculate_features_for(revision) }.to raise_error ArgumentError
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns an array" do
|
38
|
+
@calculator.calculate_features_for(@edit).should be_an(Array)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the computed feature values" do
|
42
|
+
feature_values = @calculator.calculate_features_for(@edit)
|
43
|
+
expect( feature_values.select{ |value| value.is_a? Numeric }).to eq feature_values
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns the right number of feature values" do
|
47
|
+
expect(@calculator.calculate_features_for(@edit).count).to eq @calculator.used_features.count
|
48
|
+
end
|
49
|
+
|
50
|
+
it "uses the cleaned up text if revision contains a #REDIRECT" do
|
51
|
+
config = Wikipedia::VandalismDetection.configuration
|
52
|
+
redirect_text = Wikipedia::VandalismDetection::Text.new "#REDIRECT [[Redirect page]]"
|
53
|
+
old_revision_redirect = build(:old_revision, text: redirect_text)
|
54
|
+
new_revision_redirect = build(:new_revision, text: redirect_text)
|
55
|
+
old_revision = build(:old_revision)
|
56
|
+
new_revision = build(:new_revision)
|
57
|
+
|
58
|
+
edit_redirect_1 = Wikipedia::VandalismDetection::Edit.new(old_revision_redirect, new_revision)
|
59
|
+
edit_redirect_2 = Wikipedia::VandalismDetection::Edit.new(old_revision, new_revision_redirect)
|
60
|
+
|
61
|
+
expect(@calculator.calculate_features_for(edit_redirect_1).count).to eq config.features.count
|
62
|
+
expect(@calculator.calculate_features_for(edit_redirect_2).count).to eq config.features.count
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns an array holding -1 for not extractable texts in either revision" do
|
66
|
+
configuration = Wikipedia::VandalismDetection::Configuration.instance
|
67
|
+
configuration.instance_variable_set :@features, ['all wordlists impact']
|
68
|
+
|
69
|
+
use_configuration(configuration)
|
70
|
+
calculator = Wikipedia::VandalismDetection::FeatureCalculator.new
|
71
|
+
|
72
|
+
unparsable_wiki_text = Wikipedia::VandalismDetection::Text.new "[[Image:img.jpg|\n{|\n|-\n|||| |}"
|
73
|
+
|
74
|
+
old_revision_unparsable = build(:old_revision, text: unparsable_wiki_text)
|
75
|
+
new_revision_unparsable = build(:new_revision, text: unparsable_wiki_text)
|
76
|
+
|
77
|
+
old_revision = build(:old_revision)
|
78
|
+
new_revision = build(:new_revision)
|
79
|
+
|
80
|
+
edit_1 = Wikipedia::VandalismDetection::Edit.new(old_revision_unparsable, new_revision)
|
81
|
+
edit_2 = Wikipedia::VandalismDetection::Edit.new(old_revision, new_revision_unparsable)
|
82
|
+
|
83
|
+
expect(calculator.calculate_features_for(edit_1)).to include Wikipedia::VandalismDetection::Features::MISSING_VALUE
|
84
|
+
expect(calculator.calculate_features_for(edit_2)).to include Wikipedia::VandalismDetection::Features::MISSING_VALUE
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#claculate_feature_for" do
|
89
|
+
before do
|
90
|
+
@edit = build :edit
|
91
|
+
@feature_name = "anonymity"
|
92
|
+
@random_number = rand(1000)
|
93
|
+
Wikipedia::VandalismDetection::Features::Anonymity.any_instance.stub(calculate: @random_number)
|
94
|
+
end
|
95
|
+
|
96
|
+
it { should respond_to :calculate_feature_for }
|
97
|
+
|
98
|
+
it "takes an edit and feature name as parameter" do
|
99
|
+
expect { @calculator.calculate_feature_for(@edit, @feature_name) }.not_to raise_error
|
100
|
+
end
|
101
|
+
|
102
|
+
it "raises an error if called with wrong parameter type edit" do
|
103
|
+
revision = build :empty_revision
|
104
|
+
expect { @calculator.calculate_feature_for(revision, @feature_name) }.to raise_error ArgumentError
|
105
|
+
end
|
106
|
+
|
107
|
+
it "raises an error if called with wrong parameter type feature name" do
|
108
|
+
revision = build :empty_revision
|
109
|
+
expect { @calculator.calculate_feature_for(@edit, revision) }.to raise_error ArgumentError
|
110
|
+
end
|
111
|
+
|
112
|
+
it "returns a Numeric" do
|
113
|
+
expect(@calculator.calculate_feature_for(@edit, @feature_name)).to be_a Numeric
|
114
|
+
end
|
115
|
+
|
116
|
+
it "returns the value calculated by the feature class" do
|
117
|
+
expect(@calculator.calculate_feature_for(@edit, @feature_name)).to eq @random_number
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#used_features" do
|
122
|
+
it { should respond_to :used_features }
|
123
|
+
|
124
|
+
it "returns an array of the features defined in the config feature.yml" do
|
125
|
+
expect(@calculator.used_features.sort).to eq Wikipedia::VandalismDetection.configuration.features.sort
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wikipedia::VandalismDetection::Features::AllWordlistsFrequency do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@feature = Wikipedia::VandalismDetection::Features::AllWordlistsFrequency.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_a Wikipedia::VandalismDetection::Features::FrequencyBase }
|
10
|
+
|
11
|
+
describe "#calculate" do
|
12
|
+
|
13
|
+
it "returns the inserted number of all wordlists words relative to all inserted words count" do
|
14
|
+
# inserted: total 8 words, 1 vulgarism, 1 biased, 2 pronouns = 4 bad
|
15
|
+
old_text = Wikipedia::VandalismDetection::Text.new 'Your old shit. '
|
16
|
+
new_text = Wikipedia::VandalismDetection::Text.new 'Your old shit. Fuck you great, you and all the others.'
|
17
|
+
|
18
|
+
old_revision = build(:old_revision, text: old_text)
|
19
|
+
new_revision = build(:new_revision, text: new_text)
|
20
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
21
|
+
|
22
|
+
expect(@feature.calculate(edit)).to eq 4.0 / 8.0
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns 0.0 on empty clean inserted text" do
|
26
|
+
old_text = Wikipedia::VandalismDetection::Text.new 'Your old shit. '
|
27
|
+
new_text = Wikipedia::VandalismDetection::Text.new 'Your old shit. {{speedy deletion}}'
|
28
|
+
|
29
|
+
old_revision = build(:old_revision, text: old_text)
|
30
|
+
new_revision = build(:new_revision, text: new_text)
|
31
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
32
|
+
|
33
|
+
expect(@feature.calculate(edit)).to eq 0.0
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wikipedia::VandalismDetection::Features::AllWordlistsImpact do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@feature = Wikipedia::VandalismDetection::Features::AllWordlistsImpact.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_a Wikipedia::VandalismDetection::Features::ImpactBase }
|
10
|
+
|
11
|
+
describe "#calculate" do
|
12
|
+
|
13
|
+
it "returns the impact of all wordlists words of the edit's new revision text" do
|
14
|
+
# 1 vulgarism, 2 pronouns, 0 biased = 3 bad
|
15
|
+
old_text = Wikipedia::VandalismDetection::Text.new "Fuck you, you and all the others"
|
16
|
+
# 3 vulgarism, 3 pronouns, 1 biased = 7 bad
|
17
|
+
new_text = Wikipedia::VandalismDetection::Text.new "Fuck you great, fuck you, you and all the others sluts"
|
18
|
+
|
19
|
+
old_revision = build(:old_revision, text: old_text)
|
20
|
+
new_revision = build(:new_revision, text: new_text)
|
21
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
22
|
+
|
23
|
+
expect(@feature.calculate(edit)).to eq 3.0 / (3.0 + 7.0)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns 0.5 on both no terms in text revisions" do
|
27
|
+
text = Wikipedia::VandalismDetection::Text.new "{{speedy deletion}}"
|
28
|
+
|
29
|
+
old_revision = build(:old_revision, text: text)
|
30
|
+
new_revision = build(:new_revision, text: text)
|
31
|
+
edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
|
32
|
+
|
33
|
+
expect(@feature.calculate(edit)).to eq 0.5
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns 0.0 on emtpy clean text of old revision" do
|
37
|
+
old_text = Wikipedia::VandalismDetection::Text.new "{{speedy deletion}}"
|
38
|
+
new_text = Wikipedia::VandalismDetection::Text.new "fuck"
|
39
|
+
|
40
|
+
old_revision = build(:old_revision, text: old_text)
|
41
|
+
new_revision = build(:new_revision, text: new_text)
|
42
|
+
edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
|
43
|
+
|
44
|
+
expect(@feature.calculate(edit)).to eq 0.0
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns 1.0 on emtpy clean text of new revision" do
|
48
|
+
old_text = Wikipedia::VandalismDetection::Text.new "fuck"
|
49
|
+
new_text = Wikipedia::VandalismDetection::Text.new "{{speedy deletion}}"
|
50
|
+
|
51
|
+
old_revision = build(:old_revision, text: old_text)
|
52
|
+
new_revision = build(:new_revision, text: new_text)
|
53
|
+
edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
|
54
|
+
|
55
|
+
expect(@feature.calculate(edit)).to eq 1.0
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wikipedia::VandalismDetection::Features::AnonymityPrevious do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@feature = Wikipedia::VandalismDetection::Features::AnonymityPrevious.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_a Wikipedia::VandalismDetection::Features::Base }
|
10
|
+
|
11
|
+
describe "#calculate" do
|
12
|
+
|
13
|
+
context "both contributors are given" do
|
14
|
+
it "return 1.0 in case of an registered previous editor" do
|
15
|
+
old_revision = build(:old_revision, contributor: 'Peter')
|
16
|
+
new_revision = build(:new_revision)
|
17
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
18
|
+
|
19
|
+
expect(@feature.calculate(edit)).to eq 1
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns 0.0 in case of an anonymous previous editor" do
|
23
|
+
old_revision = build(:old_revision, contributor: '137.163.16.199')
|
24
|
+
new_revision = build(:new_revision)
|
25
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
26
|
+
|
27
|
+
expect(@feature.calculate(edit)).to eq 0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "previous contributor not given" do
|
32
|
+
it "requests the user from Wikipedia API and returns 1 in case of a registered previous editor" do
|
33
|
+
old_revision = build(:old_revision, id: '324557983', contributor: nil)
|
34
|
+
new_revision = build(:new_revision, id: '329962649', parent_id: '324557983', contributor: 'Tomaxer')
|
35
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
36
|
+
|
37
|
+
expect(@feature.calculate(edit)).to eq 1
|
38
|
+
end
|
39
|
+
|
40
|
+
it "requests the user from Wikipedia API and returns 0 in case of an anonymous previous editor" do # also same editor!
|
41
|
+
old_revision = build(:old_revision, id: '328774110', contributor: nil)
|
42
|
+
new_revision = build(:new_revision, id: '328774035', parent_id: '328774110')
|
43
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
44
|
+
|
45
|
+
expect(@feature.calculate(edit)).to eq 0
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns missing if old reivision is not available anymore" do
|
49
|
+
# to get api call, see:
|
50
|
+
# https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=timestamp&revids=325218985
|
51
|
+
# <rev revid="325218985"/>
|
52
|
+
|
53
|
+
old_revision = build(:old_revision, id: '325218985', contributor: nil)
|
54
|
+
new_revision = build(:new_revision, id: '326980599', parent_id: '325218985')
|
55
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
56
|
+
|
57
|
+
expect(@feature.calculate(edit)).to eq Wikipedia::VandalismDetection::Features::MISSING_VALUE
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wikipedia::VandalismDetection::Features::Anonymity do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@feature = Wikipedia::VandalismDetection::Features::Anonymity.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_a Wikipedia::VandalismDetection::Features::Base }
|
10
|
+
|
11
|
+
describe "#calculate" do
|
12
|
+
|
13
|
+
it "return 1.0 in case of an registered editor" do
|
14
|
+
@edit = build :edit, new_revision: build(:registered_revision)
|
15
|
+
expect(@feature.calculate(@edit)).to eq 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns 0.0 in case of an anonymous editor" do
|
19
|
+
@edit = build :edit, new_revision: build(:anonymous_revision)
|
20
|
+
expect(@feature.calculate(@edit)).to eq 0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wikipedia::VandalismDetection::Features::ArticleSize do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@feature = Wikipedia::VandalismDetection::Features::ArticleSize.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_a Wikipedia::VandalismDetection::Features::Base }
|
10
|
+
|
11
|
+
describe "#calculate" do
|
12
|
+
|
13
|
+
it "returns the size of the edit's new revisions" do
|
14
|
+
old_revision_text = Wikipedia::VandalismDetection::Text.new '123'
|
15
|
+
new_revision_text = Wikipedia::VandalismDetection::Text.new '123 456789' # size 10 (with spaces)
|
16
|
+
|
17
|
+
old_revision = build(:old_revision, text: old_revision_text)
|
18
|
+
new_revision = build(:new_revision, text: new_revision_text)
|
19
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
20
|
+
|
21
|
+
expect(@feature.calculate(edit)).to eq 10
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns 0 if the edit's new revisions is empty" do
|
25
|
+
old_revision_text = Wikipedia::VandalismDetection::Text.new '123'
|
26
|
+
new_revision_text = Wikipedia::VandalismDetection::Text.new '' # size 0
|
27
|
+
|
28
|
+
old_revision = build(:old_revision, text: old_revision_text)
|
29
|
+
new_revision = build(:new_revision, text: new_revision_text)
|
30
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
31
|
+
|
32
|
+
expect(@feature.calculate(edit)).to eq 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wikipedia::VandalismDetection::Features::BadFrequency do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@feature = Wikipedia::VandalismDetection::Features::BadFrequency.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_a Wikipedia::VandalismDetection::Features::FrequencyBase }
|
10
|
+
|
11
|
+
describe "#calculate" do
|
12
|
+
|
13
|
+
it "returns the number of vulgarism words relative to all words count" do
|
14
|
+
# total 6 words, 3 bad
|
15
|
+
old_text = Wikipedia::VandalismDetection::Text.new 'Old whatever.'
|
16
|
+
new_text = Wikipedia::VandalismDetection::Text.new "Old whatever. New ugly contents. Hi, gotta fun."
|
17
|
+
|
18
|
+
old_revision = build(:old_revision, text: old_text)
|
19
|
+
new_revision = build(:new_revision, text: new_text)
|
20
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
21
|
+
|
22
|
+
expect(@feature.calculate(edit)).to eq 3.0 / 6.0
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns 0.0 on emtpy clean text revisions" do
|
26
|
+
old_text = Wikipedia::VandalismDetection::Text.new 'Old guy.'
|
27
|
+
new_text = Wikipedia::VandalismDetection::Text.new "Old guy. {{speedy deletion}}"
|
28
|
+
|
29
|
+
old_revision = build(:old_revision, text: old_text)
|
30
|
+
new_revision = build(:new_revision, text: new_text)
|
31
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
32
|
+
|
33
|
+
expect(@feature.calculate(edit)).to eq 0.0
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wikipedia::VandalismDetection::Features::BadImpact do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@feature = Wikipedia::VandalismDetection::Features::BadImpact.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should be_a Wikipedia::VandalismDetection::Features::ImpactBase }
|
10
|
+
|
11
|
+
describe "#calculate" do
|
12
|
+
|
13
|
+
it "returns the impact of bad words of the edit's new revision text" do
|
14
|
+
# 3 bad words
|
15
|
+
old_text = Wikipedia::VandalismDetection::Text.new "Hi, old text 666, dont know"
|
16
|
+
|
17
|
+
# 4 bad words
|
18
|
+
new_text = Wikipedia::VandalismDetection::Text.new "Hi, new text dosent, whatever, guy"
|
19
|
+
|
20
|
+
old_revision = build(:old_revision, text: old_text)
|
21
|
+
new_revision = build(:new_revision, text: new_text)
|
22
|
+
edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
|
23
|
+
|
24
|
+
expect(@feature.calculate(edit)).to eq 3.0 / (3.0 + 4.0)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns 0.5 on both no terms in text revisions" do
|
28
|
+
text = Wikipedia::VandalismDetection::Text.new "{{speedy deletion}}"
|
29
|
+
|
30
|
+
old_revision = build(:old_revision, text: text)
|
31
|
+
new_revision = build(:new_revision, text: text)
|
32
|
+
edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
|
33
|
+
|
34
|
+
expect(@feature.calculate(edit)).to eq 0.5
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns 0.0 on emtpy clean text of old revision" do
|
38
|
+
old_text = Wikipedia::VandalismDetection::Text.new "{{speedy deletion}}"
|
39
|
+
new_text = Wikipedia::VandalismDetection::Text.new "Guy"
|
40
|
+
|
41
|
+
old_revision = build(:old_revision, text: old_text)
|
42
|
+
new_revision = build(:new_revision, text: new_text)
|
43
|
+
edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
|
44
|
+
|
45
|
+
expect(@feature.calculate(edit)).to eq 0.0
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns 1.0 on emtpy clean text of new revision" do
|
49
|
+
old_text = Wikipedia::VandalismDetection::Text.new "Guy"
|
50
|
+
new_text = Wikipedia::VandalismDetection::Text.new "{{speedy deletion}}"
|
51
|
+
|
52
|
+
old_revision = build(:old_revision, text: old_text)
|
53
|
+
new_revision = build(:new_revision, text: new_text)
|
54
|
+
edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
|
55
|
+
|
56
|
+
expect(@feature.calculate(edit)).to eq 1.0
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wikipedia::VandalismDetection::Features::Base do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@feature = Wikipedia::VandalismDetection::Features::Base.new
|
7
|
+
@edit = build :edit
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#count" do
|
11
|
+
|
12
|
+
before do
|
13
|
+
@text = "I, you: i will help You"
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should respond_to(:count).with(2).arguments }
|
17
|
+
|
18
|
+
it "raises an error if option :in is not defined" do
|
19
|
+
expect { @feature.count([:i, :you], from: @text) }.to raise_error ArgumentError
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises an error if terms is not an Array or String" do
|
23
|
+
expect { @feature.count({term: "You"}, in: @text) }.to raise_error ArgumentError
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the number of terms in the given text found with the given term array" do
|
27
|
+
terms = [:i, :you]
|
28
|
+
expect(@feature.count(terms, in: @text)).to eq 4
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns the number of terms in the given text found with the given single term" do
|
32
|
+
expect(@feature.count("You", in: @text)).to eq 2
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
describe "#calculate" do
|
38
|
+
|
39
|
+
it { should respond_to :calculate }
|
40
|
+
|
41
|
+
it "takes an Wikipedia::Edit as parameter" do
|
42
|
+
expect { @feature.calculate(@edit) }.not_to raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it "raises an ArgumentError if param is no Wikipedia::Edit" do
|
46
|
+
expect { @feature.calculate("string") }.to raise_error
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|