wikipedia-vandalism_detection 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE.txt +4 -0
  5. data/README.md +265 -0
  6. data/Rakefile +12 -0
  7. data/lib/java/LibSVM.jar +0 -0
  8. data/lib/java/SMOTE.jar +0 -0
  9. data/lib/java/balancedRandomForest.jar +0 -0
  10. data/lib/java/diffutils-1.3.0.jar +0 -0
  11. data/lib/java/libsvm.jar +0 -0
  12. data/lib/java/oneClassClassifier.jar +0 -0
  13. data/lib/java/realAdaBoost.jar +0 -0
  14. data/lib/java/swc-engine-1.1.0-jar-with-dependencies.jar +0 -0
  15. data/lib/java/sweble-wikitext-extractor.jar +0 -0
  16. data/lib/weka/classifiers/functions/lib_svm.rb +15 -0
  17. data/lib/weka/classifiers/meta/one_class_classifier.rb +25 -0
  18. data/lib/weka/classifiers/meta/real_ada_boost.rb +17 -0
  19. data/lib/weka/classifiers/trees/balanced_random_forest.rb +18 -0
  20. data/lib/weka/filters/supervised/instance/smote.rb +22 -0
  21. data/lib/wikipedia.rb +51 -0
  22. data/lib/wikipedia/vandalism_detection.rb +30 -0
  23. data/lib/wikipedia/vandalism_detection/algorithms.rb +18 -0
  24. data/lib/wikipedia/vandalism_detection/algorithms/kullback_leibler_divergence.rb +69 -0
  25. data/lib/wikipedia/vandalism_detection/classifier.rb +186 -0
  26. data/lib/wikipedia/vandalism_detection/configuration.rb +321 -0
  27. data/lib/wikipedia/vandalism_detection/diff.rb +27 -0
  28. data/lib/wikipedia/vandalism_detection/edit.rb +75 -0
  29. data/lib/wikipedia/vandalism_detection/evaluator.rb +606 -0
  30. data/lib/wikipedia/vandalism_detection/exceptions.rb +40 -0
  31. data/lib/wikipedia/vandalism_detection/feature_calculator.rb +89 -0
  32. data/lib/wikipedia/vandalism_detection/features.rb +67 -0
  33. data/lib/wikipedia/vandalism_detection/features/all_wordlists_frequency.rb +23 -0
  34. data/lib/wikipedia/vandalism_detection/features/all_wordlists_impact.rb +22 -0
  35. data/lib/wikipedia/vandalism_detection/features/anonymity.rb +19 -0
  36. data/lib/wikipedia/vandalism_detection/features/anonymity_previous.rb +29 -0
  37. data/lib/wikipedia/vandalism_detection/features/article_size.rb +18 -0
  38. data/lib/wikipedia/vandalism_detection/features/bad_frequency.rb +23 -0
  39. data/lib/wikipedia/vandalism_detection/features/bad_impact.rb +21 -0
  40. data/lib/wikipedia/vandalism_detection/features/base.rb +54 -0
  41. data/lib/wikipedia/vandalism_detection/features/biased_frequency.rb +23 -0
  42. data/lib/wikipedia/vandalism_detection/features/biased_impact.rb +22 -0
  43. data/lib/wikipedia/vandalism_detection/features/blanking.rb +25 -0
  44. data/lib/wikipedia/vandalism_detection/features/character_diversity.rb +25 -0
  45. data/lib/wikipedia/vandalism_detection/features/character_sequence.rb +19 -0
  46. data/lib/wikipedia/vandalism_detection/features/comment_bad_frequency.rb +22 -0
  47. data/lib/wikipedia/vandalism_detection/features/comment_biased_frequency.rb +22 -0
  48. data/lib/wikipedia/vandalism_detection/features/comment_length.rb +17 -0
  49. data/lib/wikipedia/vandalism_detection/features/comment_markup_frequency.rb +27 -0
  50. data/lib/wikipedia/vandalism_detection/features/comment_pronoun_frequency.rb +22 -0
  51. data/lib/wikipedia/vandalism_detection/features/comment_sex_frequency.rb +22 -0
  52. data/lib/wikipedia/vandalism_detection/features/comment_vulgarism_frequency.rb +22 -0
  53. data/lib/wikipedia/vandalism_detection/features/compressibility.rb +27 -0
  54. data/lib/wikipedia/vandalism_detection/features/contains_base.rb +18 -0
  55. data/lib/wikipedia/vandalism_detection/features/copyedit.rb +18 -0
  56. data/lib/wikipedia/vandalism_detection/features/digit_ratio.rb +24 -0
  57. data/lib/wikipedia/vandalism_detection/features/edits_per_user.rb +65 -0
  58. data/lib/wikipedia/vandalism_detection/features/emoticons_frequency.rb +27 -0
  59. data/lib/wikipedia/vandalism_detection/features/emoticons_impact.rb +29 -0
  60. data/lib/wikipedia/vandalism_detection/features/frequency_base.rb +20 -0
  61. data/lib/wikipedia/vandalism_detection/features/impact_base.rb +22 -0
  62. data/lib/wikipedia/vandalism_detection/features/inserted_character_distribution.rb +22 -0
  63. data/lib/wikipedia/vandalism_detection/features/inserted_external_links.rb +18 -0
  64. data/lib/wikipedia/vandalism_detection/features/inserted_internal_links.rb +18 -0
  65. data/lib/wikipedia/vandalism_detection/features/inserted_size.rb +20 -0
  66. data/lib/wikipedia/vandalism_detection/features/inserted_words.rb +18 -0
  67. data/lib/wikipedia/vandalism_detection/features/longest_word.rb +20 -0
  68. data/lib/wikipedia/vandalism_detection/features/markup_frequency.rb +27 -0
  69. data/lib/wikipedia/vandalism_detection/features/markup_impact.rb +27 -0
  70. data/lib/wikipedia/vandalism_detection/features/non_alphanumeric_ratio.rb +24 -0
  71. data/lib/wikipedia/vandalism_detection/features/personal_life.rb +18 -0
  72. data/lib/wikipedia/vandalism_detection/features/pronoun_frequency.rb +23 -0
  73. data/lib/wikipedia/vandalism_detection/features/pronoun_impact.rb +21 -0
  74. data/lib/wikipedia/vandalism_detection/features/removed_all_wordlists_frequency.rb +23 -0
  75. data/lib/wikipedia/vandalism_detection/features/removed_bad_frequency.rb +23 -0
  76. data/lib/wikipedia/vandalism_detection/features/removed_biased_frequency.rb +23 -0
  77. data/lib/wikipedia/vandalism_detection/features/removed_character_distribution.rb +22 -0
  78. data/lib/wikipedia/vandalism_detection/features/removed_emoticons_frequency.rb +27 -0
  79. data/lib/wikipedia/vandalism_detection/features/removed_markup_frequency.rb +28 -0
  80. data/lib/wikipedia/vandalism_detection/features/removed_pronoun_frequency.rb +23 -0
  81. data/lib/wikipedia/vandalism_detection/features/removed_sex_frequency.rb +23 -0
  82. data/lib/wikipedia/vandalism_detection/features/removed_size.rb +20 -0
  83. data/lib/wikipedia/vandalism_detection/features/removed_vulgarism_frequency.rb +23 -0
  84. data/lib/wikipedia/vandalism_detection/features/removed_words.rb +18 -0
  85. data/lib/wikipedia/vandalism_detection/features/replacement_similarity.rb +22 -0
  86. data/lib/wikipedia/vandalism_detection/features/reverted.rb +18 -0
  87. data/lib/wikipedia/vandalism_detection/features/revisions_character_distribution.rb +21 -0
  88. data/lib/wikipedia/vandalism_detection/features/same_editor.rb +29 -0
  89. data/lib/wikipedia/vandalism_detection/features/sex_frequency.rb +23 -0
  90. data/lib/wikipedia/vandalism_detection/features/sex_impact.rb +21 -0
  91. data/lib/wikipedia/vandalism_detection/features/size_increment.rb +22 -0
  92. data/lib/wikipedia/vandalism_detection/features/size_ratio.rb +26 -0
  93. data/lib/wikipedia/vandalism_detection/features/term_frequency.rb +25 -0
  94. data/lib/wikipedia/vandalism_detection/features/time_interval.rb +31 -0
  95. data/lib/wikipedia/vandalism_detection/features/time_of_day.rb +22 -0
  96. data/lib/wikipedia/vandalism_detection/features/upper_case_ratio.rb +24 -0
  97. data/lib/wikipedia/vandalism_detection/features/upper_case_words_ratio.rb +31 -0
  98. data/lib/wikipedia/vandalism_detection/features/upper_to_lower_case_ratio.rb +24 -0
  99. data/lib/wikipedia/vandalism_detection/features/user_reputation.rb +38 -0
  100. data/lib/wikipedia/vandalism_detection/features/vulgarism_frequency.rb +23 -0
  101. data/lib/wikipedia/vandalism_detection/features/vulgarism_impact.rb +22 -0
  102. data/lib/wikipedia/vandalism_detection/features/weekday.rb +21 -0
  103. data/lib/wikipedia/vandalism_detection/features/words_increment.rb +22 -0
  104. data/lib/wikipedia/vandalism_detection/instances.rb +130 -0
  105. data/lib/wikipedia/vandalism_detection/page.rb +88 -0
  106. data/lib/wikipedia/vandalism_detection/page_parser.rb +52 -0
  107. data/lib/wikipedia/vandalism_detection/revision.rb +69 -0
  108. data/lib/wikipedia/vandalism_detection/revision_parser.rb +43 -0
  109. data/lib/wikipedia/vandalism_detection/test_dataset.rb +367 -0
  110. data/lib/wikipedia/vandalism_detection/text.rb +18 -0
  111. data/lib/wikipedia/vandalism_detection/training_dataset.rb +303 -0
  112. data/lib/wikipedia/vandalism_detection/version.rb +5 -0
  113. data/lib/wikipedia/vandalism_detection/wikitext_extractor.rb +80 -0
  114. data/lib/wikipedia/vandalism_detection/word_lists.rb +19 -0
  115. data/lib/wikipedia/vandalism_detection/word_lists/bad.rb +12 -0
  116. data/lib/wikipedia/vandalism_detection/word_lists/biased.rb +21 -0
  117. data/lib/wikipedia/vandalism_detection/word_lists/emoticons.rb +22 -0
  118. data/lib/wikipedia/vandalism_detection/word_lists/markup.rb +12 -0
  119. data/lib/wikipedia/vandalism_detection/word_lists/pronouns.rb +15 -0
  120. data/lib/wikipedia/vandalism_detection/word_lists/sex.rb +12 -0
  121. data/lib/wikipedia/vandalism_detection/word_lists/vulgarism.rb +97 -0
  122. data/spec/factories/edit.rb +20 -0
  123. data/spec/factories/page.rb +13 -0
  124. data/spec/factories/revision.rb +51 -0
  125. data/spec/resources/config/config.yml +35 -0
  126. data/spec/resources/corpora/test/edits.csv +8 -0
  127. data/spec/resources/corpora/test/ground-truth.txt +3 -0
  128. data/spec/resources/corpora/test/revisions/part-1/326471754.txt +199 -0
  129. data/spec/resources/corpora/test/revisions/part-1/326873205.txt +137 -0
  130. data/spec/resources/corpora/test/revisions/part-1/328774035.txt +162 -0
  131. data/spec/resources/corpora/test/revisions/part-2/307084144.txt +137 -0
  132. data/spec/resources/corpora/test/revisions/part-2/326978767.txt +199 -0
  133. data/spec/resources/corpora/test/revisions/part-2/328774110.txt +162 -0
  134. data/spec/resources/corpora/training/annotations.csv +7 -0
  135. data/spec/resources/corpora/training/edits.csv +7 -0
  136. data/spec/resources/corpora/training/revisions/part-1/326471754.txt +199 -0
  137. data/spec/resources/corpora/training/revisions/part-1/326873205.txt +137 -0
  138. data/spec/resources/corpora/training/revisions/part-1/328774035.txt +162 -0
  139. data/spec/resources/corpora/training/revisions/part-2/307084144.txt +137 -0
  140. data/spec/resources/corpora/training/revisions/part-2/326978767.txt +199 -0
  141. data/spec/resources/corpora/training/revisions/part-2/328774110.txt +162 -0
  142. data/spec/resources/page_with_redirects.xml +85 -0
  143. data/spec/resources/redirect_page.xml +59 -0
  144. data/spec/resources/revision_simplified.xml +13 -0
  145. data/spec/resources/sample_revision.txt +137 -0
  146. data/spec/resources/sample_revision_clean_text.txt +1 -0
  147. data/spec/resources/sample_revision_plain_text.txt +183 -0
  148. data/spec/resources/vandalism_on_wikipedia.xml +234 -0
  149. data/spec/resources/vandalism_on_wikipedia_simplified.xml +119 -0
  150. data/spec/resources/wikipedia_tokens.txt +30 -0
  151. data/spec/spec_helper.rb +22 -0
  152. data/spec/support/macros/file_reading.rb +7 -0
  153. data/spec/support/macros/test_configuration.rb +71 -0
  154. data/spec/vandalism_detection/algorithms/kullback_leibler_divergence_spec.rb +36 -0
  155. data/spec/vandalism_detection/classifier_spec.rb +317 -0
  156. data/spec/vandalism_detection/configuration_spec.rb +517 -0
  157. data/spec/vandalism_detection/diff_spec.rb +40 -0
  158. data/spec/vandalism_detection/edit_spec.rb +137 -0
  159. data/spec/vandalism_detection/evaluator_spec.rb +671 -0
  160. data/spec/vandalism_detection/feature_calculator_spec.rb +128 -0
  161. data/spec/vandalism_detection/features/all_wordlists_frequency_spec.rb +36 -0
  162. data/spec/vandalism_detection/features/all_wordlists_impact_spec.rb +58 -0
  163. data/spec/vandalism_detection/features/anonymity_previous_spec.rb +61 -0
  164. data/spec/vandalism_detection/features/anonymity_spec.rb +23 -0
  165. data/spec/vandalism_detection/features/article_size_spec.rb +35 -0
  166. data/spec/vandalism_detection/features/bad_frequency_spec.rb +36 -0
  167. data/spec/vandalism_detection/features/bad_impact_spec.rb +59 -0
  168. data/spec/vandalism_detection/features/base_spec.rb +49 -0
  169. data/spec/vandalism_detection/features/biased_frequency_spec.rb +36 -0
  170. data/spec/vandalism_detection/features/biased_impact_spec.rb +58 -0
  171. data/spec/vandalism_detection/features/blanking_spec.rb +38 -0
  172. data/spec/vandalism_detection/features/character_diversity_spec.rb +35 -0
  173. data/spec/vandalism_detection/features/character_sequence_spec.rb +37 -0
  174. data/spec/vandalism_detection/features/comment_bad_frequency_spec.rb +34 -0
  175. data/spec/vandalism_detection/features/comment_biased_frequency_spec.rb +34 -0
  176. data/spec/vandalism_detection/features/comment_length_spec.rb +27 -0
  177. data/spec/vandalism_detection/features/comment_markup_frequency_spec.rb +34 -0
  178. data/spec/vandalism_detection/features/comment_pronoun_frequency_spec.rb +34 -0
  179. data/spec/vandalism_detection/features/comment_sex_frequency_spec.rb +34 -0
  180. data/spec/vandalism_detection/features/comment_vulgarism_frequency_spec.rb +34 -0
  181. data/spec/vandalism_detection/features/compressibility_spec.rb +42 -0
  182. data/spec/vandalism_detection/features/contains_base_spec.rb +33 -0
  183. data/spec/vandalism_detection/features/copyedit_spec.rb +33 -0
  184. data/spec/vandalism_detection/features/digit_ratio_spec.rb +35 -0
  185. data/spec/vandalism_detection/features/edits_per_user_spec.rb +49 -0
  186. data/spec/vandalism_detection/features/emoticons_frequency_spec.rb +36 -0
  187. data/spec/vandalism_detection/features/emoticons_impact_spec.rb +51 -0
  188. data/spec/vandalism_detection/features/frequency_base_spec.rb +26 -0
  189. data/spec/vandalism_detection/features/impact_base_spec.rb +41 -0
  190. data/spec/vandalism_detection/features/inserted_character_distribution_spec.rb +46 -0
  191. data/spec/vandalism_detection/features/inserted_external_links_spec.rb +35 -0
  192. data/spec/vandalism_detection/features/inserted_internal_links_spec.rb +35 -0
  193. data/spec/vandalism_detection/features/inserted_size_spec.rb +35 -0
  194. data/spec/vandalism_detection/features/inserted_words_spec.rb +35 -0
  195. data/spec/vandalism_detection/features/longest_word_spec.rb +35 -0
  196. data/spec/vandalism_detection/features/markup_frequency_spec.rb +36 -0
  197. data/spec/vandalism_detection/features/markup_impact_spec.rb +59 -0
  198. data/spec/vandalism_detection/features/non_alphanumeric_ratio_spec.rb +35 -0
  199. data/spec/vandalism_detection/features/personal_life_spec.rb +26 -0
  200. data/spec/vandalism_detection/features/pronoun_frequency_spec.rb +36 -0
  201. data/spec/vandalism_detection/features/pronoun_impact_spec.rb +59 -0
  202. data/spec/vandalism_detection/features/removed_all_wordlists_frequency_spec.rb +36 -0
  203. data/spec/vandalism_detection/features/removed_bad_frequency_spec.rb +36 -0
  204. data/spec/vandalism_detection/features/removed_biased_frequency_spec.rb +36 -0
  205. data/spec/vandalism_detection/features/removed_character_distribution_spec.rb +46 -0
  206. data/spec/vandalism_detection/features/removed_emoticons_frequency_spec.rb +36 -0
  207. data/spec/vandalism_detection/features/removed_markup_frequency_spec.rb +36 -0
  208. data/spec/vandalism_detection/features/removed_pronoun_frequency_spec.rb +36 -0
  209. data/spec/vandalism_detection/features/removed_sex_frequency_spec.rb +36 -0
  210. data/spec/vandalism_detection/features/removed_size_spec.rb +35 -0
  211. data/spec/vandalism_detection/features/removed_vulgarism_frequency_spec.rb +36 -0
  212. data/spec/vandalism_detection/features/removed_words_spec.rb +35 -0
  213. data/spec/vandalism_detection/features/replacement_similarity_spec.rb +44 -0
  214. data/spec/vandalism_detection/features/reverted_spec.rb +28 -0
  215. data/spec/vandalism_detection/features/revisions_character_distribution_spec.rb +46 -0
  216. data/spec/vandalism_detection/features/same_editor_spec.rb +60 -0
  217. data/spec/vandalism_detection/features/sex_frequency_spec.rb +36 -0
  218. data/spec/vandalism_detection/features/sex_impact_spec.rb +59 -0
  219. data/spec/vandalism_detection/features/size_increment_spec.rb +35 -0
  220. data/spec/vandalism_detection/features/size_ratio_spec.rb +57 -0
  221. data/spec/vandalism_detection/features/term_frequency_spec.rb +38 -0
  222. data/spec/vandalism_detection/features/time_interval_spec.rb +50 -0
  223. data/spec/vandalism_detection/features/time_of_day_spec.rb +22 -0
  224. data/spec/vandalism_detection/features/upper_case_ratio_spec.rb +35 -0
  225. data/spec/vandalism_detection/features/upper_case_words_ratio_spec.rb +37 -0
  226. data/spec/vandalism_detection/features/upper_to_lower_case_ratio_spec.rb +35 -0
  227. data/spec/vandalism_detection/features/user_reputation_spec.rb +52 -0
  228. data/spec/vandalism_detection/features/vulgarism_frequency_spec.rb +36 -0
  229. data/spec/vandalism_detection/features/vulgarism_impact_spec.rb +58 -0
  230. data/spec/vandalism_detection/features/weekday_spec.rb +22 -0
  231. data/spec/vandalism_detection/features/words_increment_spec.rb +35 -0
  232. data/spec/vandalism_detection/instances_spec.rb +156 -0
  233. data/spec/vandalism_detection/page_parser_spec.rb +184 -0
  234. data/spec/vandalism_detection/page_spec.rb +135 -0
  235. data/spec/vandalism_detection/revision_parser_spec.rb +53 -0
  236. data/spec/vandalism_detection/revision_spec.rb +115 -0
  237. data/spec/vandalism_detection/test_dataset_spec.rb +231 -0
  238. data/spec/vandalism_detection/text_spec.rb +29 -0
  239. data/spec/vandalism_detection/training_dataset_spec.rb +264 -0
  240. data/spec/vandalism_detection/wikitext_extractor_spec.rb +72 -0
  241. data/spec/weka/classifiers/functions/lib_svm_spec.rb +38 -0
  242. data/spec/weka/classifiers/meta/one_class_classifier_spec.rb +76 -0
  243. data/spec/weka/classifiers/meta/real_ada_boost_spec.rb +40 -0
  244. data/spec/weka/classifiers/trees/balanced_random_forest_spec.rb +40 -0
  245. data/spec/weka/filters/supervised/instance/smote_spec.rb +6 -0
  246. data/wikipedia-vandalism_detection.gemspec +30 -0
  247. metadata +512 -0
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikipedia::VandalismDetection::Features::SexFrequency do
4
+
5
+ before do
6
+ @feature = Wikipedia::VandalismDetection::Features::SexFrequency.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 sex contents. Penis, dildos, boy."
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::SexImpact do
4
+
5
+ before do
6
+ @feature = Wikipedia::VandalismDetection::Features::SexImpact.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 sex words of the edit's new revision text" do
14
+ # 3 sex words
15
+ old_text = Wikipedia::VandalismDetection::Text.new "Penis, old text dildo, breast it"
16
+
17
+ # 4 sex words
18
+ new_text = Wikipedia::VandalismDetection::Text.new "Penis, old text dildo, breast anal it"
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 "anal"
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 "anal"
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,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikipedia::VandalismDetection::Features::SizeIncrement do
4
+
5
+ before do
6
+ @feature = Wikipedia::VandalismDetection::Features::SizeIncrement.new
7
+ end
8
+
9
+ it { should be_a Wikipedia::VandalismDetection::Features::Base }
10
+
11
+ describe "#calculate" do
12
+
13
+ it "returns a negative increment on more removed texts" do
14
+ old_revision_text = Wikipedia::VandalismDetection::Text.new '123456789' # length 9
15
+ new_revision_text = Wikipedia::VandalismDetection::Text.new '123' # length 3
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 3.0 - 9.0
22
+ end
23
+
24
+ it "returns a positive increment on more removed texts" do
25
+ old_revision_text = Wikipedia::VandalismDetection::Text.new '123' # length 3
26
+ new_revision_text = Wikipedia::VandalismDetection::Text.new '123456789' # length 9
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 9.0 - 3.0
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikipedia::VandalismDetection::Features::SizeRatio do
4
+
5
+ before do
6
+ @feature = Wikipedia::VandalismDetection::Features::SizeRatio.new
7
+ end
8
+
9
+ it { should be_a Wikipedia::VandalismDetection::Features::Base }
10
+
11
+ describe "#calculate" do
12
+
13
+ it "returns the ratio of the edit's revisions text sizes" do
14
+ old_revision_text = Wikipedia::VandalismDetection::Text.new '123456789' # length 9
15
+ new_revision_text = Wikipedia::VandalismDetection::Text.new '123' # length 3
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 9.0 / (9.0 + 3.0)
22
+ end
23
+
24
+ it "returns 1.0 on emtpy new text revisions" do
25
+ old_text = Wikipedia::VandalismDetection::Text.new "sample text"
26
+ new_text = Wikipedia::VandalismDetection::Text.new ""
27
+
28
+ old_revision = build(:old_revision, text: old_text)
29
+ new_revision = build(:new_revision, text: new_text)
30
+ edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
31
+
32
+ expect(@feature.calculate(edit)).to eq 1.0
33
+ end
34
+
35
+ it "returns 0.0 on emtpy old text revisions" do
36
+ old_text = Wikipedia::VandalismDetection::Text.new ""
37
+ new_text = Wikipedia::VandalismDetection::Text.new "sample text"
38
+
39
+ old_revision = build(:old_revision, text: old_text)
40
+ new_revision = build(:new_revision, text: new_text)
41
+ edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
42
+
43
+ expect(@feature.calculate(edit)).to eq 0.0
44
+ end
45
+
46
+ it "returns 0.5 on emtpy both text revisions" do
47
+ old_text = Wikipedia::VandalismDetection::Text.new ""
48
+ new_text = Wikipedia::VandalismDetection::Text.new ""
49
+
50
+ old_revision = build(:old_revision, text: old_text)
51
+ new_revision = build(:new_revision, text: new_text)
52
+ edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
53
+
54
+ expect(@feature.calculate(edit)).to eq 0.5
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikipedia::VandalismDetection::Features::TermFrequency do
4
+
5
+ before do
6
+ @feature = Wikipedia::VandalismDetection::Features::TermFrequency.new
7
+ end
8
+
9
+ it { should be_a Wikipedia::VandalismDetection::Features::FrequencyBase }
10
+
11
+ describe "#calculate" do
12
+
13
+ it "returns the average relative frequency of inserted words in the new revision" do
14
+ # removed [you, I], added [you, you, you, we]
15
+ # for [you, we] compute frequency in old_text and average for all words
16
+ # here: [you] is 6x in new text, [we] is 3x in new text of total 10 words
17
+ # avrg = (6/10 + 3/10)/2
18
+ old_text = Wikipedia::VandalismDetection::Text.new "we\nwe\nyou\nyou\nyou\nI\nyou\nI\n"
19
+ new_text = Wikipedia::VandalismDetection::Text.new "we\nwe\nyou\nyou\nI\nyou\n''(you''\nyou\nyou\n[[we]])\n"
20
+
21
+ old_revision = build(:old_revision, text: old_text)
22
+ new_revision = build(:new_revision, text: new_text)
23
+ edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
24
+
25
+ expect(@feature.calculate(edit)).to eq ((6.0/10.0) + (3.0/10.0)) / 2.0
26
+ end
27
+
28
+ it "returns 0.0 on emtpy clean text revisions" do
29
+ text = Wikipedia::VandalismDetection::Text.new "{{speedy deletion}}"
30
+
31
+ old_revision = build(:old_revision, text: text)
32
+ new_revision = build(:new_revision, text: text)
33
+ edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
34
+
35
+ expect(@feature.calculate(edit)).to eq 0.0
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikipedia::VandalismDetection::Features::TimeInterval do
4
+
5
+ before do
6
+ @feature = Wikipedia::VandalismDetection::Features::TimeInterval.new
7
+ end
8
+
9
+ it { should be_a Wikipedia::VandalismDetection::Features::Base }
10
+
11
+ describe "#calculate" do
12
+
13
+ it "returns time interval in days from old to new revision" do
14
+ old_revision_time = '2014-11-27T18:00:00Z'
15
+ new_revision_time = '2014-11-29T06:00:00Z'
16
+
17
+ old_revision = build(:old_revision, timestamp: old_revision_time)
18
+ new_revision = build(:new_revision, timestamp: new_revision_time)
19
+ edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
20
+
21
+ expect(@feature.calculate(edit)).to eq 1.5
22
+ end
23
+
24
+ it "requests the time from Wikipedia API if old revisions timestamp is not given" do
25
+ # to get api call, see:
26
+ # https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=timestamp&revids=327585467
27
+ # => 2009-11-24T01:57:35Z
28
+ new_revision_time = '2009-11-24T13:57:35Z'
29
+
30
+ old_revision = build(:old_revision, id: '327585467', timestamp: nil)
31
+ new_revision = build(:new_revision, id: '327607921', parent_id: '327585467', timestamp: new_revision_time)
32
+ edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
33
+
34
+ expect(@feature.calculate(edit)).to eq 0.5
35
+ end
36
+
37
+ it "returns missing if old reivision is not available anymore" do
38
+ # to get api call, see:
39
+ # https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=timestamp&revids=325218985
40
+ # <rev revid="325218985"/>
41
+ new_revision_time = '2011-11-11T01:00:00Z'
42
+
43
+ old_revision = build(:old_revision, id: '325218985', timestamp: nil)
44
+ new_revision = build(:new_revision, id: '326980599', parent_id: '325218985', timestamp: new_revision_time)
45
+ edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
46
+
47
+ expect(@feature.calculate(edit)).to eq Wikipedia::VandalismDetection::Features::MISSING_VALUE
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikipedia::VandalismDetection::Features::TimeOfDay do
4
+
5
+ before do
6
+ @feature = Wikipedia::VandalismDetection::Features::TimeOfDay.new
7
+ end
8
+
9
+ it { should be_a Wikipedia::VandalismDetection::Features::Base }
10
+
11
+ describe "#calculate" do
12
+
13
+ it "returns the time of day as decimal value (hours)" do
14
+ old_revision = build(:old_revision)
15
+ new_revision = build(:new_revision, timestamp: '2012-12-09T05:30:36Z' )
16
+
17
+ edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
18
+
19
+ expect(@feature.calculate(edit)).to eq 5.6
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikipedia::VandalismDetection::Features::UpperCaseRatio do
4
+
5
+ before do
6
+ @feature = Wikipedia::VandalismDetection::Features::UpperCaseRatio.new
7
+ end
8
+
9
+ it { should be_a Wikipedia::VandalismDetection::Features::Base }
10
+
11
+ describe "#calculate" do
12
+
13
+ it "returns the uppercase to all letters ratio of the edit's new revision cleaned inserted text" do
14
+ old_text = Wikipedia::VandalismDetection::Text.new('text')
15
+ new_text = Wikipedia::VandalismDetection::Text.new 'text [[1A 4B6 8Cd]]' # 3 uppercase letters of total 4 inserted letters
16
+
17
+ old_revision = build(:old_revision, text: old_text)
18
+ new_revision = build(:new_revision, text: new_text)
19
+ edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
20
+
21
+ expect(@feature.calculate(edit)).to eq (1.0 + 3) / (1.0 + 4)
22
+ end
23
+
24
+ it "returns 0.0 if no text inserted" do
25
+ old_text = Wikipedia::VandalismDetection::Text.new("deletion text")
26
+ new_text = Wikipedia::VandalismDetection::Text.new("text")
27
+
28
+ old_revision = build(:old_revision, text: old_text)
29
+ new_revision = build(:new_revision, text: new_text)
30
+ edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
31
+
32
+ expect(@feature.calculate(edit)).to eq 0.0
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Wikipedia::VandalismDetection::Features::UpperCaseWordsRatio do
5
+
6
+ before do
7
+ @feature = Wikipedia::VandalismDetection::Features::UpperCaseWordsRatio.new
8
+ end
9
+
10
+ it { should be_a Wikipedia::VandalismDetection::Features::Base }
11
+
12
+ describe "#calculate" do
13
+
14
+ it "returns the uppercase to all words ratio of the edit's new revision cleaned inserted text" do
15
+ old_text = Wikipedia::VandalismDetection::Text.new('text')
16
+ # 2 two capital (not numbers!) words of total 4 inserted, template {{23A}} is removed while cleaning!
17
+ new_text = Wikipedia::VandalismDetection::Text.new "text [[HELLO you]] NICE boyß3 1990 {{23A}}"
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 (1.0 + 2) / (1.0 + 4)
24
+ end
25
+
26
+ it "returns 0.0 if no text inserted" do
27
+ old_text = Wikipedia::VandalismDetection::Text.new("DELECTION text")
28
+ new_text = Wikipedia::VandalismDetection::Text.new("text")
29
+
30
+ old_revision = build(:old_revision, text: old_text)
31
+ new_revision = build(:new_revision, text: new_text)
32
+ edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
33
+
34
+ expect(@feature.calculate(edit)).to eq 0.0
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikipedia::VandalismDetection::Features::UpperToLowerCaseRatio do
4
+
5
+ before do
6
+ @feature = Wikipedia::VandalismDetection::Features::UpperToLowerCaseRatio.new
7
+ end
8
+
9
+ it { should be_a Wikipedia::VandalismDetection::Features::Base }
10
+
11
+ describe "#calculate" do
12
+
13
+ it "returns the uppercase to lowercase letters ratio of the edit's new revision inserted text" do
14
+ old_text = Wikipedia::VandalismDetection::Text.new('text')
15
+ new_text = Wikipedia::VandalismDetection::Text.new 'text [[1aA 4B6 8Cd ef]]' # 3 uppercase letters, 4 lowercase letters
16
+
17
+ old_revision = build(:old_revision, text: old_text)
18
+ new_revision = build(:new_revision, text: new_text)
19
+ edit = build(:edit, old_revision: old_revision, new_revision: new_revision)
20
+
21
+ expect(@feature.calculate(edit)).to eq (1.0 + 3) / (1.0 + 4)
22
+ end
23
+
24
+ it "returns 0.0 if no text inserted" do
25
+ old_text = Wikipedia::VandalismDetection::Text.new("deletion text")
26
+ new_text = Wikipedia::VandalismDetection::Text.new("text")
27
+
28
+ old_revision = build(:old_revision, text: old_text)
29
+ new_revision = build(:new_revision, text: new_text)
30
+ edit = build(:edit, new_revision: new_revision, old_revision: old_revision)
31
+
32
+ expect(@feature.calculate(edit)).to eq 0.0
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikipedia::VandalismDetection::Features::UserReputation do
4
+
5
+ before do
6
+ @feature = Wikipedia::VandalismDetection::Features::UserReputation.new
7
+ end
8
+
9
+ it { should be_a Wikipedia::VandalismDetection::Features::Base }
10
+
11
+ describe "#calculate" do
12
+
13
+ it "returns the average number of contributor's reputation (WikiTrust) in the new revision" do
14
+ #http://en.collaborativetrust.com/WikiTrust/RemoteAPI?method=wikimarkup&pageid=<page_id>&revid=<old_rev_id>
15
+ # here: http://en.collaborativetrust.com/WikiTrust/RemoteAPI?method=wikimarkup&pageid=15580374&revid=604074768
16
+ old_revision = build(:old_revision, id: '603070163')
17
+ new_revision = build(:new_revision, id: '604074768', parent_id: '603070163', contributor: 'David Levy')
18
+ page = Wikipedia::VandalismDetection::Page.new
19
+ page.id = "15580374"
20
+
21
+ edit = build(:edit, old_revision: old_revision, new_revision: new_revision, page: page)
22
+
23
+ expect(@feature.calculate(edit)).to eq 10.0
24
+ end
25
+
26
+ it "fetches the page id from the wikipedia API by page title if not available in edit" do
27
+ #http://en.collaborativetrust.com/WikiTrust/RemoteAPI?method=wikimarkup&pageid=<page_id>&revid=<old_rev_id>
28
+ # here: http://en.collaborativetrust.com/WikiTrust/RemoteAPI?method=wikimarkup&pageid=15580374&revid=604074768
29
+ old_revision = build(:old_revision, id: '603070163')
30
+ new_revision = build(:new_revision, id: '604074768', parent_id: '603070163', contributor: 'David Levy')
31
+ page = Wikipedia::VandalismDetection::Page.new
32
+ page.title = 'Main Page'
33
+
34
+ edit = build(:edit, old_revision: old_revision, new_revision: new_revision, page: page)
35
+
36
+ expect(@feature.calculate(edit)).to eq 10.0
37
+ end
38
+
39
+ it "returns 0.0 WikiTrust if no contributions are available for given user" do
40
+ #http://en.collaborativetrust.com/WikiTrust/RemoteAPI?method=wikimarkup&pageid=<page_id>&revid=<old_rev_id>
41
+ # here: http://en.collaborativetrust.com/WikiTrust/RemoteAPI?method=wikimarkup&pageid=15580374&revid=604074768
42
+ old_revision = build(:old_revision, id: '603070163')
43
+ new_revision = build(:new_revision, id: '604074768', parent_id: '603070163', contributor: 'Artificial User')
44
+ page = Wikipedia::VandalismDetection::Page.new
45
+ page.id = "15580374"
46
+
47
+ edit = build(:edit, old_revision: old_revision, new_revision: new_revision, page: page)
48
+
49
+ expect(@feature.calculate(edit)).to eq 0.0
50
+ end
51
+ end
52
+ end