# -*- coding: utf-8 -*- # Adadpted from here: http://acdx.net/calculating-the-flesch-kincaid-level-in-python/ # See here for details: http://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_test from __future__ import division import re def mean(seq): return sum(seq) / len(seq) def syllables(word): if len(word) <= 3: return 1 word = re.sub(r"(es|ed|(?= 2] if wc: words = wc else: words = sum(len(s) for s in stcs) sbls = sum(syllables(w) for s in stcs for w in s) return len(stcs), words, sbls def flesch_index(stats): stcs, words, sbls = stats if stcs == 0 or words == 0: return 0 return 206.835 - 1.015 * (words / stcs) - 84.6 * (sbls / words) def flesch_kincaid_level(stats): stcs, words, sbls = stats if stcs == 0 or words == 0: return 0 return 0.39 * (words / stcs) + 11.8 * (sbls / words) - 15.59