开始使用免费开始使用

不同出版物的可读性

在本练习中,您将获得来自四家出版物的文章节选。您的任务是使用 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)
编辑并运行代码