PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Text » Text_Statistics » Bug #4491

Add grade level

Details

Request #4491Add grade level
Submitted2005-05-31 19:56 UTC
Frommjohnson at pitsco dot com
Assignedcweiske
StatusClosed
PackageText_Statistics
PHP VersionIrrelevant
OSNA
Roadmaps(Not assigned)

Comments

[2005-05-31 19:56 UTC] mjohnson at pitsco dot com

Description:
------------
Add Flesch-Kincaid grade level. This is calculated with the formula:

(0.39 x the average number of words per sentence) + (11.8 x the average number of syllables per word) - 15.59

I've included code in the reproduce code that modifies the _analyze function. I don't have a site I can put it on easily, otherwise I'd post the whole change (which includes the addition of a $gradeLevel variable)

Reproduce code:
---------------
function _analyze()
{
$lines = explode("\n", $this->text);
foreach( $lines as $line ) {
$this->_analyze_line($line);
}
$nSentences = $this->numSentences;
if (empty($nSentences)) {
$nSentences = 1;
}
$nWords = $this->numWords;
if (empty($nWords)) {
$nWords = 1;
}

$wordsPerSent = $nWords / $nSentences;
$syllablesPerWord = $this->numSyllables/$nWords;
$this->flesch = 206.835 - 1.015 * $wordsPerSent - 84.6 * $syllablesPerWord;
$this->gradeLevel = 0.39 * $wordsPerSent + 11.8 * $syllablesPerWord - 15.59;
}