894855845fc3c318d66923b03ed78aa2a9099362
[kiosk.git] / profanity_filter.py
1 import string
2 import re
3
4 class profanity_filter:
5     def __init__(self):
6         self.arrBad = [
7             'acrotomophilia',
8             'anal',
9             'anally',
10             'anilingus',
11             'anus',
12             'arsehole',
13             'ass',
14             'asses',
15             'asshole',
16             'assmunch',
17             'auto erotic',
18             'autoerotic',
19             'babeland',
20             'baby batter',
21             'ball gag',
22             'ball gravy',
23             'ball kicking',
24             'ball licking',
25             'ball sack',
26             'ball zack',
27             'ball sucking',
28             'bangbros',
29             'bareback',
30             'barely legal',
31             'barenaked',
32             'bastardo',
33             'bastinado',
34             'bbw',
35             'bdsm',
36             'beaver cleaver',
37             'beaver lips',
38             'bestiality',
39             'bi curious',
40             'big black',
41             'big breasts',
42             'big knockers',
43             'big tits',
44             'bimbos',
45             'birdlock',
46             'bitch',
47             'bitches',
48             'black cock',
49             'blonde action',
50             'blonde on blonde',
51             'blow j',
52             'blow your l',
53             'blow ourselves',
54             'blow m',
55             'blue waffle',
56             'blumpkin',
57             'bollocks',
58             'bondage',
59             'boner',
60             'boob',
61             'boobs',
62             'booty call',
63             'breasts',
64             'brown showers',
65             'brunette action',
66             'bukkake',
67             'bulldyke',
68             'bullshit',
69             'bullet vibe',
70             'bung hole',
71             'bunghole',
72             'busty',
73             'butt',
74             'buttcheeks',
75             'butthole',
76             'camel toe',
77             'camgirl',
78             'camslut',
79             'camwhore',
80             'carpet muncher',
81             'carpetmuncher',
82             'chocolate rosebuds',
83             'circlejerk',
84             'cleveland steamer',
85             'clit',
86             'clitoris',
87             'clover clamps',
88             'clusterfuck',
89             'cock',
90             'cocks',
91             'coprolagnia',
92             'coprophilia',
93             'cornhole',
94             'creampie',
95             'cream pie',
96             'cum',
97             'cumming',
98             'cunnilingus',
99             'cunt',
100             'damn',
101             'darkie',
102             'date rape',
103             'daterape',
104             'deep throat',
105             'deepthroat',
106             'dick',
107             'dildo',
108             'dirty pillows',
109             'dirty sanchez',
110             'dog style',
111             'doggie style',
112             'doggiestyle',
113             'doggy style',
114             'doggystyle',
115             'dolcett',
116             'domination',
117             'dominatrix',
118             'dommes',
119             'donkey punch',
120             'double dick',
121             'double dong',
122             'double penetration',
123             'dp action',
124             'dtf',
125             'eat my ass',
126             'ecchi',
127             'ejaculation',
128             'erection',
129             'erotic',
130             'erotism',
131             'escort',
132             'ethical slut',
133             'eunuch',
134             'faggot',
135             'posts each week',
136             'fecal',
137             'felch',
138             'fellatio',
139             'feltch',
140             'female squirting',
141             'femdom',
142             'figging',
143             'fingering',
144             'fisting',
145             'foot fetish',
146             'footjob',
147             'frotting',
148             'fuck',
149             'fucking',
150             'fuckin',
151             'fuckin\'',
152             'fucked',
153             'fuckers',
154             'fuck buttons',
155             'fuckhead',
156             'fudge packer',
157             'fudgepacker',
158             'futanari',
159             'g-spot',
160             'gspot',
161             'gang bang',
162             'gay sex',
163             'genitals',
164             'giant cock',
165             'girl on',
166             'girl on top',
167             'girls gone wild',
168             'goatcx',
169             'goatse',
170             'goddamn',
171             'gokkun',
172             'golden shower',
173             'goo girl',
174             'goodpoop',
175             'goregasm',
176             'grope',
177             'group sex',
178             'guro',
179             'hand job',
180             'handjob',
181             'hard core',
182             'hardcore',
183             'hentai',
184             'homoerotic',
185             'honkey',
186             'hooker',
187             'horny',
188             'hot chick',
189             'how to kill',
190             'how to murder',
191             'huge fat',
192             'humping',
193             'incest',
194             'intercourse',
195             'jack off',
196             'jail bait',
197             'jailbait',
198             'jerk off',
199             'jerking off',
200             'jigaboo',
201             'jiggaboo',
202             'jiggerboo',
203             'jizz',
204             'juggs',
205             'kike',
206             'kinbaku',
207             'kinkster',
208             'kinky',
209             'knobbing',
210             'leather restraint',
211             'lemon party',
212             'lolita',
213             'lovemaking',
214             'lpt request',
215             'make me come',
216             'male squirting',
217             'masturbate',
218             'masturbated',
219             'masturbating',
220             'menage a trois',
221             'milf',
222             'milfs',
223             'missionary position',
224             'motherfucker',
225             'mound of venus',
226             'mr hands',
227             'muff diver',
228             'muffdiving',
229             'nambla',
230             'nawashi',
231             'negro',
232             'neonazi',
233             'nig nog',
234             'nigga',
235             'nigger',
236             'nimphomania',
237             'nipple',
238             'not safe for',
239             'nsfw',
240             'nsfw images',
241             'nude',
242             'nudity',
243             'nutsack',
244             'nut sack',
245             'nympho',
246             'nymphomania',
247             'octopussy',
248             'omorashi',
249             'one night stand',
250             'orgasm',
251             'orgy',
252             'paedophile',
253             'panties',
254             'panty',
255             'pedobear',
256             'pedophile',
257             'pegging',
258             'pee',
259             'penis',
260             'phone sex',
261             'piss pig',
262             'pissing',
263             'pisspig',
264             'playboy',
265             'pleasure chest',
266             'pole smoker',
267             'ponyplay',
268             'poof',
269             'poop chute',
270             'poopchute',
271             'porn',
272             'pornhub',
273             'porno',
274             'pornography',
275             'prince albert',
276             'pthc',
277             'pube',
278             'pubes',
279             'pussy',
280             'pussies',
281             'queaf',
282             'queer',
283             'raghead',
284             'raging boner',
285             'rape',
286             'raping',
287             'rapist',
288             'rectum',
289             'reverse cowgirl',
290             'rimjob',
291             'rimming',
292             'rosy palm',
293             'rusty trombone',
294             's&m',
295             'sadism',
296             'scat',
297             'schlong',
298             'scissoring',
299             'semen',
300             'sex',
301             'sexo',
302             'sexy',
303             'shaved beaver',
304             'shaved pussy',
305             'shemale',
306             'shibari',
307             'shit',
308             'shota',
309             'shrimping',
310             'slanteye',
311             'slut',
312             'smut',
313             'snatch',
314             'snowballing',
315             'sodomize',
316             'sodomy',
317             'spic',
318             'spooge',
319             'spread legs',
320             'strap on',
321             'strapon',
322             'strappado',
323             'strip club',
324             'style doggy',
325             'suck',
326             'sucks',
327             'suicide girls',
328             'sultry women',
329             'swastika',
330             'swinger',
331             'tainted love',
332             'taste my',
333             'tea bagging',
334             'threesome',
335             'throating',
336             'tied up',
337             'tight white',
338             'tit',
339             'tits',
340             'titties',
341             'titty',
342             'tongue in a',
343             'topless',
344             'tosser',
345             'towelhead',
346             'tranny',
347             'tribadism',
348             'tub girl',
349             'tubgirl',
350             'tushy',
351             'twat',
352             'twink',
353             'twinkie',
354             'undressing',
355             'upskirt',
356             'urethra play',
357             'urophilia',
358             'vagina',
359             'venus mound',
360             'vibrator',
361             'violet blue',
362             'violet wand',
363             'vorarephilia',
364             'voyeur',
365             'vulva',
366             'wank',
367             'wet dream',
368             'wetback',
369             'white power',
370             'whore',
371             'women rapping',
372             'wrapping men',
373             'wrinkled starfish',
374             'xx',
375             'xxx',
376             'yaoi',
377             'yellow showers',
378             'yiffy',
379             'zoophilia',
380         ]
381
382     def normalize(self, text):
383         result = text.lower()
384         result = result.replace('_', ' ')
385         for x in string.punctuation:
386             result = result.replace(x, '')
387         result = re.sub(
388             r"e?s$", "", result)
389         return result
390
391     def filter_bad_words(self, text):
392         badWordMask = '!@#$%!@#$%^~!@%^~@#$%!@#$%^~!'
393
394         brokenStr1 = text.split()
395         for word in brokenStr1:
396             if (self.normalize(word) in self.arrBad or
397                 word in self.arrBad):
398                 print(('***** PROFANITY WORD="%s"' % word))
399                 text = text.replace(word, badWordMask[:len(word)])
400
401         if len(brokenStr1) > 1:
402             bigrams = list(zip(brokenStr1, brokenStr1[1:]))
403             for bigram in bigrams:
404                 phrase = "%s %s" % (bigram[0], bigram[1])
405                 if (self.normalize(phrase) in self.arrBad or
406                     phrase in self.arrBad):
407                     print(('***** PROFANITY PHRASE="%s"' % phrase))
408                     text = text.replace(bigram[0], badWordMask[:len(bigram[0])])
409                     text = text.replace(bigram[1], badWordMask[:len(bigram[1])])
410
411         if len(brokenStr1) > 2:
412             trigrams = list(zip(brokenStr1, brokenStr1[1:], brokenStr1[2:]))
413             for trigram in trigrams:
414                 phrase = "%s %s %s" % (trigram[0], trigram[1], trigram[2])
415                 if (self.normalize(phrase) in self.arrBad or
416                     phrase in self.arrBad):
417                     print(('***** PROFANITY PHRASE="%s"' % phrase))
418                     text = text.replace(trigram[0], badWordMask[:len(trigram[0])])
419                     text = text.replace(trigram[1], badWordMask[:len(trigram[1])])
420                     text = text.replace(trigram[2], badWordMask[:len(trigram[2])])
421         return text
422
423     def contains_bad_words(self, text):
424         brokenStr1 = text.split()
425         for word in brokenStr1:
426             if (self.normalize(word) in self.arrBad or
427                 word in self.arrBad):
428                 print(('***** PROFANITY WORD="%s"' % word))
429                 return True
430
431         if len(brokenStr1) > 1:
432             bigrams = list(zip(brokenStr1, brokenStr1[1:]))
433             for bigram in bigrams:
434                 phrase = "%s %s" % (bigram[0], bigram[1])
435                 if (self.normalize(phrase) in self.arrBad or
436                     phrase in self.arrBad):
437                     print(('***** PROFANITY PHRASE="%s"' % phrase))
438                     return True
439
440         if len(brokenStr1) > 2:
441             trigrams = list(zip(brokenStr1, brokenStr1[1:], brokenStr1[2:]))
442             for trigram in trigrams:
443                 phrase = "%s %s %s" % (trigram[0], trigram[1], trigram[2])
444                 if (self.normalize(phrase) in self.arrBad or
445                     phrase in self.arrBad):
446                     print(('***** PROFANITY PHRASE="%s"' % phrase))
447                     return True
448
449         return False
450
451 #x = profanity_filter()
452 #print(x.filter_bad_words("Fuck this auto erotic shit, it's not safe for work."))
453 #print(x.contains_bad_words("cream pie their daughter."))
454 #print(x.contains_bad_words("If you tell someone your penis is 6 inches it's pretty believable.  If you say it's half a foot no one will believe you."))
455 #print(x.normalize("dickes"));