Adds myq_renderer.py
[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             'erotic',
129             'erotism',
130             'escort',
131             'ethical slut',
132             'eunuch',
133             'faggot',
134             'posts each week',
135             'fecal',
136             'felch',
137             'fellatio',
138             'feltch',
139             'female squirting',
140             'femdom',
141             'figging',
142             'fingering',
143             'fisting',
144             'foot fetish',
145             'footjob',
146             'frotting',
147             'fuck',
148             'fucking',
149             'fuckin',
150             'fuckin\'',
151             'fucked',
152             'fuckers',
153             'fuck buttons',
154             'fuckhead',
155             'fudge packer',
156             'fudgepacker',
157             'futanari',
158             'g-spot',
159             'gspot',
160             'gang bang',
161             'gay sex',
162             'genitals',
163             'giant cock',
164             'girl on',
165             'girl on top',
166             'girls gone wild',
167             'goatcx',
168             'goatse',
169             'goddamn',
170             'gokkun',
171             'golden shower',
172             'goo girl',
173             'goodpoop',
174             'goregasm',
175             'grope',
176             'group sex',
177             'guro',
178             'hand job',
179             'handjob',
180             'hard core',
181             'hardcore',
182             'hentai',
183             'homoerotic',
184             'honkey',
185             'hooker',
186             'horny',
187             'hot chick',
188             'how to kill',
189             'how to murder',
190             'huge fat',
191             'humping',
192             'incest',
193             'intercourse',
194             'jack off',
195             'jail bait',
196             'jailbait',
197             'jerk off',
198             'jigaboo',
199             'jiggaboo',
200             'jiggerboo',
201             'jizz',
202             'juggs',
203             'kike',
204             'kinbaku',
205             'kinkster',
206             'kinky',
207             'knobbing',
208             'leather restraint',
209             'lemon party',
210             'lolita',
211             'lovemaking',
212             'lpt request',
213             'make me come',
214             'male squirting',
215             'masturbate',
216             'masturbated',
217             'masturbating',
218             'menage a trois',
219             'milf',
220             'milfs',
221             'missionary position',
222             'motherfucker',
223             'mound of venus',
224             'mr hands',
225             'muff diver',
226             'muffdiving',
227             'nambla',
228             'nawashi',
229             'negro',
230             'neonazi',
231             'nig nog',
232             'nigga',
233             'nigger',
234             'nimphomania',
235             'nipple',
236             'not safe for',
237             'nsfw',
238             'nsfw images',
239             'nude',
240             'nudity',
241             'nutsack',
242             'nut sack',
243             'nympho',
244             'nymphomania',
245             'octopussy',
246             'omorashi',
247             'one night stand',
248             'orgasm',
249             'orgy',
250             'paedophile',
251             'panties',
252             'panty',
253             'pedobear',
254             'pedophile',
255             'pegging',
256             'pee',
257             'penis',
258             'phone sex',
259             'piss pig',
260             'pissing',
261             'pisspig',
262             'playboy',
263             'pleasure chest',
264             'pole smoker',
265             'ponyplay',
266             'poof',
267             'poop chute',
268             'poopchute',
269             'porn',
270             'pornhub',
271             'porno',
272             'pornography',
273             'prince albert',
274             'pthc',
275             'pube',
276             'pubes',
277             'pussy',
278             'pussies',
279             'queaf',
280             'queer',
281             'raghead',
282             'raging boner',
283             'rape',
284             'raping',
285             'rapist',
286             'rectum',
287             'reverse cowgirl',
288             'rimjob',
289             'rimming',
290             'rosy palm',
291             'rusty trombone',
292             's&m',
293             'sadism',
294             'scat',
295             'schlong',
296             'scissoring',
297             'semen',
298             'sex',
299             'sexo',
300             'sexy',
301             'shaved beaver',
302             'shaved pussy',
303             'shemale',
304             'shibari',
305             'shit',
306             'shota',
307             'shrimping',
308             'slanteye',
309             'slut',
310             'smut',
311             'snatch',
312             'snowballing',
313             'sodomize',
314             'sodomy',
315             'spic',
316             'spooge',
317             'spread legs',
318             'strap on',
319             'strapon',
320             'strappado',
321             'strip club',
322             'style doggy',
323             'suck',
324             'sucks',
325             'suicide girls',
326             'sultry women',
327             'swastika',
328             'swinger',
329             'tainted love',
330             'taste my',
331             'tea bagging',
332             'threesome',
333             'throating',
334             'tied up',
335             'tight white',
336             'tit',
337             'tits',
338             'titties',
339             'titty',
340             'tongue in a',
341             'topless',
342             'tosser',
343             'towelhead',
344             'tranny',
345             'tribadism',
346             'tub girl',
347             'tubgirl',
348             'tushy',
349             'twat',
350             'twink',
351             'twinkie',
352             'undressing',
353             'upskirt',
354             'urethra play',
355             'urophilia',
356             'vagina',
357             'venus mound',
358             'vibrator',
359             'violet blue',
360             'violet wand',
361             'vorarephilia',
362             'voyeur',
363             'vulva',
364             'wank',
365             'wet dream',
366             'wetback',
367             'white power',
368             'whore',
369             'women rapping',
370             'wrapping men',
371             'wrinkled starfish',
372             'xx',
373             'xxx',
374             'yaoi',
375             'yellow showers',
376             'yiffy',
377             'zoophilia',
378         ]
379
380     def normalize(self, text):
381         result = text.lower()
382         result = result.replace('_', ' ')
383         for x in string.punctuation:
384             result = result.replace(x, '')
385         result = re.sub(
386             r"e?s$", "", result)
387         return result
388
389     def filter_bad_words(self, text):
390         badWordMask = '!@#$%!@#$%^~!@%^~@#$%!@#$%^~!'
391
392         brokenStr1 = text.split()
393         for word in brokenStr1:
394             if (self.normalize(word) in self.arrBad or
395                 word in self.arrBad):
396                 print('***** PROFANITY WORD="%s"' % word)
397                 text = text.replace(word, badWordMask[:len(word)])
398
399         if len(brokenStr1) > 1:
400             bigrams = zip(brokenStr1, brokenStr1[1:])
401             for bigram in bigrams:
402                 phrase = "%s %s" % (bigram[0], bigram[1])
403                 if (self.normalize(phrase) in self.arrBad or
404                     phrase in self.arrBad):
405                     print('***** PROFANITY PHRASE="%s"' % phrase)
406                     text = text.replace(bigram[0], badWordMask[:len(bigram[0])])
407                     text = text.replace(bigram[1], badWordMask[:len(bigram[1])])
408
409         if len(brokenStr1) > 2:
410             trigrams = zip(brokenStr1, brokenStr1[1:], brokenStr1[2:])
411             for trigram in trigrams:
412                 phrase = "%s %s %s" % (trigram[0], trigram[1], trigram[2])
413                 if (self.normalize(phrase) in self.arrBad or
414                     phrase in self.arrBad):
415                     print('***** PROFANITY PHRASE="%s"' % phrase)
416                     text = text.replace(trigram[0], badWordMask[:len(trigram[0])])
417                     text = text.replace(trigram[1], badWordMask[:len(trigram[1])])
418                     text = text.replace(trigram[2], badWordMask[:len(trigram[2])])
419         return text
420
421     def contains_bad_words(self, text):
422         brokenStr1 = text.split()
423         for word in brokenStr1:
424             if (self.normalize(word) in self.arrBad or
425                 word in self.arrBad):
426                 print('***** PROFANITY WORD="%s"' % word)
427                 return True
428
429         if len(brokenStr1) > 1:
430             bigrams = zip(brokenStr1, brokenStr1[1:])
431             for bigram in bigrams:
432                 phrase = "%s %s" % (bigram[0], bigram[1])
433                 if (self.normalize(phrase) in self.arrBad or
434                     phrase in self.arrBad):
435                     print('***** PROFANITY PHRASE="%s"' % phrase)
436                     return True
437
438         if len(brokenStr1) > 2:
439             trigrams = zip(brokenStr1, brokenStr1[1:], brokenStr1[2:])
440             for trigram in trigrams:
441                 phrase = "%s %s %s" % (trigram[0], trigram[1], trigram[2])
442                 if (self.normalize(phrase) in self.arrBad or
443                     phrase in self.arrBad):
444                     print('***** PROFANITY PHRASE="%s"' % phrase)
445                     return True
446
447         return False
448
449 #x = profanity_filter()
450 #print(x.filter_bad_words("Fuck this auto erotic shit, it's not safe for work."))
451 #print(x.contains_bad_words("cream pie their daughter."))
452 #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."))
453 #print(x.normalize("dickes"));