def score(self,tokens):
total = 0.0
#score for unigrams
for token in tokens:
total += self.d_unigrams.get(token,0.0)
#score for bigrams, if bigrams exist
if len(self.d_bigrams)>0 :
#list with bigrams of the message
bigrams_list = Counter(list(bigrams(tokens))).keys()
for bigram in bigrams_list :
total += self.d_bigrams.get(bigram,0.0)
return total
#compute the number of tokens(words) that appear in the lexicon
评论列表
文章目录