-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReading Level.py
More file actions
36 lines (32 loc) · 1.39 KB
/
Reading Level.py
File metadata and controls
36 lines (32 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from textblob import TextBlob
import csv
import sys
import time
import datetime
from textstat.textstat import textstat
inputfile = "INPUT FILE"
textcol = 7
textcoltitle = "TEXT OF SPEECH"
output = csv.writer(open("readinglevel-"+inputfile, 'wt'))
def get_reading(line):
row = line
test_data = line[textcol]
try:
flesch_kincaid_grade = str(textstat.flesch_reading_ease(test_data))
gunning_fog = str(textstat.gunning_fog(test_data))
smog_index = str(textstat.smog_index(test_data))
automated_readability_index = str(textstat.automated_readability_index(test_data))
linsear_write_formula = str(textstat.linsear_write_formula(test_data))
dale_chall_readability_score = str(textstat.dale_chall_readability_score(test_data))
coleman_liau_index = str(textstat.coleman_liau_index(test_data))
consensus = str(textstat.text_standard(test_data))
output.writerow(row+[flesch_kincaid_grade,gunning_fog,smog_index,automated_readability_index,linsear_write_formula,dale_chall_readability_score,coleman_liau_index,consensus])
except Exception:
sys.exc_clear()
with open("data/"+inputfile) as f:
reader = csv.reader(f, delimiter=",")
for line in reader:
if line[textcol]==textcoltitle:
output.writerow(line+["flesch_kincaid_grade","gunning_fog","smog_index","automated_readability_index","linsear_write_formula","dale_chall_readability_score","coleman_liau_index","consensus"])
else:
get_reading(line)