资源简介
ngramScore适应度计算文件(包含引入的计算代码和分词),python支持的适应度计算导入文件

代码片段和文件信息
‘‘‘
Allows scoring of text using n-gram probabilities
17/07/12
‘‘‘
from math import log10
class ngram_score(object):
def __init__(selfngramfilesep=‘ ‘):
‘‘‘ load a file containing ngrams and counts calculate log probabilities ‘‘‘
self.ngrams = {}
for line in file(ngramfile):
keycount = line.split(sep)
self.ngrams[key] = int(count)
self.L = len(key)
self.N = sum(self.ngrams.itervalues())
#calculate log probabilities
for key in self.ngrams.keys():
self.ngrams[key] = log10(float(self.ngrams[key])/self.N)
self.floor = log10(0.01/self.N)
def score(selftext):
‘‘‘ compute the score of text ‘‘‘
score = 0
ngrams = self.ngrams.__getitem__
for i in xrange(len(text)-self.L+1):
if text[i:i+self.L] in self.ngrams: score += ngrams(text[i:i+self.L])
else: score += self.floor
return score
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 0 2020-01-13 02:40 閫傚簲搴﹁绠?
文件 6148 2020-01-13 02:40 閫傚簲搴﹁绠?.DS_Store
文件 120 2020-01-13 02:40 __MACOSX\閫傚簲搴﹁绠?._.DS_Store
文件 972 2019-11-29 01:12 閫傚簲搴﹁绠?ngram_score.py
文件 975928 2019-11-29 01:08 閫傚簲搴﹁绠?english_quadgrams.txt.zip
文件 591 2019-11-29 01:08 __MACOSX\閫傚簲搴﹁绠?._english_quadgrams.txt.zip
- 上一篇:多标签数据集.zip
- 下一篇:python习题
相关资源
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
评论
共有 条评论