主要有四种语法错误:
①少词-A类
②错字母-B类
③少字母-C类
④换词-D类
我将每个类分为1,2,3个错误数量,这样共计12个小类:
# FOR 1A
import random
err_data_num = int(len(data)/2)
res = []
for i in range(40166):
s = data[i].split(" ")
word_count = len(s)-1
print("word conut:",word_count)
print("raw:",' '.join(s))
if(word_count >= 3):
local_error_1 = random.randint(1,word_count) # 错误位置
print("Error position:",local_error_1)
s.pop(local_error_1)
if(local_error_1==word_count):
s.append(".")
print("dst:",' '.join(s))
res.append(' '.join(s))
print("")
# FOR 2A
import random
res = []
for i in range( 160667,180750):
s = data[i].split(" ")
word_count = len(s)-1
print("word conut:",word_count)
print("raw:",' '.join(s))
if(word_count >= 3):
local_error_1 = random.randint(1,word_count) # 错误位置
print("Error position 1:",local_error_1)
s.pop(local_error_1)
if(len(s)-1 >= 3):
local_error_2 = random.randint(1,len(s)-1) # 错误位置
print("Error position 2:",local_error_2)
s.pop(local_error_2)
if(local_error_2==len(s)-1):
s.append(".")
print("dst:",' '.join(s))
res.append(' '.join(s))
# FOR 3A
import random
res = []
for i in range(241001,251042):
s = data[i].split(" ")
word_count = len(s)-1
print("word conut:",word_count)
print("raw:",' '.join(s))
if(word_count >= 3):
local_error_1 = random.randint(1,word_count)
print("Error position 1:",local_error_1)
s.pop(local_error_1)
if(len(s)-1 >= 3):
local_error_2 = random.randint(1,len(s)-1)
print("Error position 2:",local_error_2)
s.pop(local_error_2)
if(len(s)-1 >= 3):
local_error_3 = random.randint(1,len(s)-1)
print("Error position 3:",local_error_3)
s.pop(local_error_3)
if(local_error_3==len(s)-1):
s.append(".")
print("dst:",' '.join(s))
res.append(' '.join(s))
# FOR 1B
import random
res = []
vocab = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(40167,80333):
s = data[i].split(" ")
word_count = len(s)-1
if(word_count >= 1):
danci_weizhi_1 = random.randint(1,word_count) # 错词位置
ci = s[danci_weizhi_1] # 取词
print("raw:",ci)
zimu_list = list(ci) # 序列化
local_zimu_error = random.randint(0,len(zimu_list)-1) # 错字母位置
random_vocab = random.randint(0,25)
zimu_list[local_zimu_error] = vocab[random_vocab] # 替换
tmp = ''.join(zimu_list)
print("dst:",tmp)
s[danci_weizhi_1] = tmp
res.append(' '.join(s))
# FOR 2B
import random
res = []
vocab = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(180751,200834):
s = data[i].split(" ")
word_count = len(s)-1
if(word_count >= 1):
#### 第一个
danci_weizhi_1 = random.randint(1,word_count) # 错词位置
ci = s[danci_weizhi_1] # 取词
print("raw:",ci)
zimu_list = list(ci) # 序列化
local_zimu_error = random.randint(0,len(zimu_list)-1) # 错字母位置
random_vocab = random.randint(0,25)
zimu_list[local_zimu_error] = vocab[random_vocab] # 替换
tmp = ''.join(zimu_list)
print("dst:",tmp)
s[danci_weizhi_1] = tmp
#### 第二个
danci_weizhi_2 = random.randint(1,word_count) # 错词位置
ci = s[danci_weizhi_2] # 取词
print("raw:",ci)
zimu_list = list(ci) # 序列化
local_zimu_error = random.randint(0,len(zimu_list)-1) # 错字母位置
random_vocab = random.randint(0,25)
zimu_list[local_zimu_error] = vocab[random_vocab] # 替换
tmp = ''.join(zimu_list)
print("dst:",tmp)
s[danci_weizhi_2] = tmp
res.append(' '.join(s))
# # FOR 3B
import random
res = []
vocab = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(251043,261083):
s = data[i].split(" ")
word_count = len(s)-1
if(word_count >= 1):
#### 第一个
danci_weizhi_1 = random.randint(1,word_count) # 错词位置
ci = s[danci_weizhi_1] # 取词
print("raw:",ci)
zimu_list = list(ci) # 序列化
local_zimu_error = random.randint(0,len(zimu_list)-1) # 错字母位置
random_vocab = random.randint(0,25)
zimu_list[local_zimu_error] = vocab[random_vocab] # 替换
tmp = ''.join(zimu_list)
print("dst:",tmp)
s[danci_weizhi_1] = tmp
#### 第二个
danci_weizhi_2 = random.randint(1,word_count) # 错词位置
ci = s[danci_weizhi_2] # 取词
print("raw:",ci)
zimu_list = list(ci) # 序列化
local_zimu_error = random.randint(0,len(zimu_list)-1) # 错字母位置
random_vocab = random.randint(0,25)
zimu_list[local_zimu_error] = vocab[random_vocab] # 替换
tmp = ''.join(zimu_list)
print("dst:",tmp)
s[danci_weizhi_2] = tmp
#### 第三个
danci_weizhi_3 = random.randint(1,word_count) # 错词位置
ci = s[danci_weizhi_3] # 取词
print("raw:",ci)
zimu_list = list(ci) # 序列化
local_zimu_error = random.randint(0,len(zimu_list)-1) # 错字母位置
random_vocab = random.randint(0,25)
zimu_list[local_zimu_error] = vocab[random_vocab] # 替换
tmp = ''.join(zimu_list)
print("dst:",tmp)
s[danci_weizhi_3] = tmp
res.append(' '.join(s))
#FOR 1C
import random
res = []
for i in range(80334,120500):
s = data[i].split(" ")
word_count = len(s)-1
if(word_count >= 1):
danci_weizhi_1 = random.randint(1,word_count) # 错词位置
ci = s[danci_weizhi_1] # 取词
print("raw:",ci)
zimu_list = list(ci) # 序列化
local_zimu_error = random.randint(0,len(zimu_list)-1) # 错字母位置
zimu_list.pop(local_zimu_error)
tmp = ''.join(zimu_list)
print("dst:",tmp)
s[danci_weizhi_1] = tmp
res.append(' '.join(s))
# #FOR 2C
import random
res = []
for i in range(200835,220918):
s = data[i].split(" ")
word_count = len(s)-1
if(word_count >= 2):
danci_weizhi_1 = random.randint(1,word_count) # 错词位置
ci = s[danci_weizhi_1] # 取词
print("raw:",ci)
zimu_list = list(ci) # 序列化
local_zimu_error = random.randint(0,len(zimu_list)-1) # 错字母位置
zimu_list.pop(local_zimu_error)
tmp = ''.join(zimu_list)
print("dst:",tmp)
s[danci_weizhi_1] = tmp
danci_weizhi_2 = random.randint(1,word_count) # 错词位置
ci2 = s[danci_weizhi_2] # 取词
print("raw:",ci2)
zimu_list2 = list(ci2) # 序列化
if(len(zimu_list2)-1 >0):
local_zimu_error2 = random.randint(0,len(zimu_list2)-1) # 错字母位置
zimu_list2.pop(local_zimu_error2)
tmp2 = ''.join(zimu_list2)
print("dst:",tmp2)
s[danci_weizhi_2] = tmp2
res.append(' '.join(s))
# #FOR 3C
data = []
for line in open("data4.txt","r"):
data.append(line)
len(data)
import random
res = []
for i in range(261084,271124):
s = data[i].split(" ")
word_count = len(s)-1
if(word_count >= 2):
danci_weizhi_1 = random.randint(1,word_count) # 错词位置
ci = s[danci_weizhi_1] # 取词
print("raw:",ci)
zimu_list = list(ci) # 序列化
if(len(zimu_list)-1 > 0):
local_zimu_error = random.randint(0,len(zimu_list)-1) # 错字母位置
zimu_list.pop(local_zimu_error)
tmp = ''.join(zimu_list)
print