def show_stat(text): rd = Readability(text) print 'Test text:' print '"%s"\n' % text print 'ARI: ', rd.ARI() print 'FleschReadingEase: ', rd.FleschReadingEase() print 'FleschKincaidGradeLevel: ', rd.FleschKincaidGradeLevel() print 'GunningFogIndex: ', rd.GunningFogIndex() print 'SMOGIndex: ', rd.SMOGIndex() print 'ColemanLiauIndex: ', rd.ColemanLiauIndex() print 'LIX: ', rd.LIX() print 'RIX: ', rd.RIX()
def get_read_stats(text): read = {} # readability stats rd = Readability(text) read['ari'] = rd.ARI() read['flesch_reading_ease'] = rd.FleschReadingEase() read['flesch_kincaid_grade_level'] = rd.FleschKincaidGradeLevel() read['gunning_fog_index'] = rd.GunningFogIndex() read['smog_index'] = rd.SMOGIndex() read['coleman_liau_index'] = rd.ColemanLiauIndex() read['lix'] = rd.LIX() read['rix'] = rd.RIX() return read
def readability(id): r = {} text = getDocContent(id) #print text rd = Readability(text) r["ARI"] = rd.ARI() r["FleschReadingEase"] = rd.FleschReadingEase() r["FleschKincaidGradeLevel"] = rd.FleschKincaidGradeLevel() r["RIX"] = rd.RIX() r["GunningFogIndex"] = rd.GunningFogIndex() r["SMOGIndex"] = rd.SMOGIndex() r["ColemanLiauIndex"] = rd.ColemanLiauIndex() r["LIX"] = rd.LIX() return r
def getReadability(): authorFileNames = os.listdir(directory) texts = [] authors = [] truth = {} quote = [] sents = [] for file in authorFileNames: if file.endswith(".xml"): te = gettext(file) te.encode('ascii', 'ignore') texts.append(te) authors.append(file[:-4]) else: fgh = open(directory + "/" + file, 'r') fg = fgh.read().split('\n')[:-1] for r in fg: df = r.split(':::')[1:] truth[r.split(':::')[0]] = df fgh.close() f = open('PANreadibility.csv', 'w') f.write( 'ID,Gender,Age,ARI,FleschReadingEase,FleschKincaidGradeLevel,GunningFogIndex,SMOGIndex,ColemanLiauIndex,LIX,RIX\n' ) for i in range(len(authors)): sf = texts[i] rd = Readability(sf.encode('ascii', 'ignore')) f.write(authors[i] + ',' + truth[authors[i]][0] + ',' + truth[authors[i]][1] + ',' + str(rd.ARI()) + ',' + str(rd.FleschReadingEase()) + ',' + str(rd.FleschKincaidGradeLevel()) + ',' + str(rd.GunningFogIndex()) + ',' + str(rd.SMOGIndex()) + ',' + str(rd.ColemanLiauIndex()) + ',' + str(rd.LIX()) + ',' + str(rd.RIX()) + '\n') f.close()
def readability(self, text): rd = Readability(text) fkg_score = rd.FleschKincaidGradeLevel() SMOG = rd.SMOGIndex() return fkg_score, SMOG
def get_smog(text): txt = Readability(text) try: return txt.SMOGIndex() except ZeroDivisionError: return 0
# encoding: utf-8 # -*- coding: utf-8 -* import sys reload(sys) sys.setdefaultencoding('utf8') from readability import Readability #file = open("C:\\Users\\Administrator\\Desktop\\myfolder\\sea-and-adventures\\the-old-man-and-the-sea.txt") file = open( "C:\\Users\\Administrator\\Desktop\\myfolder\\corpora\\An-Inquiry-into-the-Nature-and-Causes-of-the-Wealth-of-Nations.txt" ) text = file.read() rd = Readability(text) print 'ARI: ', rd.ARI() print 'FleschReadingEase: ', rd.FleschReadingEase() print 'FleschKincaidGradeLevel: ', rd.FleschKincaidGradeLevel() print 'GunningFogIndex: ', rd.GunningFogIndex() print 'SMOGIndex: ', rd.SMOGIndex() print 'ColemanLiauIndex: ', rd.ColemanLiauIndex() print 'LIX: ', rd.LIX() print 'RIX: ', rd.RIX()