MCPcopy Index your code
hub / github.com/clips/pattern / flesch_reading_ease

Function flesch_reading_ease

pattern/metrics.py:302–330  ·  view source on GitHub ↗

Returns the readability of the string as a value between 0.0-1.0: 0.30-0.50 (difficult) => 0.60-0.70 (standard) => 0.90-1.00 (very easy).

(string)

Source from the content-addressed store, hash-verified

300# 0.0-0.3 = best understood by university graduates.
301
302def flesch_reading_ease(string):
303 """ Returns the readability of the string as a value between 0.0-1.0:
304 0.30-0.50 (difficult) => 0.60-0.70 (standard) => 0.90-1.00 (very easy).
305 """
306 def count_syllables(word, vowels="aeiouy"):
307 n = 0
308 p = False # True if the previous character was a vowel.
309 for ch in word.endswith("e") and word[:-1] or word:
310 v = ch in vowels
311 n += int(v and not p)
312 p = v
313 return n
314 if len(string) < 3:
315 return 1.0
316 string = string.strip()
317 string = string.strip("\"&#x27;().")
318 string = string.lower()
319 string = string.replace("!", ".")
320 string = string.replace("?", ".")
321 string = string.replace(",", " ")
322 y = [count_syllables(w) for w in string.split() if w != ""]
323 w = len([w for w in string.split(" ") if w != ""])
324 s = len([s for s in string.split(".") if len(s) > 2])
325 #R = 206.835 - 1.015 * w/s - 84.6 * sum(y)/w
326 # Use the Farr, Jenkins & Patterson algorithm,
327 # which uses simpler syllable counting (count_syllables() is the weak point here).
328 R = 1.599 * sum(1 for v in y if v == 1) * 100 / w - 1.015*w/s - 31.517
329 R = max(0.0, min(R*0.01, 1.0))
330 return R
331
332readability = flesch_reading_ease
333

Callers

nothing calls this directly

Calls 5

lenFunction · 0.85
count_syllablesFunction · 0.85
sumFunction · 0.85
stripMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…