示例#1
0
 def get(self, key):
     if not self.handled:
         self.handled = True
         tmp, self.d = good_turing.main(self.d)
         self.none = tmp
         self.total = sum(self.d.values())+0.0
     if not self.exists(key):
         return False, self.none
     return True, self.d[key]
示例#2
0
 def get(self, key):
     if not self.handled:
         self.handled = True
         tmp, self.d = good_turing.main(self.d)
         self.none = tmp
         self.total = sum(self.d.values()) + 0.0
     if not self.exists(key):
         return False, self.none
     return True, self.d[key]
示例#3
0
def init(filename='SogouLabDic.dic'):
    global d
    with open(filename, 'r') as handle:
        for line in handle:
            word, freq = line.split('\t')[0:2]
            try:
                d[word.decode('gbk')] = int(freq)+1
            except:
                d[word] = int(freq)+1
    tmp, d = good_turing.main(d)
    d['_none_'] = tmp