示例#1
0
文件: vocab.py 项目: zzsfornlp/zmsp
 def filter_vals(word_vals, word_filter=(lambda ww, rank, val: True)):
     ranked_list = Helper.rank_key(word_vals)
     truncated_vals = {}
     for ii, ww in enumerate(ranked_list):
         rank, val = ii+1, word_vals[ww]
         if word_filter(ww, rank, val):
             truncated_vals[ww] = val
     return truncated_vals
示例#2
0
文件: vocab.py 项目: zzsfornlp/zmsp
 def ranking_vals(word_vals, pre_list, post_list, default_val, sort_vals, word_filter=(lambda ww, rank, val: True)):
     if sort_vals:
         valid_word_list = Helper.rank_key(word_vals)
     else:
         valid_word_list = word_vals.keys()
     #
     truncated_vals = [default_val] * len(pre_list)
     v = dict(zip(pre_list, range(len(pre_list))))
     for ii, ww in enumerate(valid_word_list):
         rank, val = ii+1, word_vals[ww]
         if word_filter(ww, rank, val):
             v[ww] = len(v)
             truncated_vals.append(val)
     for one in post_list:
         v[one] = len(v)
         truncated_vals.append(default_val)
     return v, truncated_vals