legibilidad.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:legibilidad 作者: amunozf 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号