要计算英文文本的Flesch Reading Ease、Flesch-Kincaid Grade、Gunning Fog和Automated Readability Index,可以使用Python中的textstat模块。首先需要安装该模块:

pip install textstat

然后可以使用以下代码计算各个指标:

import textstat

text = 'This is a sample text for readability calculation. It should not be too difficult to read, but it should be long enough to provide a meaningful sample. The quick brown fox jumps over the lazy dog.'

# 计算flesch_reading_ease
flesch_reading_ease = textstat.flesch_reading_ease(text)
print('flesch_reading_ease: ', flesch_reading_ease)

# 计算flesch_kincaid_grade
flesch_kincaid_grade = textstat.flesch_kincaid_grade(text)
print('flesch_kincaid_grade: ', flesch_kincaid_grade)

# 计算gunning_fog
gunning_fog = textstat.gunning_fog(text)
print('gunning_fog: ', gunning_fog)

# 计算automated_readability_index
automated_readability_index = textstat.automated_readability_index(text)
print('automated_readability_index: ', automated_readability_index)

以上代码输出结果如下:

flesch_reading_ease:  73.64
flesch_kincaid_grade:  6.2
gunning_fog:  8.29
automated_readability_index:  8.3

这些指标分别表示文本的易读程度,数值越小越难读,越大越容易读。

Python文本可读性分析:计算Flesch Reading Ease、Flesch-Kincaid Grade、Gunning Fog和Automated Readability Index

原文地址: https://www.cveoy.top/t/topic/oMs1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录