优化科室的匹配
This commit is contained in:
@@ -221,6 +221,22 @@ def search_hospital(hospital):
|
||||
return best_match
|
||||
|
||||
|
||||
def search_department(department):
|
||||
cut_list = jieba.lcut(department)
|
||||
session = MysqlSession()
|
||||
ylks = session.query(BdYlks.pk_ylks, BdYlks.name).filter(BdYlks.name.like(f"%{'%'.join(cut_list)}%")).all()
|
||||
if not ylks:
|
||||
filter_keywords = cut_list
|
||||
for filter_keyword in filter_keywords:
|
||||
ylks = session.query(BdYlks.pk_ylks, BdYlks.name).filter(BdYlks.name.like(f"%{filter_keyword}%")).all()
|
||||
if ylks:
|
||||
break
|
||||
session.close()
|
||||
ylks = {row.pk_ylks: row.name for row in ylks}
|
||||
best_match = process.extractOne(department, ylks, scorer=fuzz.partial_token_set_ratio)
|
||||
return best_match
|
||||
|
||||
|
||||
def settlement_task(pk_phhd, settlement_list, identity):
|
||||
settlement_list_ie_result = information_extraction(SETTLEMENT_IE, settlement_list, identity)
|
||||
settlement_data = {
|
||||
@@ -299,17 +315,24 @@ def discharge_task(pk_phhd, discharge_record, identity):
|
||||
if best_match:
|
||||
discharge_data["pk_yljg"] = best_match[2]
|
||||
if departments:
|
||||
department_values = []
|
||||
for dept in departments:
|
||||
department_values += parse_department(dept)
|
||||
department_values = list(set(department_values))
|
||||
if department_values:
|
||||
session = MysqlSession()
|
||||
ylks = session.query(BdYlks.pk_ylks, BdYlks.name) \
|
||||
.filter(BdYlks.name.in_(department_values)).limit(1).one_or_none()
|
||||
session.close()
|
||||
if ylks:
|
||||
discharge_data["pk_ylks"] = ylks.pk_ylks
|
||||
match_departments = []
|
||||
for department in departments:
|
||||
parsed_departments = parse_department(department)
|
||||
for parsed_department in parsed_departments:
|
||||
search_result = search_department(parsed_department)
|
||||
match_departments.append(search_result)
|
||||
if search_result and search_result[1] == 100:
|
||||
break
|
||||
best_match = None
|
||||
best_score = 0
|
||||
for match_department in match_departments:
|
||||
if match_department and match_department[1] > best_score:
|
||||
best_match = match_department
|
||||
best_score = match_department[1]
|
||||
if best_score == 100:
|
||||
break
|
||||
if best_match:
|
||||
discharge_data["pk_ylks"] = best_match[2]
|
||||
save_or_update_ie(ZxIeDischarge, pk_phhd, discharge_data)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user