The Flesch Reading Ease test is generally regarded as the most accurate score to express how quickly a particular English text can be read. Several U.S. government agencies use this test to check the readability of their documents. For example, the State of Florida requires a minimum Flesch Reading Ease score of 45 for life insurance contracts. The score was also built in into several popular word processors such as Microsoft Office Word and WordPerfect. The Flesch Reading Ease formula goes as follows: \[FRES=206.835 -1.015 \times \frac{\text{total words}}{\text{total sentences}} - 84.6 \times \frac{\text{total syllables}}{\text{total words}} \] The result of the formula is the Flesch Reading Ease Score (FRES). The higher the FRES, the easier it is to understand the text. A score between 0 and 30 is considered to be readable for university graduates. A text with a score between 60 and 70 should be readable for pupils from 13-15 years, and a score between 90 and 100 should be readable for pupils at the end of primary school. The highest (easiest) readability score is about 120, this is achieved when each sentence is composed of two monosyllabic words. The score has no theoretical limit. It is always possible to reduce the score by adding words with many syllables.
Although the application of FRES seems simple, we still have to clearly formulate how sentences, words and syllables are counted. Sentences are separated by punctuation marks: periods(.), exclamation marks(!), question marks(?), colons(:) and semicolons (;). The fragment after the last punctuation mark should also be counted as a sentence, unless the fragment is empty or consists only of white space. Each group of consecutive letters (a-z, A-Z) forms a separate word. In English texts an apostrophe (') is exclusively used to indicate a contraction of two words. The fragment "It's" thus contains two words. To count syllables the following rules are applied:
words of maximum three letters always consist of only one syllable
each vowel (aeiouy) in a word is considered as one syllable, except in the following cases
the silent e in word ends that are equal to -es, -ed or -e (except-le) are ignored (as if they weren't there)
sequences of vowels count as one syllable
The aim of this assignment is to determine the Flesch Reading Ease score of the text in a given text file. To do this, follow these steps.
Write a function syllables that returns the number of syllables of a given word. The word must be passed to the function as an argument.
Use the function syllables to write a function words to which a sentence should be passed as an argument. This function must determine the number of words, and the total number of syllables in all words of the sentence, and return these two values as a tuple.
Use the function words to write a function sentences that file must be passed the file name of a text as an argument. The function must determine i) how many sentences occur in the text file ii) the total number of words in the text file, and iii) the total number of syllables in all words of the file. These three values must be returned by the function as a tuple.
Write a function that FRES to which three arguments must be passed: the number of sentences in a text, the total number of words in the text, and the total number of syllables in all words of the text together. The function should return the Flesch Reading Ease score of the text based on these three values.
In the example session below the Flesch Reading Ease score is calculated of a couple sentences of chapter 64 from the classic Moby Dick1 by Herman Melville. These sentences can be found in the text file moby_dick.txt2.
>>> syllables('reliable')
3
>>> syllables('creature')
2
>>> syllables('three')
1
>>> words('The Australian platypus is seemingly a hybrid of a mammal and reptilian creature.')
(13, 24)
>>> words("Stubb's whale had been killed some distance from the ship.")
(11, 13)
>>> sentences('moby_dick.txt')
(12, 220, 298)
>>> FRES(12, 220, 298)
73.63212121212123