Skip to content

Commit ae56a8c

Browse files
committed
Package Upload
0 parents  commit ae56a8c

10 files changed

Lines changed: 319 additions & 0 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.csv
2+
*.ipynb
3+
*.zip
4+
__pycache__/
5+
.vscode/
6+
data/test2.txt
7+
PyProfane/main.py

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Ieshaan Saxena
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
6+
software and associated documentation files (the "Software"), to deal in the Software
7+
without restriction, including without limitation the rights to use, copy, modify, merge,
8+
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9+
to whom the Software is furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all copies or
12+
substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
17+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
DEALINGS IN THE SOFTWARE.

PyProfane/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from PyProfane.functions import soundex, censorWord, censorSentences, updateSwearwords, isProfane, getProfaneWords

PyProfane/constants.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
censorSymbols = ['#','%','$','!','&']
2+
censorSymbolsLength = 5
3+
4+
lettersToRemove = {'a', 'e', 'i', 'o', 'u', 'y', 'h', 'w'}
5+
letterMappings = {'b': 1,'f': 1,'p': 1,'v': 1,'c': 2,'g': 2,'j': 2,'k': 2,'q': 2,'s': 2,'x': 2,'z': 2,'d': 3,'t': 3,'l': 4,'m': 5,'n': 5,'r': 6}
6+
7+
profaneWordSoundex = {'anal': 'A540', 'anus': 'A520', 'arse': 'A620', 'ass': 'A220', 'ballsack': 'B422', 'balls': 'B422',
8+
'bastard': 'B236', 'bitch': 'B320', 'biatch': 'B320', 'bloody': 'B430', 'blowjob': 'B421', 'bollock': 'B422', 'bollok': 'B422',
9+
'boner': 'B560', 'boob': 'B100', 'bugger': 'B266', 'bum': 'B500', 'bullcrap': 'B426', 'bullshit': 'B423', 'butt': 'B330',
10+
'buttplug': 'B314', 'clitoris': 'C436', 'clit': 'C430', 'cock': 'C220', 'coon': 'C500', 'crap': 'C610', 'cunt': 'C530',
11+
'damn': 'D550', 'dick': 'D220', 'dildo': 'D430', 'dyke': 'D200', 'fag': 'F200', 'feck': 'F220', 'fellate': 'F433', 'fellatio': 'F433',
12+
'felching': 'F425', 'fuck': 'F220', 'fuckface': 'F212', 'fudgepacker': 'F321', 'flange': 'F452', 'Goddamn': 'G355', 'hell': 'H440',
13+
'homo': 'H500', 'jerk': 'J620', 'jizz': 'J220', 'knobend': 'K515', 'labia': 'L100', 'lmao': 'L500', 'lmfao': 'L510', 'muff': 'M110',
14+
'nigger': 'N266', 'nigga': 'N220', 'penis': 'P520', 'piss': 'P220', 'poop': 'P100', 'prick': 'P622', 'pussy': 'P220',
15+
'scrotum': 'S263', 'sex': 'S200', 'shit': 'S300', 'shithead': 'S330', 'slut': 'S430', 'slutty': 'S433', 'wanker': 'W526',
16+
'smegma': 'S525', 'spunk': 'S152', 'tosser': 'T266', 'turd': 'T630', 'twat': 'T300', 'cumslut': 'C524', 'vagina': 'V250',
17+
'wank': 'W520', 'whore': 'W600', 'cuntfucker': 'C531', 'shag': 'S200', 'dickweed': 'D233', 'asswhore': 'A266', 'titjob': 'T321',
18+
'gangbang': 'G521', 'cuntlick': 'C534', 'horseshit': 'H623', 'dickless': 'D242', 'dammit': 'D533', 'negro': 'N260', 'negroes': 'N262',
19+
'motherfucking': 'M361', 'cockblock': 'C214', 'asspacker': 'A212', 'orgy': 'O620', 'assfucker': 'A212', 'balllicker': 'B426',
20+
'cocklover': 'C241', 'cocksucker': 'C262', 'dicksucker': 'D262', 'asshat': 'A233', 'meatbeatter': 'M313', 'camslut': 'C524',
21+
'fuckbag': 'F212', 'mothafucka': 'M312', 'pussylover': 'P241'}
22+
23+
profaneWords = {'anal', 'anus', 'arse', 'ass', 'ballsack', 'balls', 'bastard', 'bitch', 'biatch', 'bloody', 'blowjob', 'bollock',
24+
'bollok', 'boner', 'boob', 'bugger', 'bum', 'bullcrap', 'bullshit', 'butt', 'buttplug', 'clitoris', 'clit', 'cock', 'coon', 'crap',
25+
'cunt', 'damn', 'dick', 'dildo', 'dyke', 'fag', 'feck', 'fellate', 'fellatio', 'felching', 'fuck', 'fuckface', 'fudgepacker', 'flange',
26+
'Goddamn', 'hell', 'homo', 'jerk', 'jizz', 'knobend', 'labia', 'lmao', 'lmfao', 'muff', 'nigger', 'nigga', 'penis', 'piss', 'poop',
27+
'prick', 'pussy', 'scrotum', 'sex', 'shit', 'shithead', 'slut', 'slutty', 'wanker', 'smegma', 'spunk', 'tosser', 'turd', 'twat',
28+
'cumslut', 'vagina', 'wank', 'whore', 'cuntfucker', 'shag', 'dickweed', 'asswhore', 'titjob', 'gangbang', 'cuntlick', 'horseshit',
29+
'dickless', 'dammit', 'negro', 'negroes', 'motherfucking', 'cockblock', 'asspacker', 'orgy', 'assfucker', 'balllicker', 'cocklover',
30+
'cocksucker', 'dicksucker', 'asshat', 'meatbeatter', 'camslut', 'fuckbag', 'mothafucka', 'pussylover'}
31+
32+
profaneWordsSoundexValues = {'A540', 'A520', 'A620', 'A220', 'B422', 'B422', 'B236', 'B320', 'B320', 'B430', 'B421', 'B422', 'B422',
33+
'B560', 'B100', 'B266', 'B500', 'B426', 'B423', 'B330', 'B314', 'C436', 'C430', 'C220', 'C500', 'C610', 'C530', 'D550', 'D220',
34+
'D430', 'D200', 'F200', 'F220', 'F433', 'F433', 'F425', 'F220', 'F212', 'F321', 'F452', 'G355', 'H440', 'H500', 'J620', 'J220',
35+
'K515', 'L100', 'L500', 'L510', 'M110', 'N266', 'N220', 'P520', 'P220', 'P100', 'P622', 'P220', 'S263', 'S200', 'S300', 'S330',
36+
'S430', 'S433', 'W526', 'S525', 'S152', 'T266', 'T630', 'T300', 'C524', 'V250', 'W520', 'W600', 'C531', 'S200', 'D233', 'A266',
37+
'T321', 'G521', 'C534', 'H623', 'D242', 'D533', 'N260', 'N262', 'M361', 'C214', 'A212', 'O620', 'A212', 'B426', 'C241', 'C262',
38+
'D262', 'A233', 'M313', 'C524', 'F212', 'M312', 'P241'}

