自然语言处理是对自然人类语言的自动生成和理解的研究。随着计算机技术已集成到当今几乎每个行业中,这变得越来越有趣。我们将研究自然语言处理中的一个特定领域。可读性。这涉及确定文本的可读性的主题。这表明阅读或理解文本有多困难。
可读性索引是一个数字值,它指示阅读和理解文本的难易程度。有几种用于确定可读性的测试,并且它们具有不同的使用领域。
“可读性描述了阅读文档的难易程度” [13]。存在许多不同的测试[9]来计算可读性。可读性测试“被认为是阅读容易程度的预测,但不是确定可读性的唯一方法”
某些测试对语言没有影响,但是有些测试更适合某些语言。了解不同的可读性测试对我们至关重要。
| 可读性测试- | 打算使用(语言)- | 简短说明和公式- |
|---|---|---|
| 自动可读性指数(ARI) | 英语 | 旨在衡量文本的可理解性。输出是理解课文所需的美国年级水平的近似表示。ARI = 4.71 * (characters/words) + 0.5 * (words/sentence) -21.43 |
Flesch阅读轻松 | 英语 | 旨在表明阅读文章的难易程度。分数越高,表明材料越容易阅读;较低的数字表示难读的段落。FRE = 206.835 − 1.015*(total words/ total sentences) − 84.6 * (total syllables/ total words) |
| FleschKincaid年级 | 英语 | 旨在表明阅读文章的难易程度。结果是一个与美国成绩等级相对应的数字。FKGL = 0.39 * (total words/ total sentences) + 11.8 (total syllables/ total words) -15.59 |
| 科尔曼-廖指数 | 英语 | 旨在衡量文本的可理解性。输出是被认为是理解文本所必需的近似美国年级水平。CLI = (5.89 * (characters/ words)) − (30 *(sentences/words)) − 15.8 |
| 冈尼雾指数 | 英语 | 旨在测量英语写作样本的可读性。结果索引表明一个人需要多少年接受正规教育(美国年级),以便轻松阅读一读课本。GFI = 0.4 * (( words/ sentence) + 100 * (complex words/ words)) |
| Linsear写 | 英语 | 为空军开发的英文文本可读性度量标准,可帮助他们计算技术手册的可读性。维基百科的公式:
|
| 利率指数(RIX) | 西欧语言 | 这很有用,因为它可用于任何西欧语言的文档[3]。输出是介于0(非常容易)和55+(非常困难)之间的分数。RIX = (Long Words/ Sentences) (long words = words where number of characters > 6) |
| 莱斯巴赫特指数(LIX) | 西欧语言 | 这很有用,因为它可以用于任何西欧语言的文档[2] [3]。输出是指示等级的索引。低于0.1的指数为1年级,而7.2及更高的指数为大学年级。LIX = (total words/ total sentences) + (long words/ total words * 100) (long words = words where number of characters > 6) |
例如,下面是通过flesch索引确定文本文件可读性的程序。
| 弗氏指数 | 文字文件阅读成绩 |
|---|---|
| 0-30 | 学院 |
| 50-60 | 中学 |
| 90-100 | 四年级 |
从上面,flesch-kincaid等级级别公式用于计算等效等级级别G-
FKGL = 0.39 *(总单词/总句子数)+ 11.8(总音节/总单词数)-15.59
import os
dire = os.getcwd()
listOfdir = os.listdir(dire)
while True:
UserFileName = input('Enter file name:')
if (UserFileName in listOfdir) and (UserFileName.endswith(".txt")):
InputFile = open(UserFileName,'r')
text = InputFile.read()
sentence = text.count('.') + text.count('!') + text.count(';') + text.count(':') + text.count('?')
words = len(text.split())
syllable = 0
for word in text.split():
for vowel in ['a','e','i','o','u']:
syllable + = word.count(vowel)
for ending in ['es','ed','e']:
if word.endswith(ending):
syllable - = 1
if word.endswith('le'):
syllable + = 1
G = round((0.39*words)/sentence+ (11.8*syllable)/words-15.59)
if G > = 0 and G < = 30:
print ('The Readability level is College')
elif G > = 50 and G < = 60:
print ('The Readability level is High School')
elif G > = 90 and G < = 100:
print ('The Readability level is fourth grade')
print ('This text has %d words' %(words))
elif UserFileName not in listOfdir:
print ('This text file does not exist in current directory')
elif not(UserFileName.endswith('.txt')):
print ('This is not a text file.')输出结果
Enter file name:dataVisualization.txt The Readability level is College This text has 64 words