Patch for PEAR::Text_Statistics

From: Date: Wed, 05 Feb 2003 01:42:24 +0000
Subject: Patch for PEAR::Text_Statistics
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-12976@lists.php.net to get a copy of this message
Made some quick additions to the Text/Statitistics.php file. Here is the "diff -u" output (some code for testing after that): --- Statistics.php-orig Tue Feb 4 17:00:38 2003 +++ Statistics.php Tue Feb 4 17:28:19 2003 @@ -106,10 +106,12 @@ * @var number * @access protected */ - var $_abbreviations = array('/Mr\./' => 'Misterr', + var $_abbreviations = array('/Mr\./' => 'Mister', '/Mrs\./i' => 'Misses', // Phonetic '/etc\./i' => 'etcetera', '/Dr\./i' => 'Doctor', + '/Jr\./i' => 'Junior', + '/Sr\./i' => 'Senior', ); /** @@ -125,12 +127,45 @@ } /** + * Returns the character frequencies. + * + * @return array of frequencies, where the index is the ASCII byte char value + * @access public + * @author Jesus M. Castagnetto <jmcastagnetto@php.net> + */ + function getCharFreq() { + return $this->_charFreq; + } + + /** + * Returns the number of paragaphs. + * Paragraphs are defined as chunks of text separated by + * and empty line. + * + * @return long + * @access public + * @author Jesus M. Castagnetto <jmcastagnetto@php.net> + */ + function getNumParagraphs() { + return $this->_numParas; + } + + /** * Compute statistics for the document object. * * @access protected */ function _analyze() { + // JMC changes + // char frequencies + $this->_charFreq = count_chars($this->text); + // paragraphs are defined as chunks of text separated by + // and empty line + $para_re = '/\n\s*\n/m'; + $this->_paras = preg_split($para_re, $this->text); + $this->_numParas = count($this->_paras); + // end of JMC changes $lines = explode("\n", $this->text); foreach( $lines as $line ) { $this->_analyze_line($line); @@ -165,4 +200,4 @@ $this->numSentences += count($matches[0]); } } -?> \ No newline at end of file +?> [jmc_test.php] <?php require_once 'Text/Statistics.php'; $text = "This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs. This is a simple text. With some paragraphs."; $stats = new Text_Statistics($text); print_r($stats); ?> ===== --- Jesus M. Castagnetto (jcastagnetto@yahoo.com) Research: http://metallo.scripps.edu/ Personal: http://www.castagnetto.org/ __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com

« previous php.pear.dev (#12976) next »