从文本计算统计特征

textstat的Python项目详细描述


文本状态

Python包从文本中计算统计,以确定特定语料库的可读性、复杂性和等级水平。

Downloads

用法

>>>importtextstat>>>test_data=("Playing games has always been thought to be important to ""the development of well-balanced and creative children; ""however, what part, if any, they should play in the lives ""of adults has never been researched that deeply. I believe ""that playing games is every bit as important for adults ""as for children. Not only is taking time out to play games ""with our children and other adults valuable to building ""interpersonal relationships but is also a wonderful way ""to release built up tension.")>>>textstat.flesch_reading_ease(test_data)>>>textstat.smog_index(test_data)>>>textstat.flesch_kincaid_grade(test_data)>>>textstat.coleman_liau_index(test_data)>>>textstat.automated_readability_index(test_data)>>>textstat.dale_chall_readability_score(test_data)>>>textstat.difficult_words(test_data)>>>textstat.linsear_write_formula(test_data)>>>textstat.gunning_fog(test_data)>>>textstat.text_standard(test_data)

所有已定义函数的参数(文本)保持不变- 即需要计算统计数据的文本。

安装

您可以通过python包索引(pypi)或从源代码安装textstat。

使用pip安装
pip install textstat

使用简易安装安装
easy_install textstat

从github安装最新版本
git clone https://github.com/shivam5992/textstat.git
cd textstat
pip install .

从pypi安装

http://pypi.python.org/pypi/textstat/下载最新版本的textstat

您可以通过执行以下操作来安装:

tar xfz textstat-*.tar.gz
cd textstat-*/
python setup.py build
python setup.py install # as root

功能列表

音节计数

textstat.syllable_count(text,lang='en_US')

返回给定文本中的音节数。

使用python模块Pyphen 用于音节计算。可选的lang指定为 使用哪种语言词典。

默认值是'en_US''en_GB'也可以工作。

词典计数< EH3>
textstat.lexicon_count(text,removepunct=True)

计算文本中出现的单词数。 可选removepunct指定是否需要 在计算词典时考虑标点符号。 默认值是True,它删除标点符号 在计算词汇之前。

句子计数

textstat.sentence_count(text)

返回给定文本中的句子数。

弗莱希阅读简易公式

textstat.flesch_reading_ease(text)

返回flesch reading ease分数。

下表有助于评估 文档的可读性。

该表是值的示例。而 最大得分是121.22分,没有限制的有多低 比分可以是。负分有效。

ScoreDifficulty
90-100Very Easy
80-89Easy
70-79Fairly Easy
60-69Standard
50-59Fairly Difficult
30-49Difficult
0-29Very Confusing

Further reading on Wikipedia

flesch-kincaid等级

textstat.flesch_kincaid_grade(text)

返回给定文本的flesch-kincaid等级。这是一个年级 公式中,9.3分意味着九年级学生将能够 阅读文档。

Further reading on Wikipedia

雾度(喷雾公式)

textstat.gunning_fog(text)

返回给定文本的雾索引。这是一个分数公式 9.3分意味着九年级的学生将能够阅读该文件。

Further reading on Wikipedia

烟雾指数

textstat.smog_index(text)

返回给定文本的烟雾索引。这是一个分数公式 9.3分意味着九年级的学生将能够阅读该文件。

少于30句的文章在统计上是无效的,因为 烟雾公式在30个句子样本上进行了标准化。textstat至少需要 一个结果用三句话。

Further reading on Wikipedia

自动可读性指数

textstat.automated_readability_index(text)

返回输出的ari(自动可读性索引) 接近需要的等级水平的数字 理解课文。

例如,如果ari是6.5,那么要理解的年级级别 课文是六到七年级的。

Further reading on Wikipedia

coleman liau指数

textstat.coleman_liau_index(text)

使用coleman liau公式返回文本的级别。这是 分数为9.3意味着九年级的学生 能够阅读文档。

Further reading on Wikipedia

Linsear编写公式

textstat.linsear_write_formula(text)

使用linsear write公式返回年级。这是 分数为9.3意味着九年级的学生 能够阅读文档。

Further reading on Wikipedia

戴尔·查尔可读性评分

textstat.dale_chall_readability_score(text)

与其他测试不同,因为它使用查找表 在最常用的3000个英语单词中。所以它又回来了 使用新的戴尔-查尔公式的年级。

ScoreUnderstood by
4.9 or loweraverage 4th-grade student or lower
5.0–5.9average 5th or 6th-grade student
6.0–6.9average 7th or 8th-grade student
7.0–7.9average 9th or 10th-grade student
8.0–8.9average 11th or 12th-grade student
9.0–9.9average 13th to 15th-grade (college) student

Further reading on Wikipedia

基于以上所有测试的可读性一致性

textstat.text_standard(text,float_output=False)

基于以上所有测试,返回估计的学校 理解课文所需的年级。

可选的float_output允许将分数作为 float。默认为False

贡献

如果你发现任何问题,你应该打开一个 issue

如果你能解决你发现的问题,或者其他问题,你应该打开 一个pull request

  1. 在github上派生这个存储库,开始对master进行更改 分支(或分支)。
  2. 编写一个测试,显示错误已修复或功能按预期工作。
  3. 发送请求!

开发设置

It is recommended you use a virtual environment, or Pipenv to keep your development work isolated from your systems Python installation.

$ git clone https://github.com/<yourname>/textstat.git  # Clone the repo from your fork
$ cd textstat
$ pip install -r requirements.txt  # Install all dependencies

$ # Make changes

$ python -m unittest test.py  # Run tests

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java SimpleCursorAdapter删除值   java结束while循环条件   java检查设备是否连接到特定网络   java组织。冬眠MappingException找不到逻辑名称为annotation getter的列   为什么java邮件中会抛出此异常?   加载SDK时发生java Eclipse错误   返回奇怪输出的Java数组   JavaXStream和对象类序列化   将枚举列表传递给namedQuery后出现java非法转换异常。Hibernate中的setParameter()   java Android studio不允许我在字符串上使用开关?   有没有办法从Java程序访问存储在Chrome中的cookie   java在枚举中构造实例而不修改枚举类   java Blackberry JDE FieldChangeListener   java修复错误:未报告的异常InterruptedException   java Spring数据JPA:findAll(具有规范和可分页)在计数查询中失败