多轮问询
This commit is contained in:
parent
487d12b45f
commit
4bc78e36fc
|
|
@ -1,4 +1,5 @@
|
|||
# constants.py
|
||||
SIMILARITY_VALUE = 0.7
|
||||
#日期
|
||||
DATE = "date"
|
||||
#工程名称
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from intentRecognition import IntentRecognition
|
|||
from slotRecognition import SlotRecognition
|
||||
from fuzzywuzzy import process
|
||||
from utils import CheckResult, StandardType, load_standard_name
|
||||
from constants import PROJECT_NAME, PROJECT_DEPARTMENT
|
||||
from constants import PROJECT_NAME, PROJECT_DEPARTMENT, SIMILARITY_VALUE
|
||||
|
||||
# 常量
|
||||
MODEL_ERNIE_PATH = R"../ernie/output/checkpoint-4160"
|
||||
|
|
@ -50,6 +50,8 @@ slot_recognizer = SlotRecognition(MODEL_UIE_PATH, label_map)
|
|||
standard_project_name_list = load_standard_name('./standard_data/standard_project.txt')
|
||||
#标准项目名
|
||||
standard_program_name_list = load_standard_name('./standard_data/standard_program.txt')
|
||||
|
||||
print(f":standard_project_name_list:{standard_project_name_list}")
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
|
|
@ -294,7 +296,7 @@ def check_project_standard_slot(int_res, slot) -> tuple:
|
|||
if key == PROJECT_NAME:
|
||||
match_project, match_possibility = fuzzy_match(value, standard_project_name_list)
|
||||
print(f"fuzzy_match project result:{match_project}, {match_possibility}")
|
||||
if match_possibility >= 0.9:
|
||||
if match_possibility >= SIMILARITY_VALUE:
|
||||
slot[key] = match_project
|
||||
else:
|
||||
return CheckResult.NEEDS_MORE_ROUNDS, f"抱歉,您说的工程名是{match_project}吗"
|
||||
|
|
@ -302,7 +304,7 @@ def check_project_standard_slot(int_res, slot) -> tuple:
|
|||
if key == PROJECT_DEPARTMENT:
|
||||
match_program, match_possibility = fuzzy_match(value, standard_program_name_list)
|
||||
print(f"fuzzy_match program result:{match_program}, {match_possibility}")
|
||||
if match_possibility >= 0.9:
|
||||
if match_possibility >= SIMILARITY_VALUE:
|
||||
slot[key] = match_program
|
||||
else:
|
||||
return CheckResult.NEEDS_MORE_ROUNDS, f"抱歉,您说的项目名是{match_program}吗"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
所属项目部
|
||||
第八项目管理部(淮北宿州)
|
||||
第七项目管理部(阜阳)
|
||||
第十一项目管理部(马鞍山)
|
||||
|
|
@ -21,7 +20,6 @@
|
|||
第八项目管理部(淮南变电)
|
||||
第六项目管理部(蚌埠变电)
|
||||
第十一项目管理部(宿州线路)
|
||||
|
||||
第二项目管理部(合肥变电)
|
||||
第三项目管理部(谯城变、亳州楼)
|
||||
第五项目管理部(金牛变)
|
||||
|
|
|
|||
13
api/utils.py
13
api/utils.py
|
|
@ -1,16 +1,9 @@
|
|||
from enum import Enum
|
||||
def load_standard_name(file_path:str):
|
||||
try:
|
||||
# f = open(file_path, 'r', encoding='utf-8')
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
data = f.read()
|
||||
data = data.split('\n')
|
||||
works = {}
|
||||
for d in data:
|
||||
wk = d[:d.find('(')]
|
||||
works[wk] = d
|
||||
keys = list(works.keys())
|
||||
return keys
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
lines = [line.strip() for line in file if line.strip()]
|
||||
return lines
|
||||
except FileNotFoundError:
|
||||
print(f"错误:文件 {file_path} 不存在")
|
||||
raise FileNotFoundError(f"错误:文件 {file_path} 不存在")
|
||||
|
|
|
|||
Loading…
Reference in New Issue