Procházet zdrojové kódy

调整channel废标分类;新增角色金额分级;新增业绩去除;新增地区匹配

lsm před 2 roky
rodič
revize
c57b2ae649

binární
BiddingKG/dl/industry/model/channel_foolcut_doc_type_withoutEmb.ckpt.data-00000-of-00001


binární
BiddingKG/dl/industry/model/channel_foolcut_doc_type_withoutEmb.ckpt.index


binární
BiddingKG/dl/industry/model/channel_foolcut_doc_type_withoutEmb.ckpt.meta


+ 2 - 0
BiddingKG/dl/industry/model/checkpoint

@@ -0,0 +1,2 @@
+model_checkpoint_path: "channel_foolcut_doc_type_withoutEmb.ckpt"
+all_model_checkpoint_paths: "channel_foolcut_doc_type_withoutEmb.ckpt"

+ 125 - 2
BiddingKG/dl/interface/Preprocessing.py

@@ -1134,6 +1134,8 @@ def get_preprocessed_outline(soup):
     pattern_list = [pattern_0, pattern_1, pattern_2, pattern_3]
 
     body = soup.find("body")
+    if body == None:
+        return soup  # 修复 无body的报错 例子:264419050
     body_child = body.find_all(recursive=False)
     deal_part = body
     # print(body_child[0]['id'])
@@ -1913,6 +1915,119 @@ def attachment_filelink(soup):
         # print('格式化输出',soup.prettify())
         return soup
 
