l2e_vocab_blacklist 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/l2e_vocab_blacklist.rb +20 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 573f1413f2d34fe1cbf44cccecb06ee670c50df7
|
4
|
+
data.tar.gz: e9364633b32e77d12e085fd4c5be17c800fb9034
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63b1e57ec5f4507dc11706b16d1b083ba07b05bf602c15ba10031ebcca3953deaf42fc7d984390d843b68b359c5ca24c3fb0b6691aa9e92ecb2f670dacf1e06d
|
7
|
+
data.tar.gz: cd207ac616e7a8375c5c161b7f59ebd75f3f18e725d4a4e65ea910f1296b4b11253eb9bc46ef42253e7f7af7342396480d05ef20969653379658ced1b17a4faa
|
data/lib/l2e_vocab_blacklist.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
|
+
require 'csv'
|
2
3
|
|
3
4
|
class VocabBlacklist
|
4
5
|
|
5
6
|
# Returns true or false, check to see if the
|
6
|
-
def self.blacklisted?(str)
|
7
|
+
def self.blacklisted?(str,age ="0")
|
7
8
|
# Sanitize string
|
8
9
|
str = str.downcase.strip.gsub(CONSIDER_REGEX, '')
|
9
|
-
|
10
10
|
# Blacklist if any of the words
|
11
11
|
str.split(" ").each do |word|
|
12
|
-
return true if FULL_WORDS.include?(word)
|
13
|
-
end
|
14
12
|
|
13
|
+
return true if check_full_words_csv(word,age)
|
14
|
+
|
15
|
+
end
|
15
16
|
# For compound dirty words
|
16
17
|
PHRASES.each do |bad_phrase|
|
17
18
|
return true if str.include?(bad_phrase)
|
@@ -20,23 +21,25 @@ class VocabBlacklist
|
|
20
21
|
return GREEDY_WORDS.any? { |s| str.include?(s) }
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
+
|
25
|
+
def self.censor(str, age = "0", replace_with = "****")
|
24
26
|
|
25
27
|
PHRASES.each do |bad_phrase|
|
26
28
|
str.gsub!(/#{bad_phrase}/i, replace_with)
|
27
29
|
end
|
28
30
|
|
29
31
|
str.split(/ /).map do |working_word|
|
32
|
+
|
30
33
|
word = working_word.downcase.gsub(CONSIDER_REGEX, '')
|
31
34
|
|
32
|
-
if
|
35
|
+
if check_full_words_csv(word,age)
|
33
36
|
working_word.gsub!(/#{word}/i, replace_with)
|
34
37
|
end
|
35
38
|
|
36
39
|
if GREEDY_WORDS.any? { |w| word.include?(w) }
|
37
40
|
working_word = replace_with
|
38
41
|
end
|
39
|
-
|
42
|
+
|
40
43
|
working_word
|
41
44
|
end.join(" ")
|
42
45
|
end
|
@@ -56,4 +59,14 @@ class VocabBlacklist
|
|
56
59
|
FULL_WORDS = file_to_nomalized_words("#{BLACKLIST_DIR}/full_words.txt").reject { |w| w.split(" ").length > 1 }
|
57
60
|
GREEDY_WORDS = words_with_expansions(file_to_nomalized_words("#{BLACKLIST_DIR}/greedy_words.txt")).uniq.freeze
|
58
61
|
|
62
|
+
FULL_WORDS_CSV = CSV.parse(File.read("#{BLACKLIST_DIR}/full_words.csv"), :headers => true)
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def self.check_full_words_csv(word,age)
|
67
|
+
FULL_WORDS_CSV.each do |row|
|
68
|
+
return true if row[1] >= age && row[0].downcase == word.downcase
|
69
|
+
end
|
70
|
+
return false
|
71
|
+
end
|
59
72
|
end
|