def mu(text):
'''
Muñoz Baquedano and Muñoz Urra's readability score (2006)
'''
n = count_words(text)
# Delete all digits
text = ''.join(filter(lambda x: not x.isdigit(), text))
# Cleans it all
clean = re.compile('\W+')
text = clean.sub(' ', text).strip()
text = text.split() # word list
word_lengths = []
for word in text:
word_lengths.append(len(word))
# The mean calculation needs at least 1 value on the list, and the variance, two. If somebody enters only one word or, what is worse, a figure, the calculation breaks, so this is a 'fix'
try:
mean = statistics.mean(word_lengths)
variance = statistics.variance(word_lengths)
mu = (n / (n - 1)) * (mean / variance) * 100
return round(mu, 2)
except:
return 0
评论列表
文章目录