GitHub上的源码:with open(path,'r',encoding='UTF-8') as f:
def add_dict(self, path):
words = []
with open(path,'r',encoding='UTF-8') as f:
for i, line in enumerate(f):
line = line.strip("\n").strip()
if not line:
continue
line = line.split()
word = line[0].strip()
self.trie.add_keyword(word)
if len(line) == 1:
weight = 1.0
else:
weight = float(line[1])
weight = float(weight)
self.weights[word] = weight
words.append(word)
self.sizes += len(self.weights)
python上安装的包里代码为: with open(path) as f:
def add_dict(self, path):
words = []
with open(path) as f:
for i, line in enumerate(f):
line = line.strip("\n").strip()
if not line:
continue
line = line.split()
word = line[0].strip()
self.trie.add_keyword(word)
if len(line) == 1:
weight = 1.0
else:
weight = float(line[1])
weight = float(weight)
self.weights[word] = weight
words.append(word)
self.sizes += len(self.weights)