Ubuntu – Tool for measuring readability of English text

command linelanguagesoftware-recommendation

Is there a command line program that takes a file containing English text, analyzes the text, and outputs its readability scores?

For example, if one feeds the program a text, the program should output the Flesch-Kincaid grade level, McLaughlin's SMOG grading, etc.

I believe such a program exists in the official repositories, but I cannot remember its name. There's also the possibility that I am misremebering.

Best Answer

The diction Install diction package contains a tool called style:

Style analyses the surface characteristics of the writing style of a document. It prints various readability grades, length of words, sentences and paragraphs. It can further locate sentences with certain characteristics.

For example, if I evaluate your question body (saved in a file flux_question) to print the sentences with a readability index (ARI) over 10:

$ style -r 10 flux_question
flux_question:1: Is there a command line program that takes a file containing English text, analyzes the text, and outputs its readability scores?
flux_question:2: For example, if one feeds the program a text, the program should output the Flesch-Kincaid grade level, McLaughlin's SMOG grading, etc.
readability grades:
        Kincaid: 10.2
        ARI: 10.8
        Coleman-Liau: 12.5
        Flesch Index: 51.1/100
        Fog Index: 12.0
        Lix: 48.6 = school year 9
        SMOG-Grading: 11.2
sentence info:
        333 characters
        65 words, average length 5.12 characters = 1.65 syllables
        4 sentences, average length 16.2 words
        25% (1) short sentences (at most 11 words)
        0% (0) long sentences (at least 26 words)
        1 paragraphs, average length 4.0 sentences
        25% (1) questions
        25% (1) passive sentences
        longest sent 21 wds at sent 2; shortest sent 8 wds at sent 4
word usage:
        verb types:
        to be (1) auxiliary (2) 
        types as % of total:
        conjunctions 5% (3) pronouns 9% (6) prepositions 2% (1)
        nominalizations 0% (0)
sentence beginnings:
        pronoun (1) interrogative pronoun (0) article (0)
        subordinating conjunction (0) conjunction (0) preposition (0)

To filter the output you can use e.g. tail -n8 to get only the grades or grep 'Flesch\|SMOG' to just print the Flesch Index and the SMOG-Grading:

$ style flux_question | grep 'Flesch\|SMOG'
        Flesch Index: 51.7/100
        SMOG-Grading: 11.2

Further reading