TextAnalysisLibTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. App::uses('TextAnalysisLib', 'Tools.Utility');
  3. /**
  4. * 2010-07-14 ms
  5. */
  6. class TextAnalysisLibTest extends CakeTestCase {
  7. public $TextAnalysis;
  8. public function setUp() {
  9. parent::setUp();
  10. $this->TextAnalysis = new TextAnalysisLib();
  11. }
  12. public function testIsScreamFont() {
  13. $strings = array(
  14. 'Some Äext' => false,
  15. 'SOME ÄEXT' => true,
  16. 'ST' => true,
  17. 'SOme TExt' => true,
  18. 'SOme Text' => false,
  19. );
  20. foreach ($strings as $string => $expected) {
  21. $this->TextAnalysis = new TextAnalysisLib($string);
  22. $is = $this->TextAnalysis->isScreamFont();
  23. //pr($is);
  24. $this->assertSame($expected, $is);
  25. }
  26. }
  27. public function testWordCount() {
  28. $this->TextAnalysis = new TextAnalysisLib('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.');
  29. $is = $this->TextAnalysis->wordCount(array('min_char'=>3));
  30. //pr($is);
  31. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 9);
  32. $this->TextAnalysis = new TextAnalysisLib('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.');
  33. $is = $this->TextAnalysis->wordCount(array('min_char'=>3, 'sort'=>'DESC', 'limit'=>5));
  34. //pr($is);
  35. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 5);
  36. }
  37. /** Start **/
  38. public function testOccurances() {
  39. $this->TextAnalysis = new TextAnalysisLib('Hochhaus');
  40. $is = $this->TextAnalysis->occurrences();
  41. //pr($is);
  42. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 6);
  43. $is = $this->TextAnalysis->occurrences(null, true);
  44. //pr($is);
  45. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 7);
  46. $is = $this->TextAnalysis->occurrences('h');
  47. //pr($is);
  48. $expected = 3;
  49. $this->assertEquals($is, $expected);
  50. $is = $this->TextAnalysis->occurrences('h', true);
  51. //pr($is);
  52. $expected = 2;
  53. $this->assertEquals($is, $expected);
  54. }
  55. public function testMaxOccurances() {
  56. $is = $this->TextAnalysis->maxOccurrences();
  57. //pr($is);
  58. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 1);
  59. $this->TextAnalysis = new TextAnalysisLib('Radfahren');
  60. $is = $this->TextAnalysis->maxOccurrences();
  61. //pr($is);
  62. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 2);
  63. }
  64. //TODO: rest of the test functions
  65. /*
  66. //give it the text
  67. $text = new TextParse(
  68. "PHP:Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages... .. .. For this purpose,PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document.
  69. As a general-purpose programming language, PHP code(PHP CODE)is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel.It may also function as a graphical application...... PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms."
  70. );
  71. echo "Lenght:". $text->getLenght() ."\n"; //the Lenght
  72. echo "Character:". $text->getCharacter() ."\n"; //Character count
  73. echo "Letter:". $text->getLetter() ."\n"; //Letter count
  74. echo "Space:". $text->getSpace() ."\n"; //Space count
  75. echo "Symbol:". $text->getSymbol() ."\n"; //Symbol count(non letter / space / \n / \r)
  76. echo "Word:". $text->getWord() ."\n"; //Word count
  77. echo "The Words:";
  78. print_r($text->getWord(1)); //the Words
  79. echo "\n";
  80. echo "Sentence:". $text->getSentence() ."\n"; //Sentence count
  81. echo "The Sentences:";
  82. print_r($text->getSentence(1)); //the Sentences
  83. echo "\n";
  84. echo "Paragraph:". $text->getParagraph() ."\n"; //Paragraph count
  85. echo "The Paragraphs:";
  86. print_r($text->getParagraph(1)); //the Paragraphs
  87. echo "\n";
  88. echo "Beautified Text:\n". $text->beautify(80); //beautify the text, wordwrap=80
  89. */
  90. }