Compare commits

..

No commits in common. "4bc78e36fcccfabe10aebc569353b8bf0bb8bed3" and "2411eba2f0c892c121044e712e7f8cfea08bc92e" have entirely different histories.

4 changed files with 21 additions and 19 deletions

View File

@ -1,5 +1,4 @@
# constants.py
SIMILARITY_VALUE = 0.7
#日期
DATE = "date"
#工程名称

View File

@ -12,8 +12,8 @@ from pydantic import ValidationError
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, SIMILARITY_VALUE
from utils import CheckResult, StandardType
from constants import PROJECT_NAME, PROJECT_DEPARTMENT
# 常量
MODEL_ERNIE_PATH = R"../ernie/output/checkpoint-4160"
@ -47,11 +47,9 @@ slot_recognizer = SlotRecognition(MODEL_UIE_PATH, label_map)
# 设置Flask应用
#标准工程名
standard_project_name_list = load_standard_name('./standard_data/standard_project.txt')
standard_project_name_list = utils.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}")
standard_program_name_list = utils.load_standard_name('./standard_data/standard_program.txt')
app = Flask(__name__)
@ -211,9 +209,7 @@ def agent():
})
#工程名和项目名标准化
print(f"start to check_project_standard_slot")
result, information = check_project_standard_slot(predicted_id, entities)
print(f"end check_project_standard_slot,{result},{information}")
if result == CheckResult.NEEDS_MORE_ROUNDS:
return jsonify({
"code": 10001, "msg": "成功",
@ -290,31 +286,29 @@ def check_lost(int_res, slot):
def check_project_standard_slot(int_res, slot) -> tuple:
intention_list = {3, 4, 5, 6, 7, 8}
if int_res not in intention_list:
return CheckResult.NO_MATCH, ""
return CheckResult.NO_MATCH,""
for key, value in slot.items():
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 >= SIMILARITY_VALUE:
if match_possibility >= 0.9:
slot[key] = match_project
else:
return CheckResult.NEEDS_MORE_ROUNDS, f"抱歉,您说的工程名是{match_project}"
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 >= SIMILARITY_VALUE:
if match_possibility >= 0.9:
slot[key] = match_program
else:
return CheckResult.NEEDS_MORE_ROUNDS, f"抱歉,您说的项目名是{match_program}"
return CheckResult.NO_MATCH, ""
return CheckResult.NO_MATCH,""
def fuzzy_match(user_input, standard_name):
result = process.extract(user_input, standard_name)
return result[0][0], result[0][1]/100
return result[0], result[1]/100
if __name__ == '__main__':
app.run(host='0.0.0.0', port=18074, debug=True)

View File

@ -1,3 +1,4 @@
所属项目部
第八项目管理部(淮北宿州)
第七项目管理部(阜阳)
第十一项目管理部(马鞍山)
@ -20,6 +21,7 @@
第八项目管理部(淮南变电)
第六项目管理部(蚌埠变电)
第十一项目管理部(宿州线路)
第二项目管理部(合肥变电)
第三项目管理部(谯城变、亳州楼)
第五项目管理部(金牛变)

View File

@ -1,9 +1,16 @@
from enum import Enum
def load_standard_name(file_path:str):
try:
with open(file_path, 'r', encoding='utf-8') as file:
lines = [line.strip() for line in file if line.strip()]
return lines
# 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
except FileNotFoundError:
print(f"错误:文件 {file_path} 不存在")
raise FileNotFoundError(f"错误:文件 {file_path} 不存在")