entityLink.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. #coding:UTF8
  2. '''
  3. Created on 2019年5月21日
  4. @author: User
  5. '''
  6. import re
  7. import os
  8. import time
  9. import pandas as pd
  10. _time = time.time()
  11. from BiddingKG.dl.common.Utils import *
  12. from BiddingKG.dl.interface.Entitys import *
  13. import json
  14. from BiddingKG.dl.common.constDict import ConstDict
  15. def edit_distance(source,target):
  16. dp = [["" for i in range(len(source)+1)] for j in range(len(target)+1)]
  17. for i in range(len(dp)):
  18. for j in range(len(dp[i])):
  19. if i==0:
  20. dp[i][j] = j
  21. elif j==0:
  22. dp[i][j] = i
  23. else:
  24. if source[j-1]==target[i-1]:
  25. cost = 0
  26. else:
  27. cost = 2
  28. dp[i][j] = min([dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+cost])
  29. return dp[-1][-1]
  30. def jaccard_score(source,target):
  31. source_set = set([s for s in source])
  32. target_set = set([s for s in target])
  33. if len(source_set)==0 or len(target_set)==0:
  34. return 0
  35. return max(len(source_set&target_set)/len(source_set),len(source_set&target_set)/len(target_set))
  36. def get_place_list():
  37. path = os.path.dirname(__file__) + '/../place_info.csv'
  38. place_df = pd.read_csv(path)
  39. place_list = []
  40. for index, row in place_df.iterrows():
  41. place_list.append(row[1])
  42. place_list.append('台湾')
  43. place_list.append('澳门')
  44. place_list.append('香港')
  45. # place_list.append('東莞')
  46. # place_list.append('廣州')
  47. # place_list.append('韩国')
  48. # place_list.append('德国')
  49. # place_list.append('英国')
  50. # place_list.append('日本')
  51. # place_list.append('意大利')
  52. # place_list.append('新加坡')
  53. # place_list.append('加拿大')
  54. # place_list.append('西班牙')
  55. # place_list.append('澳大利亚')
  56. # place_list.append('美国')
  57. place_list = list(set(place_list))
  58. return place_list
  59. place_list = get_place_list()
  60. place_pattern = "|".join(place_list)
  61. def link_entitys(list_entitys,on_value=1):#on_value=0.81
  62. for list_entity in list_entitys:
  63. range_entity = []
  64. for _entity in list_entity:
  65. if _entity.entity_type in ["org","company"]:
  66. range_entity.append(_entity)
  67. range_entity = range_entity[:1000]
  68. #替换公司的逻辑有问题,先取消
  69. # for first_i in range(len(range_entity)):
  70. # _entity = range_entity[first_i]
  71. # for second_i in range(first_i+1,len(range_entity)):
  72. # _ent = range_entity[second_i]
  73. # # 2021/5/21 update: 两个实体标签互斥(一个是招标人、一个是代理人)且entity_text不相等时,跳过
  74. # if _entity.entity_text != _ent.entity_text and _entity.label != _ent.label and _entity.label in [0,1] and _ent.label in [0, 1]:
  75. # continue
  76. # _score = jaccard_score(re.sub("%s|%s"%("股份|责任|有限|公司",place_pattern),"",_entity.entity_text), re.sub("%s|%s"%("股份|责任|有限|公司",place_pattern),"",_ent.entity_text))
  77. # if _entity.entity_text!=_ent.entity_text and _score>=on_value:
  78. # _entity.linked_entitys.append(_ent)
  79. # _ent.linked_entitys.append(_entity)
  80. # print("=-===",_entity.entity_text,_ent.entity_text,_score)
  81. #替换公司名称
  82. for _entity in range_entity:
  83. if re.search("公司",_entity.entity_text) is None:
  84. for _ent in _entity.linked_entitys:
  85. if re.search("公司$",_ent.entity_text) is not None:
  86. if len(_ent.entity_text)>len(_entity.entity_text):
  87. _entity.entity_text = _ent.entity_text
  88. # 2021/12/21 替换通过字典识别到的取长度最大的相似实体
  89. for _entity in range_entity:
  90. used_linked_entitys = []
  91. if not _entity.linked_entitys:
  92. continue
  93. _entity.linked_entitys.sort(key=lambda x: len(x.entity_text), reverse=True)
  94. for _ent in _entity.linked_entitys:
  95. if _ent in used_linked_entitys:
  96. break
  97. # print("_entity, _ent", _entity.entity_text, _ent.if_dict_match, _ent.entity_text)
  98. if _ent.if_dict_match == 1:
  99. if len(_ent.entity_text) > len(_entity.entity_text):
  100. # 判断两个公司地区相同
  101. match_list_1, match_list_2 = [], []
  102. for place in place_list:
  103. if place in _entity.entity_text:
  104. match_list_1.append(place)
  105. if place in _ent.entity_text:
  106. match_list_2.append(place)
  107. if str(match_list_1) == str(match_list_2):
  108. # print("字典替换", _entity.entity_text, "->", _ent.entity_text)
  109. _entity.origin_entity_text = _entity.entity_text
  110. _entity.entity_text = _ent.entity_text
  111. used_linked_entitys.append(_ent)
  112. # print(_entity.entity_text, _entity.if_dict_match, _ent.entity_text, _ent.if_dict_match)
  113. # 用于去重的标题
  114. def doctitle_refine(doctitle):
  115. _doctitle_refine = re.sub(r'工程|服务|询价|比价|谈判|竞争性|磋商|结果|中标|招标|采购|的|公示|公开|成交|公告|评标|候选人|'
  116. r'交易|通知|废标|流标|终止|中止|一笔|预告|单一来源|竞价|合同', '', doctitle)
  117. return _doctitle_refine
  118. # 前100个公司实体
  119. def get_nlp_enterprise(list_entity):
  120. nlp_enterprise = []
  121. nlp_enterprise_attachment = []
  122. max_num = 100
  123. list_entity = sorted(list_entity,key=lambda x:(x.sentence_index,x.begin_index))
  124. for entity in list_entity:
  125. if entity.entity_type in ['org','company']:
  126. if not entity.in_attachment:
  127. if entity.entity_text not in nlp_enterprise:
  128. nlp_enterprise.append(entity.entity_text)
  129. else:
  130. if entity.entity_text not in nlp_enterprise_attachment:
  131. nlp_enterprise_attachment.append(entity.entity_text)
  132. return nlp_enterprise[:max_num],nlp_enterprise_attachment[:max_num]
  133. ENTERPRISE_HUGE = None
  134. def getEnterprisePath():
  135. global ENTERPRISE_HUGE
  136. filename_huge = "LEGAL_ENTERPRISE_HUGE.txt"
  137. huge_path = getFileFromSysPath(filename_huge)
  138. if huge_path is None:
  139. if os.path.exists(filename_huge):
  140. log("enterprise path:%s"%(filename_huge))
  141. ENTERPRISE_HUGE = True
  142. return filename_huge,ENTERPRISE_HUGE
  143. else:
  144. log("enterprise path:%s"%(huge_path))
  145. ENTERPRISE_HUGE = True
  146. return huge_path,ENTERPRISE_HUGE
  147. filename = "LEGAL_ENTERPRISE.txt"
  148. real_path = getFileFromSysPath(filename)
  149. if real_path is None:
  150. real_path = filename
  151. log("ENTERPRISE path:%s"%(real_path))
  152. ENTERPRISE_HUGE = False
  153. return real_path,ENTERPRISE_HUGE
  154. DICT_ENTERPRISE_DONE = False
  155. POOL_REDIS = None
  156. ENTERPRISE_KEY_LEN = 3
  157. ENTERPRISE_PREFIX_LEN = 3
  158. ENTERPRISE_TAIL_LEN = 3
  159. SET_ENTERPRISE = set()
  160. SET_PREFIX_ENTERPRISE = set()
  161. SET_TAIL_ENTERPRISE = set()
  162. SET_PREFIX_ENTERPRISE_HUGE_FILE = "SET_PREFIX_ENTERPRISE_HUGE.pk"
  163. SET_TAIL_ENTERPRISE_HUGE_FILE = "SET_TAIL_ENTERPRISE_HUGE.pk"
  164. def getDict_enterprise():
  165. global DICT_ENTERPRISE_DONE,SET_ENTERPRISE,SET_PREFIX_ENTERPRISE,SET_TAIL_ENTERPRISE
  166. real_path,is_huge = getEnterprisePath()
  167. if is_huge:
  168. if os.path.exists(SET_PREFIX_ENTERPRISE_HUGE_FILE) and os.path.exists(SET_TAIL_ENTERPRISE_HUGE_FILE):
  169. SET_PREFIX_ENTERPRISE = load(SET_PREFIX_ENTERPRISE_HUGE_FILE)
  170. SET_TAIL_ENTERPRISE = load(SET_TAIL_ENTERPRISE_HUGE_FILE)
  171. else:
  172. with open(real_path,"r",encoding="UTF8") as f:
  173. for _e in f:
  174. if not _e:
  175. continue
  176. _e = _e.strip()
  177. if len(_e)>=4:
  178. key_enter = _e[:ENTERPRISE_KEY_LEN]
  179. SET_PREFIX_ENTERPRISE.add(key_enter)
  180. SET_TAIL_ENTERPRISE.add(_e[-ENTERPRISE_TAIL_LEN:])
  181. if not is_huge:
  182. SET_ENTERPRISE.add(_e)
  183. #仅在大文件情况下才使用缓存加载
  184. if is_huge:
  185. save(SET_PREFIX_ENTERPRISE,SET_PREFIX_ENTERPRISE_HUGE_FILE)
  186. save(SET_TAIL_ENTERPRISE,SET_TAIL_ENTERPRISE_HUGE_FILE)
  187. log("SET_PREFIX_ENTERPRISE takes memory:%.2fM size:%d"%(sys.getsizeof(SET_PREFIX_ENTERPRISE)/1024/1024,len(SET_PREFIX_ENTERPRISE)))
  188. log("SET_TAIL_ENTERPRISE takes memory:%.2fM size:%d"%(sys.getsizeof(SET_TAIL_ENTERPRISE)/1024/1024,len(SET_TAIL_ENTERPRISE)))
  189. log("SET_ENTERPRISE takes memory:%.2fM size:%d"%(sys.getsizeof(SET_ENTERPRISE)/1024/1024,len(SET_ENTERPRISE)))
  190. # for _e in ["河南省柘源","建筑工程有限公司"]:
  191. # if not _e:
  192. # continue
  193. # _e = _e.strip()
  194. # if len(_e)>=4:
  195. # key_enter = _e[:4]
  196. # if key_enter not in DICT_ENTERPRISE:
  197. # DICT_ENTERPRISE[key_enter] = set()
  198. # DICT_ENTERPRISE[key_enter].add(_e[4:])
  199. DICT_ENTERPRISE_DONE = True
  200. def init_redis_pool():
  201. from BiddingKG.dl.common.pool import ConnectorPool
  202. from BiddingKG.dl.common.source import getConnect_redis_baseline
  203. global POOL_REDIS
  204. if POOL_REDIS is None:
  205. POOL_REDIS = ConnectorPool(init_num=1,max_num=10,method_init=getConnect_redis_baseline)
  206. def is_enterprise_exist(enterprise_name):
  207. global ENTERPRISE_HUGE,SET_ENTERPRISE,POOL_REDIS
  208. if ENTERPRISE_HUGE:
  209. if POOL_REDIS is None:
  210. init_redis_pool()
  211. _db = POOL_REDIS.getConnector()
  212. try:
  213. _time = time.time()
  214. _v = _db.get(enterprise_name)
  215. POOL_REDIS.putConnector(_db)
  216. if _v is None:
  217. return False
  218. else:
  219. log("redis take %.5f of '%s' exists"%(time.time()-_time,enterprise_name))
  220. return True
  221. except Exception as e:
  222. traceback.print_exc()
  223. return False
  224. else:
  225. if enterprise_name in SET_ENTERPRISE:
  226. return True
  227. else:
  228. return False
  229. import threading
  230. import time
  231. load_enterprise_thread = threading.Thread(target=getDict_enterprise)
  232. load_enterprise_thread.start()
  233. MAX_ENTERPRISE_LEN = 30
  234. def match_enterprise_max_first(sentence):
  235. while True:
  236. if not DICT_ENTERPRISE_DONE:
  237. time.sleep(1)
  238. else:
  239. break
  240. list_match = []
  241. begin_index = 0
  242. if len(sentence)>4:
  243. while True:
  244. if begin_index+ENTERPRISE_KEY_LEN<len(sentence):
  245. key_enter = sentence[begin_index:begin_index+ENTERPRISE_KEY_LEN]
  246. # if key_enter in DICT_ENTERPRISE:
  247. # _len = min(MAX_ENTERPRISE_LEN-ENTERPRISE_KEY_LEN+1,len(sentence)-begin_index)
  248. # for _i in range(_len):
  249. # enter_name = sentence[begin_index+ENTERPRISE_KEY_LEN:begin_index+_len-_i]
  250. # if enter_name in DICT_ENTERPRISE[key_enter]:
  251. # match_item = {"entity_text":"%s%s"%(key_enter,enter_name),"begin_index":begin_index,"end_index":begin_index+len(key_enter)+len(enter_name)}
  252. # list_match.append(match_item)
  253. # begin_index += (len(key_enter)+len(enter_name))-1
  254. # break
  255. if key_enter in SET_PREFIX_ENTERPRISE:
  256. _len = min(MAX_ENTERPRISE_LEN-ENTERPRISE_KEY_LEN+1,len(sentence)-begin_index)
  257. for _i in range(_len):
  258. enter_name = sentence[begin_index:begin_index+_len-_i]
  259. enter_tail = enter_name[-ENTERPRISE_TAIL_LEN:]
  260. if enter_tail in SET_TAIL_ENTERPRISE:
  261. if is_enterprise_exist(enter_name):
  262. match_item = {"entity_text":"%s"%(enter_name),"begin_index":begin_index,"end_index":begin_index+len(enter_name)}
  263. # print("match_item",key_enter,enter_name)
  264. list_match.append(match_item)
  265. begin_index += (len(key_enter)+len(enter_name))-1
  266. break
  267. begin_index += 1
  268. else:
  269. break
  270. # print("======",list_match)
  271. return list_match
  272. def calibrateEnterprise(list_articles,list_sentences,list_entitys):
  273. for _article,list_sentence,list_entity in zip(list_articles,list_sentences,list_entitys):
  274. list_calibrate = []
  275. match_add = False
  276. match_replace = False
  277. range_entity = []
  278. for p_entity in list_entity:
  279. if p_entity.entity_type in ("org","company","location"):
  280. range_entity.append(p_entity)
  281. if len(range_entity)>1000:
  282. break
  283. for p_sentence in list_sentence:
  284. sentence = p_sentence.sentence_text
  285. sentence_entitys = [(ent.entity_text,ent.wordOffset_begin,ent.wordOffset_end) for ent in list_entity if ent.sentence_index==p_sentence.sentence_index and ent.entity_type in ['org','company']]
  286. list_match = match_enterprise_max_first(sentence)
  287. # print("list_match", list_match)
  288. doc_id = p_sentence.doc_id
  289. sentence_index = p_sentence.sentence_index
  290. tokens = p_sentence.tokens
  291. list_match.sort(key=lambda x:x["begin_index"])
  292. for _match_index in range(len(list_match)):
  293. _match = list_match[_match_index]
  294. find_flag = False
  295. for p_entity in range_entity:
  296. if p_entity.sentence_index!=p_sentence.sentence_index:
  297. continue
  298. if p_entity.entity_type=="location" and p_entity.entity_text==_match["entity_text"]:
  299. find_flag = True
  300. p_entity.entity_type = "company"
  301. p_entity.if_dict_match = 1
  302. if p_entity.entity_type not in ["location","org","company"]:
  303. continue
  304. if _match["entity_text"] == p_entity.entity_text:
  305. p_entity.if_dict_match = 1
  306. #有重叠
  307. #match部分被包含则不处理
  308. if _match["begin_index"]>=p_entity.wordOffset_begin and _match["end_index"]<=p_entity.wordOffset_end:
  309. find_flag = True
  310. #判断是否是多个公司
  311. for _match_j in range(_match_index,len(list_match)):
  312. if not list_match[_match_j]["end_index"]<=p_entity.wordOffset_end:
  313. _match_j -= 1
  314. break
  315. if _match_j>_match_index:
  316. match_replace = True
  317. match_add = True
  318. begin_index = changeIndexFromWordToWords(tokens,_match["begin_index"])
  319. end_index = changeIndexFromWordToWords(tokens,_match["end_index"]-1)
  320. list_calibrate.append({"type":"update","from":p_entity.entity_text,"to":_match["entity_text"]})
  321. p_entity.entity_text = _match["entity_text"]
  322. p_entity.wordOffset_begin = _match["begin_index"]
  323. p_entity.wordOffset_end = _match["end_index"]
  324. p_entity.begin_index = begin_index
  325. p_entity.end_index = end_index
  326. # 该公司实体是字典识别的
  327. p_entity.if_dict_match = 1
  328. for _match_h in range(_match_index+1,_match_j+1):
  329. entity_text = list_match[_match_h]["entity_text"]
  330. entity_type = "company"
  331. begin_index = changeIndexFromWordToWords(tokens,list_match[_match_h]["begin_index"])
  332. end_index = changeIndexFromWordToWords(tokens,list_match[_match_h]["end_index"]-1)
  333. entity_id = "%s_%d_%d_%d"%(doc_id,sentence_index,begin_index,end_index)
  334. add_entity = Entity(p_sentence.doc_id,entity_id,entity_text,entity_type,sentence_index,begin_index,end_index,list_match[_match_h]["begin_index"],list_match[_match_h]["end_index"],in_attachment=p_sentence.in_attachment)
  335. add_entity.if_dict_match = 1
  336. list_entity.append(add_entity)
  337. range_entity.append(add_entity)
  338. list_calibrate.append({"type":"add","from":"","to":entity_text})
  339. _match_index = _match_j
  340. break
  341. continue
  342. elif _match["begin_index"]<=p_entity.wordOffset_begin and _match["end_index"]>p_entity.wordOffset_begin:
  343. find_flag = True
  344. if _match["begin_index"]<p_entity.wordOffset_begin and _match["end_index"]<=p_entity.wordOffset_end:
  345. if p_entity.entity_type in ("org","company"):
  346. _diff_text = sentence[p_entity.wordOffset_end:_match["end_index"]]
  347. if re.search("分",_diff_text) is not None:
  348. pass
  349. else:
  350. match_replace = True
  351. begin_index = changeIndexFromWordToWords(tokens,_match["begin_index"])
  352. end_index = changeIndexFromWordToWords(tokens,_match["end_index"]-1)
  353. list_calibrate.append({"type":"update","from":p_entity.entity_text,"to":_match["entity_text"]})
  354. p_entity.entity_text = _match["entity_text"]
  355. p_entity.wordOffset_begin = _match["begin_index"]
  356. p_entity.wordOffset_end = _match["end_index"]
  357. p_entity.begin_index = begin_index
  358. p_entity.end_index = end_index
  359. p_entity.if_dict_match = 1
  360. elif _match["end_index"]>=p_entity.wordOffset_end:
  361. # 原entity列表已有实体,则不重复添加
  362. if (_match["entity_text"],_match["begin_index"],_match["end_index"]) not in sentence_entitys:
  363. match_replace = True
  364. begin_index = changeIndexFromWordToWords(tokens,_match["begin_index"])
  365. end_index = changeIndexFromWordToWords(tokens,_match["end_index"]-1)
  366. list_calibrate.append({"type":"update","from":p_entity.entity_text,"to":_match["entity_text"]})
  367. p_entity.entity_text = _match["entity_text"]
  368. p_entity.wordOffset_begin = _match["begin_index"]
  369. p_entity.wordOffset_end = _match["end_index"]
  370. p_entity.begin_index = begin_index
  371. p_entity.end_index = end_index
  372. p_entity.entity_type = "company"
  373. p_entity.if_dict_match = 1
  374. elif _match["begin_index"]<p_entity.wordOffset_end and _match["end_index"]>p_entity.wordOffset_end:
  375. find_flag = True
  376. if p_entity.entity_type in ("org","company"):
  377. match_replace = True
  378. begin_index = changeIndexFromWordToWords(tokens,_match["begin_index"])
  379. end_index = changeIndexFromWordToWords(tokens,_match["end_index"]-1)
  380. list_calibrate.append({"type":"update","from":p_entity.entity_text,"to":_match["entity_text"]})
  381. p_entity.entity_text = _match["entity_text"]
  382. p_entity.wordOffset_begin = _match["begin_index"]
  383. p_entity.wordOffset_end = _match["end_index"]
  384. p_entity.begin_index = begin_index
  385. p_entity.end_index = end_index
  386. p_entity.if_dict_match = 1
  387. if not find_flag:
  388. match_add = True
  389. entity_text = _match["entity_text"]
  390. entity_type = "company"
  391. begin_index = changeIndexFromWordToWords(tokens,_match["begin_index"])
  392. end_index = changeIndexFromWordToWords(tokens,_match["end_index"]-1)
  393. entity_id = "%s_%d_%d_%d"%(doc_id,sentence_index,begin_index,end_index)
  394. add_entity = Entity(p_sentence.doc_id,entity_id,entity_text,entity_type,sentence_index,begin_index,end_index,_match["begin_index"],_match["end_index"],in_attachment=p_sentence.in_attachment)
  395. list_entity.append(add_entity)
  396. range_entity.append(add_entity)
  397. list_calibrate.append({"type":"add","from":"","to":entity_text})
  398. #去重
  399. set_calibrate = set()
  400. list_match_enterprise = []
  401. for _calibrate in list_calibrate:
  402. _from = _calibrate.get("from","")
  403. _to = _calibrate.get("to","")
  404. _key = _from+_to
  405. if _key not in set_calibrate:
  406. list_match_enterprise.append(_calibrate)
  407. set_calibrate.add(_key)
  408. match_enterprise_type = 0
  409. if match_add:
  410. match_enterprise_type += 1
  411. if match_replace:
  412. match_enterprise_type += 2
  413. _article.match_enterprise = list_match_enterprise
  414. _article.match_enterprise_type = match_enterprise_type
  415. def isLegalEnterprise(name):
  416. is_legal = True
  417. if re.search("^[省市区县]",name) is not None or re.search("^\**.{,3}(分(公司|行|支)|街道|中心|办事处|经营部|委员会|有限公司)$",name) or re.search("标段|标包|名称|联系人|联系方式|中标单位|中标人|测试单位|采购单位|采购人|代理人|代理机构|盖章|(主)",name) is not None:
  418. is_legal = False
  419. return is_legal
  420. def fix_LEGAL_ENTERPRISE():
  421. unlegal_enterprise = []
  422. _path = getEnterprisePath()
  423. _sum = 0
  424. set_enter = set()
  425. paths = [_path]
  426. for _p in paths:
  427. with open(_p,"r",encoding="utf8") as f:
  428. while True:
  429. line = f.readline()
  430. if not line:
  431. break
  432. line = line.strip()
  433. if isLegalEnterprise(line):
  434. set_enter.add(line)
  435. if line=="有限责任公司" or line=='设计研究院' or line=='限责任公司' or (re.search("^.{,4}(分公司|支行|分行)$",line) is not None and re.search("电信|移动|联通|建行|工行|农行|中行|交行",line) is None):
  436. print(line)
  437. if line in set_enter:
  438. set_enter.remove(line)
  439. with open("enter.txt","w",encoding="utf8") as fwrite:
  440. for line in list(set_enter):
  441. fwrite.write(line.replace("(","(").replace(")",")"))
  442. fwrite.write("\n")
  443. # if re.search("标段|地址|标包|名称",line) is not None:#\(|\)||
  444. # _count += 1
  445. # print("=",line)
  446. # print("%d/%d"%(_count,_sum))
  447. # a_list = []
  448. # with open("电信分公司.txt","r",encoding="utf8") as f:
  449. # while True:
  450. # _line = f.readline()
  451. # if not _line:
  452. # break
  453. # if _line.strip()!="":
  454. # a_list.append(_line.strip())
  455. # with open("enter.txt","a",encoding="utf8") as f:
  456. # for _line in a_list:
  457. # f.write(_line)
  458. # f.write("\n")
  459. if __name__=="__main__":
  460. # edit_distance("GUMBO","GAMBOL")
  461. # print(jaccard_score("周口经济开发区陈营运粮河两岸拆迁工地土工布覆盖项目竞争性谈判公告","周口经济开发区陈营运粮河两岸拆迁工地土工布覆盖项目-成交公告"))
  462. #
  463. # sentences = "广州比地数据科技有限公司比地数据科技有限公司1111111123沈阳南光工贸有限公司"
  464. # print(match_enterprise_max_first(sentences))
  465. #
  466. # print("takes %d s"%(time.time()-_time))
  467. # fix_LEGAL_ENTERPRISE()
  468. print(jaccard_score("吉林省九台","吉林省建苑设计集团有限公司"))
  469. # print(match_enterprise_max_first("中国南方航空股份有限公司黑龙江分公司"))