Commit 2007a2e9 authored by 段英荣's avatar 段英荣

modify

parent 352a4ba9
...@@ -21,22 +21,22 @@ def uuid4(): ...@@ -21,22 +21,22 @@ def uuid4():
def get_tips_suggest_list(instance_cn_name): def get_tips_suggest_list(instance_cn_name):
try: try:
ch_full_weight = 6.0 * 10000 ch_full_weight = 6.0 * 1000
py_full_weight = 3.0 * 10000 py_full_weight = 3.0 * 1000
py_acronym_full_weight = 3.0 * 10000 py_acronym_full_weight = 3.0 * 1000
py_acronym_prefix_weight = 2 py_acronym_prefix_weight = 2
ch_prefix_weight = 1.5 ch_prefix_weight = 1.5
py_prefix_weight = 1.0 py_prefix_weight = 1.0
# 命中开始部分加权 # 命中开始部分加权
begin_prefix_weight = 1.2 * 10000 begin_prefix_weight = 1.2 * 1000
ch_full_word = instance_cn_name.strip() ch_full_word = instance_cn_name.strip()
py_full_word = ''.join(lazy_pinyin(ch_full_word)) py_full_word = ''.join(lazy_pinyin(ch_full_word))
py_acronym_full_word = ''.join(lazy_pinyin(ch_full_word, style=pypinyin.FIRST_LETTER)) py_acronym_full_word = ''.join(lazy_pinyin(ch_full_word, style=pypinyin.FIRST_LETTER))
suggest_list = list() suggest_dict = dict()
cur_index = 0 cur_index = 0
# 中文 # 中文
for i in range(len(ch_full_word)): for i in range(len(ch_full_word)):
...@@ -50,10 +50,16 @@ def get_tips_suggest_list(instance_cn_name): ...@@ -50,10 +50,16 @@ def get_tips_suggest_list(instance_cn_name):
"input": [ch_name_term], "input": [ch_name_term],
"word_weight": (1.0 * len(ch_name_term) / len((ch_full_word))) * prefix_weight, "word_weight": (1.0 * len(ch_name_term) / len((ch_full_word))) * prefix_weight,
"suggest_type": suggest_type, "suggest_type": suggest_type,
"cur_index": cur_index
} }
if ch_name_term[0] not in suggest_dict:
cur_index += 1 cur_index += 1
suggest_list.append(suggest_item) suggest_item["cur_index"] = cur_index
suggest_dict[ch_name_term[0]] = suggest_item
else:
suggest_dict[ch_name_term[0]]["input"].append(ch_name_term)
if suggest_item["word_weight"] > suggest_dict[ch_name_term[0]]["word_weight"]:
suggest_dict[ch_name_term[0]]["word_weight"] = suggest_item["word_weight"]
suggest_dict[ch_name_term[0]]["suggest_type"] = suggest_item["suggest_type"]
# 拼音 # 拼音
for i in range(len(py_full_word)): for i in range(len(py_full_word)):
...@@ -67,11 +73,17 @@ def get_tips_suggest_list(instance_cn_name): ...@@ -67,11 +73,17 @@ def get_tips_suggest_list(instance_cn_name):
suggest_item = { suggest_item = {
"input": [py_name_term], "input": [py_name_term],
"word_weight": (1.0 * len(py_name_term) / len(py_full_word)) * prefix_weight, "word_weight": (1.0 * len(py_name_term) / len(py_full_word)) * prefix_weight,
"suggest_type": suggest_type, "suggest_type": suggest_type
"cur_index": cur_index
} }
if py_name_term[0] not in suggest_dict:
cur_index += 1 cur_index += 1
suggest_list.append(suggest_item) suggest_item["cur_index"] = cur_index
suggest_dict[py_name_term[0]] = suggest_item
else:
suggest_dict[py_name_term[0]]["input"].append(py_name_term)
if suggest_item["word_weight"] > suggest_dict[py_name_term[0]]["word_weight"]:
suggest_dict[py_name_term[0]]["word_weight"] = suggest_item["word_weight"]
suggest_dict[py_name_term[0]]["suggest_type"] = suggest_item["suggest_type"]
# 简写 # 简写
for i in range(len(py_acronym_full_word)): for i in range(len(py_acronym_full_word)):
...@@ -89,10 +101,17 @@ def get_tips_suggest_list(instance_cn_name): ...@@ -89,10 +101,17 @@ def get_tips_suggest_list(instance_cn_name):
"suggest_type": suggest_type, "suggest_type": suggest_type,
"cur_index": cur_index "cur_index": cur_index
} }
if py_acronym_term[0] not in suggest_dict:
cur_index += 1 cur_index += 1
suggest_list.append(suggest_item) suggest_item["cur_index"] = cur_index
suggest_dict[py_acronym_term[0]] = suggest_item
else:
suggest_dict[py_acronym_term[0]]["input"].append(py_acronym_term)
if suggest_item["word_weight"] > suggest_dict[py_acronym_term[0]]["word_weight"]:
suggest_dict[py_acronym_term[0]]["word_weight"] = suggest_item["word_weight"]
suggest_dict[py_acronym_term[0]]["suggest_type"] = suggest_item["suggest_type"]
return suggest_list return suggest_dict.values()
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return list() return list()
......
...@@ -133,6 +133,7 @@ class TypeInfo(object): ...@@ -133,6 +133,7 @@ class TypeInfo(object):
continue continue
data = self.get_data_func(instance) data = self.get_data_func(instance)
(item_dict, suggest_list) = data (item_dict, suggest_list) = data
for suggest_item in suggest_list: for suggest_item in suggest_list:
suggest_dict = copy.deepcopy(item_dict) suggest_dict = copy.deepcopy(item_dict)
suggest_dict["suggest_type"] = suggest_item["suggest_type"] suggest_dict["suggest_type"] = suggest_item["suggest_type"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment