Source for file Statistics.php
Documentation is available at Statistics.php
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: George Schlossnagle <george@omniti.com> |
// +----------------------------------------------------------------------+
// $Id: Statistics.php 251907 2008-02-01 06:52:59Z cweiske $
require_once "Text/Word.php";
* Text_Statistics calculates some basic readability metrics on a
* block of text. The number of words, the number of sentences,
* and the number of total syllables is counted. These statistics
* can be used to calculate the Flesch score for a sentence, which
* is a number (usually between 0 and 100) that represents the
* readability of the text. A basic breakdown of scores is:
* 60 to 70 8th and 9th grade
* 50 to 60 10th to 12th grade (high school)
* 0 to 30 college graduate
* More info can be read up on at
* http://www.mang.canterbury.ac.nz/courseinfo/AcademicWriting/Flesch.htm
* require 'Text/Statistics.php';
* $block = Text_Statistics($sometext);
* $block->flesch; // returns flesch score for $sometext
* see the unit tests for additional examples.
* @package Text_Statistics
* @author George Schlossnagle <george@omniti.com>
* The number of syllables in the document.
* The number of words in the document.
* The number of unique words in the document.
* The number of sentences in the document.
* The Flesch score of the document.
* It is FALSE if there were no words in the document.
* Flesch-Kincaid grade level
* It is FALSE if there were no words in the document.
* Some abbreviations we should expand. This list could/should
'/Mrs\./i' => 'Misses', // Phonetic
'/etc\./i' => 'etcetera',
* List of all words that have been found already.
* Returns the character frequencies.
* @return array of frequencies, where the index is the ASCII byte char value
* @author Jesus M. Castagnetto <jmcastagnetto@php.net>
* Returns the number of paragaphs.
* Paragraphs are defined as chunks of text separated by
* @author Jesus M. Castagnetto <jmcastagnetto@php.net>
* Compute statistics for the document object.
// Set ourselves as 'out of text block to start
foreach( $lines as $line ) {
// A paragraph is when we enter a text line
// after a line that was all whitespace
- 84.6 * $syllablesPerWord;
+ 11.8 * $syllablesPerWord
* Helper function, computes statistics on a given line.
// expand abbreviations for counting syllables
foreach( $words[1 ] as $word ) {
if(!isset ($this->_uniques[$word])) {
$this->_uniques[$word] = 1;
Documentation generated on Mon, 11 Mar 2019 15:36:08 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|