The Flesch readability index is a tool for estimating the reading comprehension level necessary to understand a written document. For a given document, the Flesch readability index is an integer indicating how difficult the document is to understand, with lower numbers indicating greater difficulty. For example, the table below shows typical Flesch readability index values for some common(and some not-so-common) reading material:
| Material | Flesch Index |
|---|---|
| Comics | 95 |
| Consumer Ads | 82 |
| Sports Illustrated | 65 |
| Time | 57 |
| New York Times | 39 |
| Auto Insurance | 10 |
| IRS Code | -6 |
Flesch readability indexes are also often translated into the educational level that is usually necessary to understand a document:
| Flesch Index | Educational Level |
|---|---|
| 91-100 | 5th grade |
| 81-90 | 6th grade |
| 71-80 | 7th grade |
| 66-70 | 8th grade |
| 61-66 | 9th grade |
| 51-60 | High School |
| 31-50 | Some College |
| 0-30 | College Graduate |
| < 0 | Law School Graduate |
The Flesch readability index for a document is computed using 5 steps:
With a simple method for computing the Flesch readability index it is possible for authors to write and revise documents until they are comprehensible to the target audience. For example, a newspaper reported might continue to revise an article until the Fesch readability index is above 60.
At least one popular word processor is able to compute the Fesch readability index. If you ask Microsoft Word to display the readability statistics for a document, it will display a Flesh reading ease score, which is the same as the readability index. If you are interested in more information see chapter 2, of Flesch's "How to Write Plain English" (interestingly enough, Flesch was French!)
Before beginning the lab you will need to create a lab7 directory within your cs132 directory. All of your files for this lab must be saved in this cs132/lab7 directory.
You will also need to download the TextFileReader.class file to your cs132/lab7 directory. You will use a TextFileReader object to read a document from a text file in order to compute its Flesch readability index. There are more details on how to use the TextFileReader class below.
In this lab you will develop and test two classes and write an application that uses your classes to compute the Flesch readability index for a document. The first class you will write and test is the Word class which represents a single word and provides a method for counting the number of syllables in a word. The second class that you will write and test is the Sentence class. The Sentence class represents a collection of words. It provides methods for counting the number of words in the sentence and extracting each word from the sentence one by one. With both of these classes written and tested you will write an application (i.e. a class with a main method) which uses Word and Sentence objects to compute the Flesch readability index of a document. More details on each part of this assignment appear in the following sections:
The Word Class
Implement the Word class according to the description which appears in the Java documentation for the Word class. Notice that the rules for how syllables should be counted are described in the documentation for the countSyllables method.
Write a test program for your Word class in the file WordTest.java. As with our test programs in the past, this test program should contain only a main method. The main method should create a number of Word objects and test each of the instance methods. Be sure to select test cases which are sufficient to fully test your Word class.
The Sentence Class
Implement the Sentence class according to the description which appears in the Java documentation for the Sentence class. The easiest approach to implementing the Sentence class is to use a StringTokenizer as part of the the instance data. You may also find that the endsWith instance method in the String class is useful in creating your Sentence class.
Notice that the Sentence class is coupled to the Word class. Thus, your Word class must be completed before you can write the Sentence class. Write a test program for your Sentence class in the file SentenceTest.java.
The Flesch Appplication
In a class named Flesch, write a main method that uses your Sentence and Word classes to compute and display the Flesch readability index of a document. Your Flesch application should prompt the user for the name of the file to be analyzed and then compute and display the Flesch readability index for that file.
In order to read the input file you will need to use a TextFileReader object. The Java documentation for the TextFileReader class contains an example which should be sufficient to get you started.
You should create a few simple text files in emacs to test your Flesch program. If you make these files simple enough you can compute the index by hand. That way, when you run you program you can tell if it computes the correct answer. After you do that you might want to run your program on some more extensive text files. The Etexts web site provides an extensive library of text files containing public domain literary works. Some examples, with their readability index include:
| Work | Flesch Index |
|---|---|
| Romeo & Juliet | 84 |
| Tom Sawyer, Detective | 84 |
| Beowulf | 75 |
| Plato's Republic | 69 |
To test your program on one of these texts, click on its link and then choose "Save as..." from the "File" menu. Please, be sure to delete these files when you are finished to avoid filling up your home directory.
This lab will be worth 50 points. The Word and Sentence classes will be worth 15 points each. The WordTest and SentenceTest classes will be worth 5 points each. The Flesch program will be worth 10 points.
On the due date for this lab, you must hand in a printout of the following files:
Word.java
WordTest.java
Sentence.java
SentenceTest.java
Flesch.java
These files must also appear in your cs132/lab7 directory.
When writing your programs please be sure to pay attention to the following readability and maintainability issues: