不同出版物的可读性
在本练习中,您将获得来自四家出版物的文章节选。您的任务是使用 Gunning fog 分数计算这些节选的可读性,并据此判断这些出版物的相对阅读难度。
这些节选以如下字符串给出:
forbes——来自《Forbes》杂志关于中国社会信用体系的文章节选。harvard_law——来自《Harvard Law Review》发表的一篇书评节选。r_digest——来自《Reader's Digest》关于航班颠簸的文章节选。time_kids——来自《TIME for Kids》关于食盐摄入不良影响的文章节选。
本练习是课程的一部分
Python 中的 NLP 特征工程
练习说明
- 从
readability导入Readability类。 - 对每个
excerpt,在Readability上调用gunning_fog()方法来计算gf对象。 - 使用
score属性计算 Gunning fog 分数。 - 打印 Gunning fog 分数列表。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import Readability
from readability import Readability
# List of excerpts
excerpts = [forbes, harvard_law, r_digest, time_kids]
# Loop through excerpts and compute gunning fog index
gunning_fog_scores = []
for excerpt in excerpts:
gf = Readability(excerpt).____()
gf_score = gf.____
gunning_fog_scores.append(gf_score)
# Print the gunning fog indices
print(gunning_fog_scores)