Tham khảo tài liệu 'advanced php programming- p5', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 178 Chapter 6 Unit Testing this- numSentences 2 this- numWords 16 this- numSyllables 24 this- object new Text_Statistics this- sample function _construct name parent construct name Sure enough the bug is there. Mr. matches as the end of a can try to avoid this problem by removing the periods from common do this you need to add a list of common abbreviations and expansions that strip the abbreviations of their make this a static attribute of Text_Statistics and then substitute on that list during analyze_line. Here s the code for this class Text_Statistics . static abbreviations array 1 Mr . 1 1 Mr1 1 Mrs . i1 1 Mrs1 1 etc . i1 1 etc1 Dr . i lDrl . protected function analyze_line line replace our known abbreviations line preg_replace array_keys self abbreviations array_values self abbreviations line preg_match_all 11 b w wi - b 11 line words foreach words 1 as word word strtolower word w_obj new Text_Word word this- numSyllables w_obj- numSyllables this- numWords if isset this- _uniques word this- _uniques word 1 else this- uniqWords preg_match_all 11 . 11 line matches this- numSentences count matches 0 Unit Testing in a Web Environment 179 The sentence count is correct now but now the syllable count is off. It seems that Mr. counts as only one syllable because it has no vowels . To handle this you can expand the abbreviation expansion list to not only eliminate punctuation but also to expand the abbreviations for the purposes of counting syllables. Here s the code that does this class Text_Statistics . static abbreviations array 1 Mr . 1 Mister Mrs . i Misses Phonetic etc . i etcetera Dr . i Doctor . There are still many improvements you can make to the Text_Statistics routine. The silentSyllable and additionalSyllable arrays for tracking exceptional cases are a good start but there is still much work to do. Similarly the abbreviations list is pretty limited at this point and could easily be expanded as well. .