comac_desk_app/GenerateReport/Resources/pyScripts/model_ASR.py

282 lines
12 KiB
Python
Raw Normal View History

2024-11-21 11:50:43 +08:00
import string
punc = string.punctuation
def Cube(content, model_param, flag_asr):
Trigger = ["密封", "立分", "栗方", "立翻", "立芬", "立分", "荔湾", "立风", "立丰", "地方", "立方", "立邦", "立缝", "立棚"]
Param = ["", "", "", "边长"]
Operation = {"散射": 0}
model_operation = []
for i in Trigger:
if i in content:
param_1 = ''
param_2 = ''
param_3 = ''
flag_asr = 1
pos1 = content.rfind(Param[0])
pos2 = content.rfind(Param[1])
pos3 = content.rfind(Param[2])
pos4 = content.rfind(Param[3])
num_end_flag = False
if pos1 != -1:
for j in range(pos1 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_1 = param_1 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
num_end_flag = False
break
if pos2 != -1:
for j in range(pos2 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_2 = param_2 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
num_end_flag = False
break
if pos3 != -1:
for j in range(pos3 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_3 = param_3 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
break
if pos4 != -1:
param_1 = ''
param_2 = ''
param_3 = ''
for j in range(pos4 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_1 = param_1 + temp
param_2 = param_1
param_3 = param_2
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
break
if param_3 == '':
param_3 = '10'
if param_2 == '':
param_2 = '10'
if param_1 == '':
param_1 = '10'
model_param = [param_1, param_2, param_3]
for k in Operation.keys():
if k in content:
model_operation.append(Operation[k])
break
return model_param, flag_asr, model_operation
def Cylinder(content, model_param, flag_asr):
Trigger = ["圆柱", "原柱", "原主", "圆主", "原著", "圆珠", "原处", "云追", "卷住", "原住", "原物", "源物"]
Param = ["", "半径", "直径", ""]
Operation = {"散射": 0}
model_operation = []
for i in Trigger:
if i in content:
param_1 = ''
param_2 = ''
flag_asr = 2
pos1 = content.rfind(Param[0]) # 高
pos2 = content.rfind(Param[1]) # 半径
pos3 = content.rfind(Param[2]) # 直径
pos4 = content.rfind(Param[3]) # 长
num_end_flag = False
if pos1 != -1:
for j in range(pos1 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_1 = param_1 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
num_end_flag = False
break
if pos2 != -1:
for j in range(pos2 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_2 = param_2 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
num_end_flag = False
break
if pos3 != -1:
for j in range(pos3 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_2 = param_2 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
num_end_flag = False
param_2 = str(int(param_2) / 2.0)
break
if pos4 != -1 and pos1 == -1:
for j in range(pos4 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_1 = param_1 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
break
if param_2 == '':
param_2 = '5'
if param_1 == '':
param_1 = '10'
model_param = [param_1, param_2]
for k in Operation.keys():
if k in content:
model_operation.append(Operation[k])
break
return model_param, flag_asr, model_operation
def Sphere(content, model_param, flag_asr):
Trigger = ['', '']
Param = ["半径", "直径"]
Operation = {"散射": 0}
model_operation = []
for i in Trigger:
if i in content:
param_1 = ''
flag_asr = 4
pos1 = content.rfind(Param[0]) # 半径
pos2 = content.rfind(Param[1]) # 直径
num_end_flag = False
if pos1 != -1:
for j in range(pos1 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_1 = param_1 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
num_end_flag = False
break
if pos2 != -1:
for j in range(pos2 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_1 = param_1 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
param_1 = str(int(param_1) / 2.0)
break
if param_1 == '':
param_1 = '5'
model_param = [param_1]
for k in Operation.keys():
if k in content:
model_operation.append(Operation[k])
break
return model_param, flag_asr, model_operation
def Cone(content, model_param, flag_asr):
Trigger = ["圆锥", "云锥", "缘追", "袁尊", "原追", "圆台", "原台"]
Param = ["顶部半径", "底部半径", "半径", "", "", "上半径", "下半径"]
Operation = {"散射": 0}
model_operation = []
for i in Trigger:
if i in content:
param_1 = ''
param_2 = ''
param_3 = ''
flag_asr = 3
pos1 = content.rfind(Param[0]) # 顶部半径
pos2 = content.rfind(Param[1]) # 底部半径
pos3 = content.rfind(Param[2]) # 半径
pos4 = content.rfind(Param[3]) # 高
pos5 = content.rfind(Param[4]) # 长
if pos1 == -1:
pos1 = content.rfind(Param[-2])
if pos2 == -1:
pos2 = content.rfind(Param[-1])
num_end_flag = False
if pos1 != -1:
for j in range(pos1 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_1 = param_1 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
num_end_flag = False
break
if pos2 != -1:
for j in range(pos2 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_2 = param_2 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
num_end_flag = False
break
if pos3 != -1 and pos2 == -1 and pos1 == -1:
for j in range(pos3 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_2 = param_2 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
num_end_flag = False
break
if pos4 != -1:
for j in range(pos4 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_3 = param_3 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
num_end_flag = False
break
if pos5 != -1 and pos4 == -1:
for j in range(pos5 + 1, len(content)):
if content[j].isdecimal() or content[j] in punc:
temp = content[j]
param_3 = param_3 + temp
if j == len(content) - 1 or (not content[j + 1].isdecimal() and not content[j + 1] in punc):
num_end_flag = True
if num_end_flag:
break
if param_3 == '':
param_3 = '10'
if param_2 == '':
param_2 = '5'
if param_1 == '':
param_1 = '0'
model_param = [param_1, param_2, param_3]
for k in Operation.keys():
if k in content:
model_operation.append(Operation[k])
break
return model_param, flag_asr, model_operation
def antenna(content):
Trigger = ["天线"]
pass