本文整理汇总了Python中tokenizer.Tokenizer.unique_tokenizer方法的典型用法代码示例。如果您正苦于以下问题:Python Tokenizer.unique_tokenizer方法的具体用法?Python Tokenizer.unique_tokenizer怎么用?Python Tokenizer.unique_tokenizer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tokenizer.Tokenizer
的用法示例。
在下文中一共展示了Tokenizer.unique_tokenizer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train
# 需要导入模块: from tokenizer import Tokenizer [as 别名]
# 或者: from tokenizer.Tokenizer import unique_tokenizer [as 别名]
def train(self):
for category, file in self.to_train:
email = EmailObject(io.open(file, 'rb'))
self.categories.add(category)
for token in Tokenizer.unique_tokenizer(email.body()):
self.training[category][token] += 1
self.totals['_all'] += 1
self.totals[category] += 1
self.to_train = {}
示例2: score
# 需要导入模块: from tokenizer import Tokenizer [as 别名]
# 或者: from tokenizer.Tokenizer import unique_tokenizer [as 别名]
def score(self, email):
self.train()
cat_totals = self.totals
aggregates = {cat: cat_totals[cat]/cat_totals['_all'] for cat in self.categories}
for token in Tokenizer.unique_tokenizer(email.body()):
for cat in self.categories:
value = self.training[cat][token]
r = (value+1)/(cat_totals[cat]+1)
aggregates[cat] *= r
return aggregates