PyProfane/functions.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
from PyProfane.constants import censorSymbols, censorSymbolsLength, letterMappings, lettersToRemove, profaneWordSoundex, profaneWordsSoundexValues, profaneWords
2+
from typing import List
3+
import re
4+
import random
5+
try:
6+
from pprint import pprint
7+
printVersion = 1
8+
except:
9+
printVersion = 0
10+
11+
def soundex(term: str) -> str:
12+
'''
13+
Return soundex
14+
'''
15+
query = term.lower()
16+
letters = [char for char in query if char.isalpha()]
17+
18+
if len(letters)!=len(query):
19+
return term
20+
21+
firstLetter = letters[0]
22+
23+
letters = [char for char in letters[1:] if char not in lettersToRemove]
24+
25+
for i in range(len(letters)):
26+
27+
letters[i] = letterMappings[letters[i]]
28+
29+
j = 0
30+
for i in range(1,len(letters)):
31+
if letters[j] != letters[i]:
32+
j+=1
33+
letters[j] = letters[i]
34+
35+
if len(letters)>=3:
36+
letters = [str(i) for i in letters][:3]
37+
else:
38+
while(len(letters) < 3):
39+
letters.append(0)
40+
letters = [str(i) for i in letters][:3]
41+
42+
sound = firstLetter.upper() + ''.join(letters)
43+
44+
return sound
45+
46+
def censorWord(word: str) -> str:
47+
48+
term = list(word)
49+
length = len(term)
50+
if length <= 4:
51+
term[1] = censorSymbols[random.randint(0,censorSymbolsLength-1)]
52+
if length > 4:
53+
censorPositions = random.sample(range(1,length-2), length//2)
54+
for i in censorPositions:
55+
term[i] = censorSymbols[random.randint(0,censorSymbolsLength-1)]
56+
57+
return ''.join(term)
58+
59+
60+
def censorSentences(comments: List[str]) -> List[str]:
61+
62+
sentences = []
63+
64+
for i in comments:
65+
soundexComment = i
66+
allWords = re.findall(r"[\w']+|[.,!?;]", i)
67+
for j in allWords:
68+
value = soundex(j)
69+
if value in profaneWordsSoundexValues:
70+
keys = getAllKeysFromValues(profaneWordSoundex,value)
71+
for key in keys:
72+
if set(j) == set(key):
73+
soundexComment = soundexComment.replace(j,censorWord(j))
74+
sentences.append(soundexComment)
75+
76+
return sentences
77+
78+
def updateSwearwords(filename: str) -> int:
79+
80+
global profaneWordSoundex, profaneWordsSoundexValues, profaneWords
81+
82+
f = open(filename,'r')
83+
words = f.read().splitlines()
84+
yourSoundex = dict()
85+
86+
for i in words:
87+
yourSoundex[i] = soundex(i)
88+
89+
profaneWordSoundex = yourSoundex
90+
profaneWordsSoundexValues = list(yourSoundex.values())
91+
profaneWords = list(yourSoundex.keys())
92+
93+
print('**Your soundex was successfully updated**')
94+
95+
return 0
96+
97+
def isProfane(sentence: str) -> bool:
98+
99+
allWords = re.findall(r"[\w']+|[.,!?;]", sentence)
100+
for j in allWords:
101+
value = soundex(j)
102+
if value in profaneWordsSoundexValues:
103+
keys = getAllKeysFromValues(profaneWordSoundex,value)
104+
for i in keys:
105+
if set(j) == set(i):
106+
return True
107+
108+
return False
109+
110+
def getProfaneWords():
111+
112+
if printVersion:
113+
pprint(profaneWords)
114+
else:
115+
print(profaneWords)
116+
117+
def getAllKeysFromValues(mapping: dict, searchValue: str) -> List[str]:
118+
119+
return [key for (key,value) in mapping.items() if value == searchValue]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## PyProfane

data/comments.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
you're a piece of shit
2+
fucking whore
3+
why you such a cumslut
4+
an online whore
5+
fucking wanker
6+
hey, hope you do great!
7+
sluttyyyy whoreeee
8+
wear a dress

data/swearWords.txt

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
anal
2+
anus
3+
arse
4+
ass
5+
ballsack
6+
balls
7+
bastard
8+
bitch
9+
biatch
10+
bloody
11+
blowjob
12+
bollock
13+
bollok
14+
boner
15+
boob
16+
bugger
17+
bum
18+
bullcrap
19+
bullshit
20+
butt
21+
buttplug
22+
clitoris
23+
clit
24+
cock
25+
coon
26+
crap
27+
cunt
28+
damn
29+
dick
30+
dildo
31+
dyke
32+
fag
33+
feck
34+
fellate
35+
fellatio
36+
felching
37+
fuck
38+
fuckface
39+
fudgepacker
40+
flange
41+
Goddamn
42+
hell
43+
homo
44+
jerk
45+
jizz
46+
knobend
47+
labia
48+
lmao
49+
lmfao
50+
muff
51+
nigger
52+
nigga
53+
penis
54+
piss
55+
poop
56+
prick
57+
pussy
58+
scrotum
59+
sex
60+
shit
61+
shithead
62+
slut
63+
slutty
64+
wanker
65+
smegma
66+
spunk
67+
tosser
68+
turd
69+
twat
70+
cumslut
71+
vagina
72+
wank
73+
whore
74+
cuntfucker
75+
shag
76+
dickweed
77+
asswhore
78+
titjob
79+
gangbang
80+
cuntlick
81+
horseshit
82+
dickless
83+
dammit
84+
negro
85+
negroes
86+
motherfucking
87+
cockblock
88+
asspacker
89+
orgy
90+
assfucker
91+
balllicker
92+
cocklover
93+
cocksucker
94+
dicksucker
95+
asshat
96+
meatbeatter
97+
camslut
98+
fuckbag
99+
mothafucka
100+
pussylover

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description-file=README.md

setup.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import setuptools
2+
3+
with open("README.md", "r") as fileObj:
4+
longDescription = fileObj.read()
5+
6+
setuptools.setup(name="PyProfane",
7+
packages=['PyProfane'],
8+
version="1.0.0",
9+
author="Ieshaan Saxena",
10+
author_email="ieshaan1999@gmail.com",
11+
description="A library to censor and detect offensive words in strings.",
12+
long_description=longDescription,
13+
long_description_content_type="text/markdown",
14+
license="MIT",
15+
url="",
16+
package_data={ 'profanity_check': ['data/model.joblib', 'data/vectorizer.joblib'] },
17+
data_files=[('data',['swearWords.txt', 'comments.txt'])],
18+
classifiers=[
19+
"Development Status :: 3 - Alpha",
20+
"Natural Language :: English",
21+
"Programming Language :: Python :: 3",
22+
"License :: OSI Approved :: MIT License",
23+
"Operating System :: OS Independent",
24+
],)

0 commit comments

Comments
 (0)