-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypo_generator.py
44 lines (38 loc) · 1.34 KB
/
typo_generator.py
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
36
37
38
39
40
41
42
43
44
import pandas as pd
import random
import string
from essential_english import essential_english
def typo_generator(medlist):
typolist = []
c = ["add", "drop", "swap"]
for i in range(0, len(medlist)):
if medlist[i] != "":
k = 0
while k <= 2:
target = medlist[i]
a = len(target)
error = random.randint(0, 2)
numbererrors = random.randint(1, 3)
t = target
typo = None
for j in range(1, numbererrors):
b = random.randint(0, a - 1)
if error == 2:
typo = t[:b - 1] + random.choice(string.ascii_letters) + t[b:]
if error == 1:
typo = t[:b - 1] + t[b:]
if error == 0:
typo = t[:b] + random.choice(string.ascii_letters) + t[b:]
t = typo
a = len(typo)
j += 1
typolist.append([typo, target])
k += 1
return (typolist)
testdata = typo_generator(essential_english)
df = pd.DataFrame(testdata)
print(df)
from pathlib import Path
filepath = Path('testdata.csv')
filepath.parent.mkdir(parents=True, exist_ok=True)
df.to_csv(filepath)