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,20 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
class FrequencyBase < Base
|
8
|
+
|
9
|
+
# Returns the ratio of given numbers.
|
10
|
+
# For frequency calculation it returns 0.0 if total_count is zero.
|
11
|
+
def frequency(text, terms)
|
12
|
+
total_count = text.split.count
|
13
|
+
term_count = count terms, in: text
|
14
|
+
|
15
|
+
(total_count > 0) ? (term_count.to_f) / (total_count.to_f) : 0.0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
|
3
|
+
module Wikipedia
|
4
|
+
module VandalismDetection
|
5
|
+
module Features
|
6
|
+
|
7
|
+
class ImpactBase < Base
|
8
|
+
|
9
|
+
# Returns the ratio of given text's terms count.
|
10
|
+
# For impact calculation it returns 0.5 if number of terms in old text is zero.
|
11
|
+
def impact(old_text, new_text, terms)
|
12
|
+
old_terms_count = (count terms, in: old_text).to_f
|
13
|
+
new_terms_count = (count terms, in: new_text).to_f
|
14
|
+
|
15
|
+
no_terms_in_both = (old_terms_count == 0 && new_terms_count == 0)
|
16
|
+
no_terms_in_both ? 0.5 : (old_terms_count / (old_terms_count + new_terms_count))
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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 inserted text's character distribution
|
9
|
+
# relative to the character distribution of the old revision's text.
|
10
|
+
# The smaller the divergence, the higher the similarity of the distributions and conversely.
|
11
|
+
class InsertedCharacterDistribution < Base
|
12
|
+
include Algorithms
|
13
|
+
|
14
|
+
def calculate(edit)
|
15
|
+
super
|
16
|
+
|
17
|
+
kullback_leibler_divergence(edit.old_revision.text, edit.inserted_text)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
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 inserted external links [http://example.com].
|
8
|
+
class InsertedExternalLinks < Base
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
edit.inserted_text.scan(/\[?(https?|ftp)\s?:\s?\/\/[^\s\/$.?#].[^\s]*]?/i).count
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
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 inserted internal links [[link]].
|
8
|
+
class InsertedInternalLinks < Base
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
edit.inserted_text.scan(/\[{2}([^\[].*?)\]{2}/).count
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
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 inserted text in the edit's new revision.
|
8
|
+
class InsertedSize < Base
|
9
|
+
|
10
|
+
# Returns the size of inserted character in the new revision.
|
11
|
+
def calculate(edit)
|
12
|
+
super
|
13
|
+
|
14
|
+
size = edit.inserted_text.size
|
15
|
+
size >= 0 ? size : 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
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 inserted words in the edit's new revision.
|
8
|
+
class InsertedWords < Base
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
edit.inserted_words.count
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/base'
|
2
|
+
require 'wikipedia/vandalism_detection/text'
|
3
|
+
|
4
|
+
module Wikipedia
|
5
|
+
module VandalismDetection
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This feature computes the length of the longest word in the inserted text.
|
9
|
+
class LongestWord < Base
|
10
|
+
|
11
|
+
def calculate(edit)
|
12
|
+
super
|
13
|
+
|
14
|
+
sequence_hash = Text.new(edit.inserted_words.join("\n")).clean.split(/[\b\s+,;:]/).group_by(&:length)
|
15
|
+
sequence_hash.empty? ? 0 : sequence_hash.max.first
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
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 bad words in the inserted text.
|
9
|
+
class MarkupFrequency < Base
|
10
|
+
|
11
|
+
# Returns the percentage of markup related 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
|
+
text = edit.inserted_text
|
17
|
+
all_words_count = edit.inserted_words.count
|
18
|
+
|
19
|
+
regex = /(#{WordLists::MARKUP.join('|')})/
|
20
|
+
markup_words_count = text.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,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 the percentage by which the edit increases the number of markup words in the text.
|
9
|
+
class MarkupImpact < Base
|
10
|
+
|
11
|
+
def calculate(edit)
|
12
|
+
super
|
13
|
+
|
14
|
+
old_text = edit.old_revision.text
|
15
|
+
new_text = edit.new_revision.text
|
16
|
+
regex = /(#{WordLists::MARKUP.join('|')})/
|
17
|
+
|
18
|
+
old_markup_count = old_text.scan(regex).count.to_f
|
19
|
+
new_markup_count = new_text.scan(regex).count.to_f
|
20
|
+
|
21
|
+
no_terms_in_both = (old_markup_count == 0 && new_markup_count == 0)
|
22
|
+
no_terms_in_both ? 0.5 : (old_markup_count / (old_markup_count + new_markup_count))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
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 non-alphanumeric to all letters ratio of the edit's new revision inserted text.
|
8
|
+
class NonAlphanumericRatio < Base
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
text = edit.inserted_text
|
14
|
+
return 0.0 if text.empty?
|
15
|
+
|
16
|
+
non_alpha_count = text.scan(/[^a-zA-Z0-9\s]/).size
|
17
|
+
all_letters_count = text.scan(/[^\s]/).size
|
18
|
+
|
19
|
+
(1.0 + non_alpha_count) / (1.0 + all_letters_count)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
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 'personal life'.
|
8
|
+
class PersonalLife < ContainsBase
|
9
|
+
|
10
|
+
def calculate(edit)
|
11
|
+
super
|
12
|
+
|
13
|
+
contains(edit.new_revision.comment, 'personal life')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
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 insetred text.
|
10
|
+
class PronounFrequency < FrequencyBase
|
11
|
+
|
12
|
+
# Returns the percentage of pronoun 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::PRONOUNS)
|
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/pronouns'
|
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 pronouns in the text.
|
9
|
+
class PronounImpact < 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::PRONOUNS)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'wikipedia/vandalism_detection/features/frequency_base'
|
2
|
+
require 'wikipedia/vandalism_detection/word_lists'
|
3
|
+
require 'wikipedia/vandalism_detection/text'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature computes frequency of all wordlists words in the removed text.
|
10
|
+
class RemovedAllWordlistsFrequency < FrequencyBase
|
11
|
+
|
12
|
+
# Returns the percentage of wordlists 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.all)
|
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 bad words in the removed text.
|
10
|
+
class RemovedBadFrequency < FrequencyBase
|
11
|
+
|
12
|
+
# Returns the percentage of bad 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::BAD)
|
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/biased'
|
3
|
+
require 'wikipedia/vandalism_detection/text'
|
4
|
+
|
5
|
+
module Wikipedia
|
6
|
+
module VandalismDetection
|
7
|
+
module Features
|
8
|
+
|
9
|
+
# This feature computes frequency of biased words in the removed text.
|
10
|
+
class RemovedBiasedFrequency < FrequencyBase
|
11
|
+
|
12
|
+
# Returns the percentage of biased 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::BIASED)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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 removed text's character distribution
|
9
|
+
# relative to the character distribution of the new revision's text.
|
10
|
+
# The smaller the divergence, the higher the similarity of the distributions and conversely.
|
11
|
+
class RemovedCharacterDistribution < Base
|
12
|
+
include Algorithms
|
13
|
+
|
14
|
+
def calculate(edit)
|
15
|
+
super
|
16
|
+
|
17
|
+
kullback_leibler_divergence(edit.new_revision.text, edit.removed_text)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
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 the frequency of emoticon words in the removed text.
|
9
|
+
class RemovedEmoticonsFrequency < Base
|
10
|
+
|
11
|
+
# Returns the percentage of markup words in the removed text.
|
12
|
+
# Returns 0.0 if cleaned removed text is of zero length.
|
13
|
+
def calculate(edit)
|
14
|
+
super
|
15
|
+
|
16
|
+
removed_text = edit.removed_text
|
17
|
+
regex = /(^|\s)(#{WordLists::EMOTICONS.join('|')})(?=\s|$|\Z|[\.,!?]\s|[\.!?]\Z)/
|
18
|
+
|
19
|
+
emoticons_count = removed_text.scan(regex).flatten.reject { |c| c.size < 2 }.count
|
20
|
+
total_count = removed_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
|