TextAnalysisLibTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. App::uses('TextAnalysisLib', 'Tools.Utility');
  3. /**
  4. */
  5. class TextAnalysisLibTest extends CakeTestCase {
  6. public $TextAnalysis;
  7. public function setUp() {
  8. parent::setUp();
  9. $this->TextAnalysis = new TextAnalysisLib();
  10. }
  11. public function testIsScreamFont() {
  12. $strings = [
  13. 'Some Äext' => false,
  14. 'SOME ÄEXT' => true,
  15. 'ST' => true,
  16. 'SOme TExt' => true,
  17. 'SOme Text' => false,
  18. ];
  19. foreach ($strings as $string => $expected) {
  20. $this->TextAnalysis = new TextAnalysisLib($string);
  21. $is = $this->TextAnalysis->isScreamFont();
  22. //pr($is);
  23. $this->assertSame($expected, $is);
  24. }
  25. }
  26. public function testWordCount() {
  27. $this->TextAnalysis = new TextAnalysisLib('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.');
  28. $is = $this->TextAnalysis->wordCount(['min_char' => 3]);
  29. //pr($is);
  30. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 9);
  31. $this->TextAnalysis = new TextAnalysisLib('Hochhaus, Unter dem Bau von ae Äußeren Einflüssen - und von Autos.');
  32. $is = $this->TextAnalysis->wordCount(['min_char' => 3, 'sort' => 'DESC', 'limit' => 5]);
  33. //pr($is);
  34. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 5);
  35. }
  36. /** Start **/
  37. public function testOccurances() {
  38. $this->TextAnalysis = new TextAnalysisLib('Hochhaus');
  39. $is = $this->TextAnalysis->occurrences();
  40. //pr($is);
  41. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 6);
  42. $is = $this->TextAnalysis->occurrences(null, true);
  43. //pr($is);
  44. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 7);
  45. $is = $this->TextAnalysis->occurrences('h');
  46. //pr($is);
  47. $expected = 3;
  48. $this->assertEquals($expected, $is);
  49. $is = $this->TextAnalysis->occurrences('h', true);
  50. //pr($is);
  51. $expected = 2;
  52. $this->assertEquals($expected, $is);
  53. }
  54. public function testMaxOccurances() {
  55. $is = $this->TextAnalysis->maxOccurrences();
  56. //pr($is);
  57. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 1);
  58. $this->TextAnalysis = new TextAnalysisLib('Radfahren');
  59. $is = $this->TextAnalysis->maxOccurrences();
  60. //pr($is);
  61. $this->assertTrue(!empty($is) && is_array($is) && count($is) === 2);
  62. }
  63. //TODO: rest of the test functions
  64. /*
  65. //give it the text
  66. $text = new TextParse(
  67. "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.
  68. 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."
  69. );
  70. echo "Lenght:". $text->getLenght() ."\n"; //the Lenght
  71. echo "Character:". $text->getCharacter() ."\n"; //Character count
  72. echo "Letter:". $text->getLetter() ."\n"; //Letter count
  73. echo "Space:". $text->getSpace() ."\n"; //Space count
  74. echo "Symbol:". $text->getSymbol() ."\n"; //Symbol count(non letter / space / \n / \r)
  75. echo "Word:". $text->getWord() ."\n"; //Word count
  76. echo "The Words:";
  77. print_r($text->getWord(1)); //the Words
  78. echo "\n";
  79. echo "Sentence:". $text->getSentence() ."\n"; //Sentence count
  80. echo "The Sentences:";
  81. print_r($text->getSentence(1)); //the Sentences
  82. echo "\n";
  83. echo "Paragraph:". $text->getParagraph() ."\n"; //Paragraph count
  84. echo "The Paragraphs:";
  85. print_r($text->getParagraph(1)); //the Paragraphs
  86. echo "\n";
  87. echo "Beautified Text:\n". $text->beautify(80); //beautify the text, wordwrap=80
  88. */
  89. }