Lingua::EN::Fathom 1.05
Perl
module
-
Part of CPAN
distribution
Lingua-EN-Fathom 1.05.
Lingua::EN::Fathom - readability and general measurements of English text
use Lingua::EN::Fathom;
my $text = new Lingua::EN::Fathom;
$text->analyse_file("sample.txt");
$accumulate = 1;
$text->analyse_block($text_string,$accumulate);
$num_chars = $text->num_chars;
$num_words = $text->num_words;
$num_sentences = $text->num_sentences;
$num_text_lines = $text->num_text_lines;
$num_blank_lines = $text->num_blank_lines;
$num_paragraphs = $text->num_paragraphs;
%words = $text->unique_words;
foreach $word ( sort keys %words )
{
print("$words{$word} :$word\n");
}
$fog = $text->fog;
$flesch = $text->flesch;
$kincaid = $text->kincaid;
print($text->report);
Perl, version 5.001 or higher, Lingua::EN::Syllable
This module analyses English text in either a string or file. Totals are
then calculated for the number of characters, words, sentences, blank
and non blank (text) lines and paragraphs.
Three common readability statistics are also derived, the Fog, Flesch and
Kincaid indices.
All of these properties can be accessed through individual methods, or by
generating a text report.
A hash of all unique words and the number of times they occur is generated.
The new method creates an instance of an text object This must be called
before any of the following methods are invoked. Note that the object only
needs to be created once, and can be reused with new input data.
my $text = new Lingua::EN::Fathom;
The analyse_file method takes as input the name of a text file. Various
text based statistics are calculated for the file. This method and
analyse_block are prerequisites for all the following methods. An optional
argument may be supplied to control accumulation of statistics. If set to
a non zero value, all statistics are accumulated with each successive call.
The analyse_block method takes as input the name of a text file. Various
text based statistics are calculated for the file. This method and
analyse_file are prerequisites for all the following methods. An optional
argument may be supplied to control accumulation of statistics. If set to
a non zero value, all statistics are accumulated with each successive call.
Returns the number of characters in the analysed text file or block. This
includes characters such as spaces, and punctuation marks.
Returns the number of words in the analysed text file or block. A word must
consist of letters a-z with at least one vowel sound, and optionally an
apostrophe or hyphen. Items such as "&, K108, NSW" are not counted as words.
Returns the number of sentences in the analysed text file or block. A sentence
is any group of words and non words terminated with a single full stop. Spaces
may occur before and after the full stop.
Returns the number of lines containing some text in the analysed text file
or block.
Returns the number of lines NOT containing any text in the analysed text file
or block.
Returns the number of paragraphs in the analysed text file or block.
Three indices of text readability are calculated. They all measure complexity as
a function of syllables per word and words per sentence. They assume the text is
well formed and logical. You could analyse a passage of nonsensical English and
find the readability is quite good, provided the words are not too complex and
the sentences not too long.
For more information see: http://www.plainlanguage.com/Resources/readability.html
Returns the Fog index for the analysed text file or block.
words_per_sentence + percent_complex_words ) * 0.4
The Fog index, developed by Robert Gunning, is a well known and simple
formula for measuring readability. The index indicates the number of years
of formal education a reader of average intelligence would need to read the
text once and understand that piece of writing with its word sentence workload.
18 unreadable
14 difficult
12 ideal
10 acceptable
8 childish
Returns the Flesch reading ease score for the analysed text file or block.
206.835 - (1.015 * words_per_sentence) - (84.6 * syllables_per_word)
This score rates text on a 100 point scale. The higher the score, the easier
it is to understand the text. A score of 60 to 70 is considered to be optimal.
Returns the Flesch-Kincaid grade level score for the analysed text
file or block.
(11.8 * syllables_per_word) + (0.39 * words_per_sentence) - 15.59;
This score rates text on U.S. grade school level. So a score of 8.0 means
that the document can be understood by an eighth grader. A score of 7.0 to
8.0 is considered to be optimal.
Returns a hash of unique words. The words (in lower case) are held in
the hash keys while the number of occurrences are held in the hash values.
print($text->report);
Produces a text based report containing the following statistics for
the currently analysed text block or file:
Number of characters
Number of words
Average syllables per word
Number of sentences
Average words per sentence
Number of text lines
Number of blank lines
Number of paragraphs
Fog Index
Flesch Index
Flesch-Kincaid Index
The return value is a string containing the report contents
Lingua::EN::Syllable
Lingua::EN::Sentence
B::Fathom
Count white space and punctuation characters
Allow user control over what strictly defines a word
Provide a density measure of white space to characters
The syllable count provided in Lingua::EN::Syllable is about 90% accurate
Acronyms that contain vowels, like GPO, will be counted as words.
The fog index should exclude proper names
Copyright (c) 2000-1 Kim Ryan. All rights reserved.
This program is free software; you can redistribute it
and/or modify it under the terms of the Perl Artistic License
(see http://www.perl.com/perl/misc/Artistic.html).
Lingua::EN::Fathom was written by Kim Ryan <kimaryan@ozemail.com.au> in 2000.
|