|
@@ -232,7 +232,7 @@ def norm_community(asr):
|
|
|
text = "|".join([word[0] for word in pinyin(text, style=Style.NORMAL)])
|
|
|
if text in user_dict['pinyin']:
|
|
|
return user_dict['pinyin'][text]
|
|
|
- words = jieba.lcut(asr)
|
|
|
+ words = jieba.lcut(asr)[::-1]
|
|
|
for word in words:
|
|
|
if word in user_dict['zh']:
|
|
|
return user_dict['zh'].get(word)
|
|
@@ -245,9 +245,20 @@ def norm_community(asr):
|
|
|
result =[feature.result() for feature in as_completed(features)]
|
|
|
res = [i for i in filter(lambda x: x is not None, result)]
|
|
|
if len(res) >0:
|
|
|
+ if len(res)==1:
|
|
|
+ return res[0]
|
|
|
+ term_pinyin = ["|".join([term[0] for term in pinyin(ret, style=Style.NORMAL)]) for ret in res]
|
|
|
+ term_pinyin = dict([[val, index] for index, val in enumerate(term_pinyin)])
|
|
|
+ terms = ["|".join([term[0] for term in pinyin(ret, style=Style.NORMAL)]) for ret in words]
|
|
|
+ for term in terms:
|
|
|
+ if term in term_pinyin:
|
|
|
+ return res[term_pinyin[term]]
|
|
|
return res[0]
|
|
|
return asr
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- print(norm_community("五一村"))
|
|
|
+ asr="佳木斯长青乡四核村"
|
|
|
+ print(f"asr:{asr}")
|
|
|
+ loc = norm_community(asr)
|
|
|
+ print(f"命中小区:{loc}")
|