Spaces:
Runtime error
Runtime error
File size: 987 Bytes
88c82eb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
class RandomNoiser():
def __init__(self, n_words):
self.n_words = n_words
def noiser(self, text):
self.text = text
json_dict = {}
for i in range(0, self.n_words):
lower_text = string.ascii_lowercase
sl = list(lower_text)
random_character = random.choice(sl)
text = re.sub('\W+',' ', self.text.lower())
list_ = text.split(" ")
if "" in list_:
list_.remove("")
ch = random.choice(list_)
if ch not in ["", " "]:
k = ch.replace(random.choice(ch), random.choice(sl))
else:
k = ch.replace(ch, random.choice(sl))
if ch not in json_dict.keys():
json_dict[ch] = k
nl = []
for x in list_:
if x not in json_dict.keys():
nl.append(x)
else:
nl.append(json_dict[x])
return (" ").join(nl) |