+def del_achievement(text):
+    if re.search('中标|成交|入围|结果|评标|开标|候选人', text[:500]) == None or re.search('业绩', text) == None:
+        return text
+    p0 = '[,。;]((\d{1,2})|\d{1,2}、)[\w、]{,8}:|((\d{1,2})|\d{1,2}、)|。' # 例子 264392818
+    p1 = '业绩[:,](\d、[-\w()、]{6,30}(工程|项目|勘察|设计|施工|监理|总承包|采购|更新)[\w()]{,10}[,;])+' # 例子 257717618
+    p2 = '(类似业绩情况:|业绩:)(\w{,20}:)?(((\d)|\d、)项目名称:[-\w(),;、\d\s:]{5,100}[;。])+' # 例子 264345826
+    p3 = '(投标|类似|(类似)?项目|合格|有效|企业|工程)?业绩(名称|信息|\d)?:(项目名称:)?[-\w()、]{6,50}(项目|工程|勘察|设计|施工|监理|总承包|采购|更新)'
+
+    l = []
+    tmp = []
+    for it in re.finditer(p0, text):
+        if it.group(0)[-3:] in ['业绩:', '荣誉:']:
+            if tmp != []:
+                del_text = text[tmp[0]:it.start()]
+                l.append(del_text)
+                tmp = []
+            tmp.append(it.start())
+        elif tmp != []:
+            del_text = text[tmp[0]:it.start()]
+            l.append(del_text)
+            tmp = []
+    if tmp != []:
+        del_text = text[tmp[0]:]
+        l.append(del_text)
+    for del_text in l:
+        text = text.replace(del_text, '')
+        # print('删除业绩信息:', del_text)
+
+    for rs in re.finditer(p1, text):
+        # print('删除业绩信息:', rs.group(0))
+        text = text.replace(rs.group(0), '')
+
+    for rs in re.finditer(p2, text):
+        # print('删除业绩信息:', rs.group(0))
+        text = text.replace(rs.group(0), '')
+
+    for rs in re.finditer(p3, text):
+        # print('删除业绩信息:', rs.group(0))
+        text = text.replace(rs.group(0), '')
+    return text
+
+def del_tabel_achievement(soup):
+    if re.search('中标|成交|入围|结果|评标|开标|候选人', soup.text[:800]) == None or re.search('业绩', soup.text)==None:
+        return None
+    p1 = '中标(单位|候选人)的?(企业|项目|项目负责人|\w{,5})?业绩|类似(项目)?业绩|\w{,10}业绩$|业绩(公示|情况|荣誉)'
+
+    for tag in soup.find_all('table'):
+        pre_text = tag.findPreviousSibling().text.strip() if tag.findPreviousSibling() != None else ""
+        tr_text = tag.find('tr').text.strip() if tag.find('tr') != None else ""
+        #     print(re.search(p1, pre_text),pre_text, len(pre_text), re.findall('序号|中标候选人名称|项目名称|工程名称|合同金额|建设单位|业主', tr_text))
+        if re.search(p1, pre_text) and len(pre_text) < 20 and tag.find('tr') != None and len(tr_text)<100:
+            _count = 0
+            for td in tag.find('tr').find_all('td'):
+                td_text = td.text.strip()
+                if len(td_text) > 25:
+                    break
+                if len(td_text) < 25 and re.search('中标候选人|(项目|业绩|工程)名称|\w{,10}业绩$|合同金额|建设单位|采购单位|业主|甲方', td_text):
+                    _count += 1
+                if _count >=2:
+                    pre_tag = tag.findPreviousSibling().extract()
+                    del_tag = tag.extract()
+                    # print('删除表格业绩内容', pre_tag.text + del_tag.text)
+        elif re.search('业绩名称', tr_text) and re.search('建设单位|采购单位|业主', tr_text) and len(tr_text)<100:
+            del_tag = tag.extract()
+            # print('删除表格业绩内容', del_tag.text)
+    del_trs = []
+    for tag in soup.find_all('table'):
+        text = tag.text
+        if re.search('业绩', text) == None:
+            continue
+        # for tr in tag.find_all('tr'):
+        trs = tag.find_all('tr')
+        i = 0
+        while i < len(trs):
+            tr = trs[i]
+            if len(tr.find_all('td'))==2 and tr.td!=None and tr.td.findNextSibling()!=None:
+                td1_text =tr.td.text
+                td2_text =tr.td.findNextSibling().text
+                if re.search('业绩', td1_text)!=None and len(td1_text)<10 and len(re.findall('(\d、|(\d))?[-\w()、]+(工程|项目|勘察|设计|施工|监理|总承包|采购|更新)', td2_text))>=2:
+                    # del_tag = tr.extract()
+                    # print('删除表格业绩内容', del_tag.text)
+                    del_trs.append(tr)
+            elif tr.td != None and re.search('^业绩|业绩$', tr.td.text.strip()) and len(tr.td.text.strip())<25:
+                rows = tr.td.attrs.get('rowspan', '')
+                cols = tr.td.attrs.get('colspan', '')
+                if rows.isdigit() and int(rows)>2:
+                    for j in range(int(rows)):
+                        if i+j < len(trs):
+                            del_trs.append(trs[i+j])
+                    i += j
+                elif cols.isdigit() and int(cols)>3 and len(tr.find_all('td'))==1 and i+2 < len(trs):
+                    next_tr_cols = 0
+                    td_num = 0
+                    for td in trs[i+1].find_all('td'):
+                        td_num += 1
+                        if td.attrs.get('colspan', '').isdigit():
+                            next_tr_cols += int(td.attrs.get('colspan', ''))
+                    if next_tr_cols == int(cols):
+                        del_trs.append(tr)
+                        for j in range(1,len(trs)-i):
+                            if len(trs[i+j].find_all('td')) == 1:
+                                break
+                            elif len(trs[i+j].find_all('td')) >= td_num-1:
+                                del_trs.append(trs[i+j])
+                            else:
+                                break
+                        i += j
+            i += 1
+        for tr in del_trs:
+            del_tag = tr.extract()
+            # print('删除表格业绩内容', del_tag.text)
+
+
 def get_preprocessed_article(articles,cost_time = dict(),useselffool=True):
     '''
     :param articles: 待处理的article source html
@@ -1947,6 +2062,10 @@ def get_preprocessed_article(articles,cost_time = dict(),useselffool=True):
         start_time = time.time()
         # article_processed = tableToText(BeautifulSoup(sourceContent,"lxml"))
         article_processed = BeautifulSoup(sourceContent,"lxml")
+
+        '''表格业绩内容删除'''
+        del_tabel_achievement(article_processed)
+
         '''特别数据源对 BeautifulSoup(html) 做特别修改'''
         if web_source_no in ["00753-14","DX008357-11","18021-2"]:
             article_processed = special_treatment(article_processed, web_source_no)
@@ -1973,6 +2092,10 @@ def get_preprocessed_article(articles,cost_time = dict(),useselffool=True):
         article_processed = re.sub('任务(?=编号[::])', '项目',article_processed)  # 2022/08/10 修正为项目编号
         article_processed = article_processed.replace('招标(建设)单位', '招标单位')  #2022/8/10 修正预测不到表达
         article_processed = re.sub('(招标|采购)人(概况|信息):?[,。]', '采购人信息:', article_processed)  # 2022/8/10统一表达
+
+        '''去除业绩内容'''
+        article_processed = del_achievement(article_processed)
+
         # 修复OCR金额中“,”、“。”识别错误
         article_processed_list = article_processed.split("##attachment##")
         if len(article_processed_list)>1:
@@ -2240,7 +2363,7 @@ def get_preprocessed_entitys(list_sentences,useselffool=True,cost_time=dict()):
 
             '''正则识别角色实体  经营部|经销部|电脑部|服务部|复印部|印刷部|彩印部|装饰部|修理部|汽修部|修理店|零售店|设计店|服务店|家具店|专卖店|分店|文具行|商行|印刷厂|修理厂|维修中心|修配中心|养护中心|服务中心|会馆|文化馆|超市|门市|商场|家具城|印刷社|经销处'''
             for it in re.finditer(
-                    '(?P<text_key_word>(((单一来源|中标|中选|中价|成交)(供应商|供货商|服务商|候选人|单位|人))|(供应商|供货商|服务商|候选人))(名称)?[为::]+)(?P<text>([^,。、;《::]{5,20})(厂|中心|超市|门市|商场|工作室|文印室|城|部|店|站|馆|行|社|处))[,。]',
+                    '(?P<text_key_word>(((单一来源|中标|中选|中价|成交)(供应商|供货商|服务商|候选人|单位|人))|(供应商|供货商|服务商|候选人))(名称)?[为::]+)(?P<text>([()\w]{5,20})(厂|中心|超市|门市|商场|工作室|文印室|城|部|店|站|馆|行|社|处))[,。]',
                     sentence_text):
                 for k, v in it.groupdict().items():
                     if k == 'text_key_word':
@@ -2256,7 +2379,7 @@ def get_preprocessed_entitys(list_sentences,useselffool=True,cost_time=dict()):
                     ner_entitys.append((b, e, 'company', entity))
 
             for it in re.finditer(
-                    '(?P<text_key_word>((建设|招租|招标|采购)(单位|人)|业主)(名称)?[为::]+)(?P<text>\w{2,4}[省市县区镇]([^,。、;《]{2,20})(管理处|办公室|委员会|村委会|纪念馆|监狱|管教所|修养所|社区|农场|林场|羊场|猪场|石场|村|幼儿园))[,。]',
+                    '(?P<text_key_word>((建设|招租|招标|采购)(单位|人)|业主)(名称)?[为::]+)(?P<text>\w{2,4}[省市县区镇]([()\w]{2,20})(管理处|办公室|委员会|村委会|纪念馆|监狱|管教所|修养所|社区|农场|林场|羊场|猪场|石场|村|幼儿园))[,。]',
                     sentence_text):
                 for k, v in it.groupdict().items():
                     if k == 'text_key_word':

+ 19 - 4
BiddingKG/dl/interface/extract.py

@@ -106,7 +106,7 @@ def extractCount(extract_dict):
         extract_count += 1
     return extract_count
 
-def predict(doc_id,text,title="",page_time="",web_source_no='',original_docchannel='',**kwargs):
+def predict(doc_id,text,title="",page_time="",web_source_no='',web_source_name="",original_docchannel='',**kwargs):
     cost_time = dict()
 
     start_time = time.time()
@@ -157,6 +157,16 @@ def predict(doc_id,text,title="",page_time="",web_source_no='',original_docchann
     predictor.getPredictor("tendereeRuleRecall").predict(list_articles,list_sentences,list_entitys, codeName)
     cost_time["tendereeRuleRecall"] = round(time.time()-start_time,2)
 
+    '''规则调整角色概率'''
+    start_time = time.time() #
+    predictor.getPredictor("rolegrade").predict(list_sentences,list_entitys)
+    cost_time["rolegrade"] = round(time.time()-start_time,2)
+
+    '''规则调整金额概率'''
+    start_time = time.time() #
+    predictor.getPredictor("moneygrade").predict(list_sentences,list_entitys)
+    cost_time["moneygrade"] = round(time.time()-start_time,2)
+
     start_time = time.time() #联系人模型提取
     predictor.getPredictor("epc").predict(list_sentences,list_entitys)
     log("get epc done of doc_id%s"%(doc_id))
@@ -224,13 +234,18 @@ def predict(doc_id,text,title="",page_time="",web_source_no='',original_docchann
     '''行业分类提取,需要用标题、项目名称、产品、及prem 里面的角色'''
     industry = predictor.getPredictor('industry').predict(title, project=codeName[0]['name'], product=','.join(product_list), prem=prem)
 
+    '''地区获取'''
+    start_time = time.time()
+    district = predictor.getPredictor('district').predict(project_name=codeName[0]['name'], prem=prem, web_source_name=web_source_name)
+    cost_time["district"] = round(time.time() - start_time, 2)
+
     '''限制行业最高金额'''
     getAttributes.limit_maximum_amount(prem, industry)
 
 
     # data_res = Preprocessing.union_result(Preprocessing.union_result(codeName, prem),list_punish_dic)[0]
     # data_res = Preprocessing.union_result(Preprocessing.union_result(Preprocessing.union_result(codeName, prem),list_punish_dic), list_channel_dic)[0]
-    data_res = dict(codeName[0], **prem[0], **channel_dic, **product_attrs[0], **product_attrs[1], **payment_way_dic, **fail_reason, **industry)
+    data_res = dict(codeName[0], **prem[0], **channel_dic, **product_attrs[0], **product_attrs[1], **payment_way_dic, **fail_reason, **industry, **district)
     data_res["doctitle_refine"] = doctitle_refine
     data_res["nlp_enterprise"] = nlp_enterprise
     data_res["nlp_enterprise_attachment"] = nlp_enterprise_attachment
@@ -249,7 +264,7 @@ def predict(doc_id,text,title="",page_time="",web_source_no='',original_docchann
     #         log("type:%s,text:%s,label:%s,values:%s,sentence:%s,begin_index:%s,end_index:%s"%
     #               (str(_entity.entity_type),str(_entity.entity_text),str(_entity.label),str(_entity.values),str(_entity.sentence_index),
     #                str(_entity.begin_index),str(_entity.end_index)))
-    return json.dumps(data_res,cls=MyEncoder,sort_keys=True,indent=4,ensure_ascii=False)#, list_articles[0].content, list_entitys[0]
+    return json.dumps(data_res,cls=MyEncoder,sort_keys=True,indent=4,ensure_ascii=False)#, list_articles[0].content, get_ent_context(list_sentences, list_entitys)
 
 
 def test(name,content):
@@ -273,7 +288,7 @@ def get_ent_context(list_sentences, list_entitys):
                 b = _entity.wordOffset_begin
                 e = _entity.wordOffset_end
                 # print("%s %d %.4f; %s  %s  %s"%(_entity.entity_type, _entity.label, _entity.values[_entity.label], s[max(0, b-10):b], _entity.entity_text, s[e:e+10]))
-                rs_list.append("%s %d %.4f; %s  %s  %s"%(_entity.entity_type, _entity.label, _entity.values[_entity.label], s[max(0, b-10):b], _entity.entity_text, s[e:e+10]))
+                rs_list.append("%s %d %.4f; %s ## %s ## %s"%(_entity.entity_type, _entity.label, _entity.values[_entity.label], s[max(0, b-10):b], _entity.entity_text, s[e:e+10]))
     return '\n'.join(rs_list)
 
 if __name__=="__main__":

+ 4 - 2
BiddingKG/dl/interface/getAttributes.py

@@ -662,6 +662,8 @@ def getPackagesFromArticle(list_sentence,list_entity):
                     dict_packageCode[temp_package_number] = code
                 PackageSet.add(temp_package_number)
         for iter in re.finditer(package_number_pattern,content):
+            if re.match('\d', iter.group(0)) and iter.end()<len(content) and content[iter.end()].isdigit():  # 排除2.10标段3 这种情况
+                continue
             temp_package_number = re.findall(number_pattern,content[iter.span()[0]:iter.span()[1]])[0]
             if re.search(re_digital, temp_package_number):
                 temp_package_number = str(int(temp_package_number))
@@ -3023,7 +3025,7 @@ def correct_rolemoney(prem, total_product_money):
                     print('表格产品价格修正中标价格报错:%s'%e)
 
 def limit_maximum_amount(prem, industry):
-    indu = industry.get('class_name', '')
+    indu = industry['industry'].get('class_name', '')
     indu_amount = {
         '计算机设备': 200000000,
         '办公设备': 100000000,
@@ -3035,7 +3037,7 @@ def limit_maximum_amount(prem, industry):
         '工程技术与设计服务': 1000000000,
         '工程评价服务': 100000000,
         '其他工程服务': 100000000,
-        '工程监理服务': 1000000000,
+        '工程监理服务': 100000000,
         '工程造价服务': 100000000
     }
     if indu in indu_amount:

+ 253 - 21
BiddingKG/dl/interface/predictor.py

@@ -17,6 +17,7 @@ sys.path.append(os.path.abspath("../.."))
 from BiddingKG.dl.common.Utils import *
 from BiddingKG.dl.interface.modelFactory import *
 import tensorflow as tf
+import pandas as pd
 from BiddingKG.dl.product.data_util import decode, process_data
 from BiddingKG.dl.interface.Entitys import Entity
 from BiddingKG.dl.complaint.punish_predictor import Punish_Extract
@@ -49,7 +50,10 @@ dict_predictor = {"codeName":{"predictor":None,"Lock":RLock()},
                   "channel": {"predictor": None, "Lock": RLock()},
                   "deposit_payment_way": {"predictor": None, "Lock": RLock()},
                   "total_unit_money": {"predictor": None, "Lock": RLock()},
-                  "industry": {"predictor": None, "Lock": RLock()}
+                  "industry": {"predictor": None, "Lock": RLock()},
+                  "rolegrade": {"predictor": None, "Lock": RLock()},
+                  "moneygrade": {"predictor": None, "Lock": RLock()},
+                  "district": {"predictor": None, "Lock": RLock()}
                   }
 
 
@@ -87,6 +91,12 @@ def getPredictor(_type):
                     dict_predictor[_type]["predictor"] = TotalUnitMoney()
                 if _type == 'industry':
                     dict_predictor[_type]["predictor"] = IndustryPredictor()
+                if _type == 'rolegrade':
+                    dict_predictor[_type]["predictor"] = RoleGrade()
+                if _type == 'moneygrade':
+                    dict_predictor[_type]["predictor"] = MoneyGrade()
+                if _type == 'district':
+                    dict_predictor[_type]["predictor"] = DistrictPredictor()
             return dict_predictor[_type]["predictor"]
     raise NameError("no this type of predictor")
 
@@ -1130,7 +1140,7 @@ class RoleRulePredictor():
         self.pattern_tenderee_left_w1 = "(?P<tenderee_left_w1>(,|。|^)(项目)?((遴选|寻源|采购|招标|竞价|议价|比选|委托|询比?价|比价|评选|谈判|邀标|邀请|洽谈|约谈|选取|抽取|抽选)" \
                                      "(人|公司|单位|组织|用户|业主|主体|方|部门))" \
                                      "(是|为|:|:|\s*)+$)"
-        self.pattern_tenderee_center = "(?P<tenderee_center>(受.{5,20}委托|现将[\w()()]{5,20}[\d年月季度至()]+采购意向))"
+        self.pattern_tenderee_center = "(?P<tenderee_center>(受.{5,20}委托|现将[\w()()]{5,20}[\d年月季度至()]+采购意向|尊敬的供应商(伙伴)?:\w{5,20}(以下简称“\w{2,5}”)))"
         self.pattern_tenderee_right = "(?P<tenderee_right>^([((](以下简称)?[,\"“]*(招标|采购)(人|单位|机构)[,\"”]*[))]|^委托|^将于[\d年月日,::]+进行|^现委托|^的\w{2,10}正在进行|[\d年月季度至]+采购意向|^)?的招标工作已圆满结束))"  #|(^[^.。,,::](采购|竞价|招标|施工|监理|中标|物资)(公告|公示|项目|结果|招标))|的.*正在进行询比价)
         self.pattern_tendereeORagency_right = "(?P<tendereeORagency_right>(^拟对|^现?就|^现对))"
         self.pattern_agency_left = "(?P<agency_left>(代理(?:人|机构|公司|单位|组织)|专业采购机构|集中采购机构|招标组织机构|交易机构|集采机构|[招议))]+标机构)(名称)?(.{,4}名,?称|全称|是|为|:|:|[,,]?\s*)$|(受.{5,20}委托,?$))"
@@ -1138,14 +1148,14 @@ class RoleRulePredictor():
         # 2020//11/24 大网站规则 中标关键词添加 选定单位|指定的中介服务机构
         self.pattern_winTenderer_left = "(?P<winTenderer_left>(乙|承做|施工|供货|承包|承建|承租|竞得|受让|签约)(候选)?(人|单位|机构|供应商|方|公司|厂商|商)[::是为]+$|" \
                                         "(选定单位|指定的中介服务机构|实施主体|承制单位|供方)[::是为]+$|((评审结果|名次|排名|中标结果)[::]*第?[一1]名?)[::是为]+$|" \
-                                        "单一来源(采购)?(供应商|供货商|服务商|方式向)$|((中标|成交)(结果|信息))[::是为]+$|(供应|供货|承销|承保|承包|承接|服务|实施)(机构|单位|商|方)(名称)?[::是为]+$)"
+                                        "单一来源(采购)?(供应商|供货商|服务商|方式向)$|((中标|成交)(结果|信息))[::是为]+$|(供应|供货|承销|承保|承包|承接|服务|实施|合作)(机构|单位|商|方)(名称)?[::是为]+$)"
         self.pattern_winTenderer_left_w0 = "(?P<winTenderer_left_w1>(,|。|^)((中标(投标)?|中选|中价|成交)(候选)?(人|单位|机构|供应商|客户|方|公司|厂商|商)|第?[一1]名)(名称)?[,,]?([((]按综合排名排序[))])?[::,,]$)" #解决表头识别不到加逗号情况,需前面为,。空
         self.pattern_winTenderer_left_w1 = "(?P<winTenderer_left_w1>(中标|中选|中价|成交)(候选)?(人|单位|机构|供应商|客户|方|公司|厂商|商)(名称)?([((]按综合排名排序[))])?[::是为]+$)" #取消逗号 并拒绝执行改进计划的供应商,华新水泥将可能终止与其合作关系
         # self.pattern_winTenderer_center = "(?P<winTenderer_center>第[一1].{,20}[是为]((中标|中选|中价|成交|施工)(人|单位|机构|供应商|公司)|供应商)[::是为])"
         # self.pattern_winTenderer_right = "(?P<winTenderer_right>(^[是为\(]((采购(供应商|供货商|服务商)|(第[一1]|预)?(拟?(中标|中选|中价|成交)(候选)?(人|单位|机构|供应商|公司|厂商)))))|^(报价|价格)最低,确定为本项目成交供应商)"
         self.pattern_winTenderer_right = "(?P<winTenderer_right>(^[是为]((采购|中标)(供应商|供货商|服务商)|(第[一1]|预)?(拟?(中标|中选|中价|成交)(候选)?(人|单位|机构|供应商|公司|厂商)))|" \
-                                        "^(报价|价格)最低,确定为本项目成交供应商|^:贵公司参与|^:?你方于|^中标。|^[成作]?为([\w、()()]+|本|此|该)项目的?(成交|中选|中标|服务)(供应商|单位|人)|^[((]中标人名称[))]))"
-        self.pattern_winTenderer_whole = "(?P<winTenderer_center>贵公司.{,15}以.{,15}中标|最终由.{,15}竞买成功|经.{,15}决定[以由].{,15}公司中标|决定由.{5,20}承办|(谈判结果:|确定)由.{5,20}(向我单位)?供货)|中标通知书.{,15}你方"   # 2020//11/24 大网站规则 中标关键词添加 谈判结果:由.{5,20}供货
+                                        "^(报价|价格)最低,确定为本项目成交供应商|^:贵公司参与|^:?你方于|^中标。|^[成作]?为([\w、()()]+|本|此|该)项目的?(成交|中选|中标|服务)(供应商|单位|人)|^[((](中标|成交|承包)人名??[))]))"
+        self.pattern_winTenderer_whole = "(?P<winTenderer_center>贵公司.{,15}以.{,15}中标|最终由.{,15}竞买成功|经.{,15}决定[以由].{,15}公司中标|决定由.{5,20}承办|(谈判结果:|确定)由.{5,20}(向我单位)?供货|中标通知书.{,15}你方|单一来源从[()\w]{5,20}采购)"   # 2020//11/24 大网站规则 中标关键词添加 谈判结果:由.{5,20}供货
 
         # self.pattern_winTenderer_location = "(中标|中选|中价|乙|成交|承做|施工|供货|承包|竞得|受让)(候选)?(人|单位|机构|供应商|方|公司|厂商|商)|(供应商|供货商|服务商)[::]?$|(第[一1](名|((中标|中选|中价|成交)?(候选)?(人|单位|机构|供应商))))(是|为|:|:|\s*$)|((评审结果|名次|排名)[::]第?[一1]名?)|(单一来源(采购)?方式向.?$)"
 
@@ -1176,8 +1186,8 @@ class RoleRulePredictor():
 
         self.SET_NOT_TENDERER = set(["人民政府","人民法院","中华人民共和国","人民检察院","评标委员会","中国政府","中国海关","中华人民共和国政府"])
         
-        self.pattern_money_tenderee = re.compile("投标最高限价|采购计划金额|项目预算|招标金额|采购金额|项目金额|建安费用|采购(单位|人)委托价|限价|拦标价|预算金额")
-        self.pattern_money_tenderer = re.compile("((合同|成交|中标|应付款|交易|投标|验收|订单)[)\)]?(总?金额|结果|[单报]?价))|总价|标的基本情况")
+        self.pattern_money_tenderee = re.compile("投标最高限价|采购计划金额|项目预算|招标金额|采购金额|项目金额|建安费用|投资估算|采购(单位|人)委托价|限价|拦标价|预算金额|标底|总计|限额")
+        self.pattern_money_tenderer = re.compile("((合同|成交|中标|应付款|交易|投标|验收|订单)[)\)]?(总?金额|结果|[单报]?价))|总价|标的基本情况|承包价")
         self.pattern_money_tenderer_whole = re.compile("(以金额.*中标)|中标供应商.*单价|以.*元中标")
         self.pattern_money_other = re.compile("代理费|服务费")
         self.pattern_pack = "(([^承](包|标[段号的包]|分?包|包组)编?号?|项目)[::]?[\((]?[0-9A-Za-z一二三四五六七八九十]{1,4})[^至]?|(第?[0-9A-Za-z一二三四五六七八九十]{1,4}(包号|标[段号的包]|分?包))|[0-9]个(包|标[段号的包]|分?包|包组)"
@@ -1226,7 +1236,7 @@ class RoleRulePredictor():
                                     if _name != "" and str(_span[0][-10:]+_span[1] + _span[2][:len(str(_name))]).find(_name) >= 0:  #加上前面一些信息,修复公司不在项目名称开头的,检测不到
                                         find_flag = True
                                         if p_entity.values[0] > on_value:
-                                            p_entity.values[0] = 0.6 + (p_entity.values[0] - 0.6) / 10
+                                            p_entity.values[0] = 0.5 + (p_entity.values[0] - 0.5) / 10
                                         else:
                                             p_entity.values[0] = on_value  # 2022/03/08 修正类似 223985179 公司在文章开头的项目名称概率又没达到0.5的情况
                         if find_flag:
@@ -1352,8 +1362,10 @@ class RoleRulePredictor():
                         for _sentence in list_sentence:
                             if _sentence.sentence_index == p_entity.sentence_index:
                                 _span = spanWindow(tokens=_sentence.tokens, begin_index=p_entity.begin_index,
-                                                   end_index=p_entity.end_index, size=20, center_include=True,
+                                                   end_index=p_entity.end_index, size=10, center_include=True,
                                                    word_flag=True, text=p_entity.entity_text)
+                                if re.search(',\w{2,}', _span[0]):
+                                    _span[0] = _span[0].split(',')[-1]  #避免多个价格在一起造成误判
                                 if re.search(self.pattern_money_tenderee, _span[0]) is not None and re.search(
                                         self.pattern_money_other, _span[0]) is None:
                                     p_entity.values[0] = 0.8 + p_entity.values[0] / 10
@@ -1444,7 +1456,7 @@ class RoleRuleFinalAdd():
         sear_ent1 = re.search('((招标|采购)联系人)[,::][A-Za-z0-9_]*(?P<entity>[\u4e00-\u9fa5()()]{4,20})', list_articles[0].content[:5000])
         sear_ent2 = re.search('(户名|开户名称|单位名称|名称)[::](?P<entity>[\u4e00-\u9fa5()()]{5,20})[,。]', list_articles[0].content[:5000])
         sear_ent3 = re.search('(买家信息|所有权人|土地权属单位|报名咨询|[收送交]货地点|)[,:](?P<entity>[\u4e00-\u9fa5()()]{5,20})[0-9\-]*[,。]', list_articles[0].content[:5000])
-        sear_ent4 = re.search('(发布(?:人|单位|机构|企业)|项目业主|尊敬的供应商|所属公司|寻源单位)[,::][A-Za-z0-9_]*(?P<entity>[\u4e00-\u9fa5()()]{4,20})[,。]', list_articles[0].content[:5000])
+        sear_ent4 = re.search('(发布(?:人|单位|机构|企业)|项目业主|所属公司|寻源单位)[,::][A-Za-z0-9_]*(?P<entity>[\u4e00-\u9fa5()()]{4,20})[,。]', list_articles[0].content[:5000])
         sear_list = [sear_ent4 , sear_ent3 , sear_ent2 ,sear_ent1, sear_ent]
 
         tenderee_notfound = True
@@ -1697,6 +1709,108 @@ class TendereeRuleRecall():
                 list_entitys[0] = sorted(list_entitys[0], key=lambda x: (x.sentence_index, x.begin_index))
                 break
 
+class RoleGrade():
+    def __init__(self):
+        self.tenderee_left_9 = "(?P<tenderee_left_9>(招标|采购|遴选|寻源|竞价|议价|比选|委托|询比?价|比价|评选|谈判|邀标|邀请|洽谈|约谈|选取|抽取|抽选|甲)(人|方|单位))"
+        self.tenderee_center_9 = "(?P<tenderee_center_9>受.{5,20}委托)"
+        self.tenderee_left_8 = "(?P<tenderee_left_8>(业主|转让方|尊敬的供应商|出租方|处置方|(需求|建设|最终|发包)(人|方|单位|组织|用户|业主|主体|部门|公司)))"
+        self.agency_left_9 = "(?P<agency_left_9>代理)"
+        self.winTenderer_left_9 = "(?P<winTenderer_left_9>(中标|中选|中价|成交|竞得|乙方)|第[1一])"
+        self.winTenderer_left_8 = "(?P<winTenderer_left_8>(供应商|供货商|候选人))"
+        self.secondTenderer_left_9 = "(?P<secondTenderer_left_9>(第[二2](中标|中选|中价|成交)?候选(人|单位|供应商|公司)|第[二2]名))"
+        self.thirdTenderer_left_9 = "(?P<thirdTenderer_left_9>(第[三3](中标|中选|中价|成交)?候选(人|单位|供应商|公司)|第[三3]名))"
+        self.pattern_list = [self.tenderee_left_9,self.tenderee_center_9, self.tenderee_left_8,self.agency_left_9, self.winTenderer_left_9,
+                             self.winTenderer_left_8, self.secondTenderer_left_9, self.thirdTenderer_left_9]
+    def predict(self, list_sentences, list_entitys, span=10, min_prob=0.7):
+        '''
+        根据规则给角色分配不同等级概率;分三级:0.9-1,0.8-0.9,0.7-0.8;附件0.7-0.8,0.6-0.7,0.5-0.6
+        :param list_articles:
+        :param list_sentences:
+        :param list_entitys:
+        :param codeName:
+        :return:
+        '''
+        sentences = sorted(list_sentences[0], key=lambda x:x.sentence_index)
+        role2id = {"tenderee": 0, "agency": 1, "winTenderer": 2, "secondTenderer": 3, "thirdTenderer": 4}
+        for entity in list_entitys[0]:
+            if entity.entity_type in ['org', 'company'] and entity.label in [0, 1, 2, 3, 4] and entity.values[entity.label]> 0.6:
+                text = sentences[entity.sentence_index].sentence_text
+                in_att = sentences[entity.sentence_index].in_attachment
+                b = entity.wordOffset_begin
+                e = entity.wordOffset_end
+                not_found = 1
+                for pattern in self.pattern_list:
+                    if 'left' in pattern:
+                        context = text[max(0, b-span):b]
+                    elif 'right' in pattern:
+                        context = text[e:e+span]
+                    elif 'center' in pattern:
+                        context = text[max(0, b-span):e+span]
+                    else:
+                        print('规则错误', pattern)
+                    ser = re.search(pattern, context)
+                    if ser:
+                        groupdict = pattern.split('>')[0].replace('(?P<', '')
+                        _role, _direct, _prob = groupdict.split('_')
+                        _label = role2id.get(_role)
+                        if _label != entity.label:
+                            continue
+                        _prob = int(_prob)*0.1
+                        # print('规则修改角色概率前:', entity.entity_text, entity.label, entity.values)
+                        if in_att:
+                            _prob = _prob - 0.2
+                        entity.values[_label] = _prob + entity.values[_label] / 20
+                        not_found = 0
+                        # print('规则修改角色概率后:', entity.entity_text, entity.label, entity.values)
+                        break
+                if not_found and entity.values[entity.label]> min_prob:
+                    _prob = min_prob - 0.1 if in_att else min_prob
+                    entity.values[entity.label] = _prob + entity.values[entity.label] / 20
+                    # print('找不到规则修改角色概率:', entity.entity_text, entity.label, entity.values)
+
+
+class MoneyGrade():
+    def __init__(self):
+        self.tenderee_money_left_9 = "(?P<tenderee_left_9>最高(投标)?限价)|控制价|拦标价"
+        self.tenderee_money_left_8 = "(?P<tenderee_left_8>预算|限价|起始|起拍|底价|标底)"
+        self.tenderer_money_left_9 = "(?P<tenderer_left_9>(中标|成交|合同))"
+        self.tenderer_money_left_8 = "(?P<tenderer_left_8>(投标|总价))"
+
+        self.pattern_list = [self.tenderee_money_left_9, self.tenderee_money_left_8, self.tenderer_money_left_9]
+
+    def predict(self, list_sentences, list_entitys, span=10, min_prob=0.7):
+        sentences = sorted(list_sentences[0], key=lambda x:x.sentence_index)
+        role2id = {"tenderee": 0, "tenderer": 1}
+        for entity in list_entitys[0]:
+            if entity.entity_type in ['money'] and entity.label in [0, 1] and entity.values[entity.label]> 0.6:
+                text = sentences[entity.sentence_index].sentence_text
+                in_att = sentences[entity.sentence_index].in_attachment
+                b = entity.wordOffset_begin
+                e = entity.wordOffset_end
+                context = text[max(0, b - span):b]
+                not_found = 1
+                for pattern in self.pattern_list:
+                    ser = re.search(pattern, context)
+                    if ser:
+                        groupdict = pattern.split('>')[0].replace('(?P<', '')
+                        _role, _direct, _prob = groupdict.split('_')
+                        _label = role2id.get(_role)
+                        if _label != entity.label:
+                            continue
+                        _prob = int(_prob) * 0.1
+                        # print('规则修改金额概率前:', entity.entity_text, entity.label, entity.values)
+                        if in_att:
+                            _prob = _prob - 0.2
+                        entity.values[_label] = _prob + entity.values[_label] / 20
+                        not_found = 0
+                        # print('规则修改金额概率后:', entity.entity_text, entity.label, entity.values)
+                        break
+                if not_found and entity.values[entity.label] > min_prob:
+                    _prob = min_prob - 0.1 if in_att else min_prob
+                    entity.values[entity.label] = _prob + entity.values[entity.label] / 20
+                    # print('找不到规则修改金额概率:', entity.entity_text, entity.label, entity.values)
+
+
 # 时间类别
 class TimePredictor():
     def __init__(self,config=None):
@@ -2566,13 +2680,13 @@ class DocChannel():
           '公告变更': '第[\d一二]次变更|(更正|变更)(公告|公示|信息|内容|事项|原因|理由|日期|时间|如下)|原公告((主要)?(信息|内容)|发布时间)|(变更|更正)[前后]内容|现?在?(变更|更正|修改|更改)(内容)?为|(公告|如下|信息|内容|事项|结果|文件|发布|时间|日期)(更正|变更)',
           '候选人公示': '候选人公示|评标结果公示',
           '中标信息': '供地结果信息|采用单源直接采购的?情况说明|[特现]?将\w{,4}(成交|中标|中选|选定结果|选取结果|入围结果)\w{,4}(进行公示|公[示布]如下)|(中标|中选)(供应商|承包商|候选人|入围单位)如下|拟定供应商的情况|((中标|中选)(候选人|人|成交)|成交)\w{,3}(信息|情况)[::\s]',
-          '中标信息2': '\s(成交|中标|中选)(信息|日期|时间|总?金额|价格)[::\s]|(采购|招标|成交|中标|中选|评标)结果|单一来源采购原因|拟采取单一来源方式采购',
+          '中标信息2': '\s(成交|中标|中选)(信息|日期|时间|总?金额|价格)[::\s]|(采购|招标|成交|中标|中选|评标)结果|单一来源采购原因|拟采取单一来源方式采购|单一来源采购公示',
           '中标信息3': '(中标|中选|成交|拟定|拟选用|最终选定的?|受让|唯一)(供应商|供货商|服务商|机构|企业|公司|单位|候选人|人)(名称)?[::\s]|[、\s](第一名|(拟定|推荐|入围)?(供应商|供货商)|(中选|中标|供货)单位|中选人)[::\s]',
           '中标信息neg': '按项目控制价下浮\d%即为成交价|成交原则|不得确定为(中标|成交)|招标人按下列原则选择中标人|评选成交供应商:|拟邀请供应商|除单一来源采购项目外|单一来源除外|(各.{,5}|尊敬的)(供应商|供货商)[:\s]|竞拍起止时间:|询价结果[\s\n::]*不公开|本项目已具备招标条件|现对该项目进行招标公告|发布\w{2}结果后\d天内送达|本次\w{2}结果不对外公示',
       # |确定成交供应商[:,\s]
           '合同公告': '合同(公告|公示|信息|内容)|合同(编号|名称|主体|基本情况|签订日期)|(供应商乙方|乙方供应商):|合同总?金额',
-          '废标公告': '(终止|中止|废标|流标|失败|作废|异常|撤销)(结果)?(公告|公示|招标|采购|竞价)|(谈判结果为|结果类型):?废标|((本|该)项目|本标段|本次(招标)?)((采购|招标)?(失败|终止|流标|废标)|予以废标|(按|做|作)?(流标|废标)处理)|(采购|招标|询价|议价|竞价|比价|比选|遴选|邀请|邀标|磋商|洽谈|约谈|谈判|竞谈|应答|项目)(终止|中止|废标|流标|失败|作废|异常|撤销)',
-          '废标公告2': '(无效|中止|终止|废标|流标|失败|作废|异常|撤销)的?原因|本项目因故取消|本(项目|次)(公开)?\w{2}失败|已终止\s*原因:|(人数|供应商|单位)不足|已终止'
+          '废标公告': '(终止|中止|废标|流标|失败|作废|异常|撤销)(结果)?(公告|公示|招标|采购|竞价)|(谈判结果为|结果类型):?废标|((本|该)(项目|标段|合同|合同包|采购包|次)\w{,5})((失败|终止|流标|废标)|予以废标|(按|做|作)?(流标|废标)处理)|(采购|招标|询价|议价|竞价|比价|比选|遴选|邀请|邀标|磋商|洽谈|约谈|谈判|竞谈|应答|项目)(终止|中止|废标|流标|失败|作废|异常|撤销)',
+          '废标公告2': '(无效|中止|终止|废标|流标|失败|作废|异常|撤销)的?(原因|理由)|本项目因故取消|本(项目|次)(公开)?\w{2}失败|已终止\s*原因:|(人|人数|供应商|单位)(不足|未达\w{,3}数量)|已终止|不足[3三]家|无(废标)'
       }
       self.title_life_dic = {
           '采购意向': '采购意向|招标意向|选取意向|意向公告|意向公示|意向公开',
@@ -2843,9 +2957,9 @@ class DocChannel():
               else:
                   html = html[:ser.start() + 500]
           text = re.sub('<[^<]*?>', '', html).replace('&nbsp;', ' ')
-          text = re.sub('http[0-9a-zA-Z-.:/]+|[0-9a-zA-Z-./@]+', '', text)
+          # text = re.sub('http[0-9a-zA-Z-.:/]+|[0-9a-zA-Z-./@]+', '', text)
           text = re.sub('\s+', ' ', text)
-          text = re.sub('[/|[()()]', '', text)
+          # text = re.sub('[/|[()()]', '', text)
           text = cut_single_cn_space(text)
           return text[:20000]
 
@@ -2948,7 +3062,6 @@ class DocChannel():
                   life_list = [k]
               elif life_score[k] == max_score and life_score[k] > 0:
                   life_list.append(k)
-
           if '采购意向' in life_kw_title or '采购意向' in life_list:
               return '采购意向', msc
           elif '招标预告' in life_kw_title or '招标预告' in life_list:
@@ -2976,18 +3089,23 @@ class DocChannel():
           elif '候选人公示' in life_kw_title or '候选人公示' in life_list:
               if '招标公告' in life_kw_title and life_score.get('招标公告', 0) > 3:
                   return '招标公告', msc
+              elif '废标公告' in life_kw_title or life_score.get('废标公告', 0) > 5:
+                  return '废标公告', msc
               return '候选人公示', msc
           elif '合同公告' in life_kw_title or '合同公告' in life_list:
               if '招标公告' in life_kw_title and life_score.get('招标公告', 0) > 3:
                   return '招标公告', msc
+              elif '废标公告' in life_kw_title or life_score.get('废标公告', 0) > 5:
+                  return '废标公告', msc
               return '合同公告', msc
+
           elif '中标信息' in life_kw_title or '中标信息' in life_list:
               if '招标公告' in life_kw_title and life_score.get('招标公告',
                                                             0) > 2:  # (life_score.get('招标公告', 0)>2 or life_score.get('中标信息', 0)<4) 0.7886409793924245
                   return '招标公告', msc
-              elif '废标公告' in life_kw_title:
+              elif '废标公告' in life_kw_title or life_score.get('废标公告', 0) > 5:
                   return '废标公告', msc
-              elif life_score.get('候选人公示', 0) >= 3:
+              elif life_score.get('候选人公示', 0) > 3:
                   return '候选人公示', msc
               elif life_score.get('合同公告', 0) > 5:
                   return '合同公告', msc
@@ -3050,7 +3168,7 @@ class DocChannel():
           2、废标公告有中标人且标题无废标关键词,返回中标信息
           3、答疑公告标题无答疑关键且原始为招标,返回原始类别
           4、招标公告有中标人且原始为中标,返回中标信息
-          5、预测及原始均在招标、预告、意向,返回原始类别
+          5、预测为招标,原始为预告、意向,返回原始类别
           6、预测及原始均在变更、答疑,返回原始类别
           7、预测为采招数据,原始为产权且有关键词,返回原始类别
           8、废标公告原始为招标、预告且标题无废标关键期,返回原始类别
@@ -3073,8 +3191,8 @@ class DocChannel():
                   original_docchannel, '') == '中标信息':
               result['docchannel']['docchannel'] = '中标信息'
               msc += '最终规则修改:预测为招标公告却有中标人且原始为中标改为中标信息;'
-          elif result['docchannel']['docchannel'] in ['招标公告', '采购意向', '招标预告'] and origin_dic.get(
-                  original_docchannel, '') in ['招标公告', '采购意向', '招标预告']:
+          elif result['docchannel']['docchannel'] in ['招标公告'] and origin_dic.get(
+                  original_docchannel, '') in ['采购意向', '招标预告']:
               result['docchannel']['docchannel'] = origin_dic.get(original_docchannel, '')
               msc += '最终规则修改:预测及原始均在招标、预告、意向,返回原始类别'
           elif result['docchannel']['docchannel'] in ['招标答疑', '公告变更'] and origin_dic.get(
@@ -3774,6 +3892,120 @@ class IndustryPredictor():
                             }
                 }
 
+class DistrictPredictor():
+    def __init__(self):
+        with open(os.path.dirname(__file__)+'/district_dic.pkl', 'rb') as f:
+            dist_dic = pickle.load(f)
+            short_name = '|'.join(sorted(set([v['简称'] for v in dist_dic.values()]), key=lambda x: len(x), reverse=True))
+            full_name = '|'.join(sorted(set([v['全称'] for v in dist_dic.values()]), key=lambda x: len(x), reverse=True))
+            short2id = {}
+            full2id = {}
+            for k, v in dist_dic.items():
+                if v['简称'] not in short2id:
+                    short2id[v['简称']] = [k]
+                else:
+                    short2id[v['简称']].append(k)
+                if v['全称'] not in full2id:
+                    full2id[v['全称']] = [k]
+                else:
+                    full2id[v['全称']].append(k)
+            self.dist_dic = dist_dic
+            self.short_name = short_name
+            self.full_name = full_name
+            self.short2id = short2id
+            self.full2id = full2id
+
+    def predict(self, project_name, prem, web_source_name = ""):
+        def get_ree_addr(prem):
+            tenderee = ""
+            tenderee_address = ""
+            try:
+                for v in prem[0]['prem'].values():
+                    for link in v['roleList']:
+                        if link['role_name'] == 'tenderee' and tenderee == "":
+                            tenderee = link['role_text']
+                            tenderee_address = link['address']
+            except Exception as e:
+                print('解析prem 获取招标人、及地址出错')
+            return tenderee, tenderee_address
+        tenderee, tenderee_address = get_ree_addr(prem)
+        project_name = str(project_name).replace(str(tenderee), '')
+        text = "{} {} {}".format(project_name, tenderee, tenderee_address)
+        text = re.sub('复合肥|铁路|公路', ' ', text)
+        score_l = []
+        id_set = set()
+
+        if re.search(self.short_name, text):
+            for it in re.finditer(self.full_name, text):
+                name = it.group(0)
+                score = len(name) / len(text)
+                for _id in self.full2id[name]:
+                    area = self.dist_dic[_id]['area'] + [''] * (3 - len(self.dist_dic[_id]['area']))
+                    # score_l.append([_id, score] + area)
+                    w = self.dist_dic[_id]['权重']
+                    score_l.append([_id, score+w]+ area)
+
+            flag = 0
+            for it in re.finditer(self.short_name, text):
+                if it.end() < len(text) and re.search('^(村|镇|街|路|江|河|湖|北路|南路|东路|大道|社区)', text[it.end():]) == None:
+                    name = it.group(0)
+                    score = (it.start() + len(name)) / len(text)
+                    for _id in self.short2id[name]:
+                        score2 = 0
+                        w = self.dist_dic[_id]['权重']
+                        _type = self.dist_dic[_id]['类型']
+                        area = self.dist_dic[_id]['area'] + [''] * (3 - len(self.dist_dic[_id]['area']))
+                        if area[0] in ['2', '16', '20', '30']:
+                            _type += 10
+                        score2 += w
+                        if _id not in id_set:
+                            if _type == 20:
+                                type_w = 3
+                            elif _type == 30:
+                                type_w = 2
+                            else:
+                                type_w = 1
+                            id_set.add(_id)
+                            score2 += w * type_w
+                        score_l.append([_id, score * w + score2] + area)
+
+            if flag == 1:
+                pass
+            #         print('score', score)
+        if re.search('公司', web_source_name) == None:
+            for it in re.finditer(self.short_name, web_source_name):
+                name = it.group(0)
+                for _id in self.short2id[name]:
+                    area = self.dist_dic[_id]['area'] + [''] * (3 - len(self.dist_dic[_id]['area']))
+                    w = self.dist_dic[_id]['权重']
+                    score = w * 0.2
+                    score_l.append([_id, score] + area)
+        area_dic = {'area': '全国', 'province': '未知', 'city': '未知', 'district': '未知'}
+        if len(score_l) == 0:
+            return {'district':area_dic}
+        else:
+            df = pd.DataFrame(score_l, columns=['id', 'score', 'province', 'city', 'district'])
+            df_pro = df.groupby('province').sum().sort_values(by=['score'], ascending=False)
+            pro_id = df_pro.index[0]
+            # if df_pro.loc[pro_id, 'score'] < 0.1:  # 省级评分小于0.1的不要
+            #     print('评分低于0.1', df_pro.loc[pro_id, 'score'], self.dist_dic[pro_id]['地区'])
+            #     return area_dic
+            area_dic['province'] = self.dist_dic[pro_id]['地区']
+            area_dic['area'] = self.dist_dic[pro_id]['大区']
+            df = df[df['city'] != ""]
+            df = df[df['province'] == pro_id]
+            if len(df) > 0:
+                df_city = df.groupby('city').sum().sort_values(by=['score'], ascending=False)
+                city_id = df_city.index[0]
+                area_dic['city'] = self.dist_dic[city_id]['地区']
+                df = df[df['district'] != ""]
+                df = df[df['city'] == city_id]
+                if len(df) > 0:
+                    df_dist = df.groupby('district').sum().sort_values(by=['score'], ascending=False)
+                    dist_id = df_dist.index[0]
+                    area_dic['district'] = self.dist_dic[dist_id]['地区']
+            # print(area_dic)
+            return {'district':area_dic}
 
 
 def getSavedModel():