l2e_vocab_blacklist 1.0.1 → 1.1.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 +25 -3
- 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: 9ff5c746de5666a34afa6ca613e8d00b253ecb35
|
4
|
+
data.tar.gz: 013ce4b1478a34ba82b5664ac3c4f9c6e33309bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2e1a7a39a4aee8e8b8da9e60fbc74ce3bc45dede898978b8722be2cc184fdc130ff15cced70591c54668172834172f25355e32df9769ba42e99e8e822ac64bc
|
7
|
+
data.tar.gz: dbb188bdb38cf44bf376345e48946ce085ed6cfae2e89b26a0afd7c37701b924e5295ca1fbabcbf29784a9f9a63ae6644230102a12eef0dfc5d6e22581ce0fd8
|
data/lib/l2e_vocab_blacklist.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
2
|
|
3
3
|
class VocabBlacklist
|
4
|
+
|
5
|
+
# Returns true or false, check to see if the
|
4
6
|
def self.blacklisted?(str)
|
5
7
|
# Sanitize string
|
6
8
|
str = str.downcase.strip.gsub(CONSIDER_REGEX, '')
|
7
9
|
|
8
10
|
# Blacklist if any of the words
|
9
11
|
str.split(" ").each do |word|
|
10
|
-
return true if FULL_WORDS.include?(
|
12
|
+
return true if FULL_WORDS.include?(word)
|
11
13
|
end
|
12
14
|
|
13
15
|
# For compound dirty words
|
@@ -15,7 +17,27 @@ class VocabBlacklist
|
|
15
17
|
return true if str.include?(bad_phrase)
|
16
18
|
end
|
17
19
|
|
18
|
-
return
|
20
|
+
return GREEDY_WORDS.any? { |s| str.include?(s) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.censor(str, replace_with = "****")
|
24
|
+
PHRASES.each do |bad_phrase|
|
25
|
+
str.gsub!(/#{bad_phrase}/i, replace_with)
|
26
|
+
end
|
27
|
+
|
28
|
+
str.split(" ").map do |working_word|
|
29
|
+
word = working_word.downcase.strip.gsub(CONSIDER_REGEX, '')
|
30
|
+
|
31
|
+
if FULL_WORDS.include?(word)
|
32
|
+
working_word.gsub!(word, replace_with)
|
33
|
+
end
|
34
|
+
|
35
|
+
if GREEDY_WORDS.any? { |w| word.include?(w) }
|
36
|
+
working_word = replace_with
|
37
|
+
end
|
38
|
+
|
39
|
+
working_word
|
40
|
+
end.join(" ")
|
19
41
|
end
|
20
42
|
|
21
43
|
def self.file_to_nomalized_words(file)
|
@@ -31,6 +53,6 @@ class VocabBlacklist
|
|
31
53
|
|
32
54
|
PHRASES = file_to_nomalized_words("#{BLACKLIST_DIR}/full_words.txt").select { |w| w.split(" ").length > 1 }
|
33
55
|
FULL_WORDS = file_to_nomalized_words("#{BLACKLIST_DIR}/full_words.txt").reject { |w| w.split(" ").length > 1 }
|
34
|
-
|
56
|
+
GREEDY_WORDS = words_with_expansions(file_to_nomalized_words("#{BLACKLIST_DIR}/greedy_words.txt")).uniq.freeze
|
35
57
|
|
36
58
|
end
|