不同出版物的可讀性
在這個練習中,你會拿到來自四種出版物的文章節錄。你的任務是用 Gunning fog 分數計算這些節錄的可讀性,並據此判斷閱讀這些出版物的相對難度。
這些節錄以以下字串提供:
forbes-出自《Forbes》雜誌一篇談論中國社會信用評分系統的文章節錄。harvard_law-出自《Harvard Law Review》書評的節錄。r_digest-出自《Reader's Digest》談飛行亂流的文章節錄。time_kids-出自《TIME for Kids》一篇討論攝取鹽分負面影響的文章節錄。
本練習屬於課程
Python 中文本特徵工程
練習說明
- 從
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)