修复BUG

This commit is contained in:
zhiyang7 2022-02-11 09:04:52 +08:00
parent d0785ae9b9
commit 49bfc52caa
2 changed files with 9 additions and 2 deletions

View File

@ -220,9 +220,11 @@ def print_max_group(all_idiom, group, num):
print(item) print(item)
def get_max_group(all_idiom, group, num): def get_max_group(all_idiom, group, num):
result = list()
if(len(group) == 0):
return result
group['pinyin_c'] = group.apply(lambda x: (math.log(x['frequency'], 2)/16 + 1) * len(set(trim_space(x['pinyin_r']))), axis=1) group['pinyin_c'] = group.apply(lambda x: (math.log(x['frequency'], 2)/16 + 1) * len(set(trim_space(x['pinyin_r']))), axis=1)
ret_list = group.nlargest(num, ['pinyin_c', 'frequency']).index.tolist() ret_list = group.nlargest(num, ['pinyin_c', 'frequency']).index.tolist()
result = list()
for i in ret_list: for i in ret_list:
result.append(json.loads(all_idiom.loc[i].to_json(orient = 'index',force_ascii=False))) result.append(json.loads(all_idiom.loc[i].to_json(orient = 'index',force_ascii=False)))
return result return result

View File

@ -82,8 +82,13 @@
text = result.result.map(function(item){ text = result.result.map(function(item){
return item.word + '\t' + item.pinyin return item.word + '\t' + item.pinyin
}).join('\n') }).join('\n')
if(!text){
$('#result').val('无匹配结果')
}
else{
$('#result').val(text) $('#result').val(text)
} }
}
else { else {
$('#result').val(result) $('#result').val(result)
} }