prs_server/utils/chkmail/teststr.py
2022-08-08 14:29:03 +08:00

64 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
import copy
txtlist = [{'公司名': [{'end': 353,
'probability': 0.8196403474903491,
'start': 341,
'text': '武汉漫维智能科技有限公司'},
{'end': 20,
'probability': 0.8494340282651791,
'start': 6,
'text': '武汉中软国际科技服务有限公司'},
{'end': 400,
'probability': 0.5690599404322967,
'start': 388,
'text': '武汉漫维智能科技有限公司'},
{'end': 733,
'probability': 0.9766299737741235,
'start': 721,
'text': '广州中道电子科技有限公司'}],
'时间': [{'end': 34,
'probability': 0.6200274175388927,
'start': 22,
'text': '2018.03 - 至今'},
{'end': 383,
'probability': 0.4970208179496325,
'start': 366,
'text': '2017.09 - 2018.04'},
{'end': 752,
'probability': 0.5228238735354154,
'start': 735,
'text': '2015.11 - 2017.09'}]}]
def chkworlkandtime(dictdata):
res = {}
for i in dictdata:
for key, datalist in i.items():
trueDict = {}
for data in datalist:
if data['text'] in trueDict:
if data['probability'] <= trueDict[data['text']]['probability']:
continue
trueDict.update({
data['text']: {
'end': data['end'],
'probability': data['probability'],
'start': data['start'],
}
})
trueList = []
for key1, value1 in trueDict.items():
value1.update({
'text': key1
})
trueDict1 = copy.deepcopy(value1)
trueList.append(trueDict1)
trueList.sort(key=lambda item: item['start'])
res.update({key: trueList})
return res
chkworlkandtime(txtlist)