| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use \Mystem\Word; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use \Mystem\MystemConst; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | class WordTest extends \PHPUnit_Framework_TestCase { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     public function testStemm() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |         $word = Word::stemm('самолетами'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         $this->assertEquals('самолет', $word->normalized()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     public function testFromLexicalString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $lex = 'самолетами{самолет=S,муж,неод=твор,мн}'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $word = Word::stemm($lex); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $this->assertEquals('самолет', $word->normalized()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public function testCantNormalize() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->assertEmpty(Word::stemm('asfd')->normalized()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public function testToString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $this->assertEquals('самолет', (string)Word::stemm('самолетами')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function testPredict() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->assertEquals('варкаться', Word::stemm('варкалось')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public static function providerVerbTime() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             array('летел', MystemConst::PAST), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             array('полетит', MystemConst::FUTURE), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @dataProvider providerVerbTime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @param string $verb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @param string $time | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function testVerbTime($verb, $time) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->assertEquals($time, Word::stemm($verb)->getVerbTime()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public static function providerCount() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             array('ёжик', MystemConst::SINGULAR), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             array('ёжики', MystemConst::PLURAL), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             array('бегал', MystemConst::SINGULAR), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             array('бежали', MystemConst::PLURAL), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @dataProvider providerCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @param string $noun | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @param string $count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     public function testCount($noun, $count) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->assertEquals($count, Word::stemm($noun)->getCount()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     public static function providerGender() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             array('котейка', MystemConst::FEMININE), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             array('каравай', MystemConst::MASCULINE), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             array('ведро', MystemConst::NEUTER), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @dataProvider providerGender | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @param string $noun | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @param string $gender | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 87 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |     public function testGender($noun, $gender) | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |         $this->assertEquals($gender, Word::stemm($noun)->getGender()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     public static function providerAnimate() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             array('поросенок', MystemConst::ANIMATE), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             array('стул', MystemConst::INANIMATE), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @dataProvider providerAnimate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * @param string $noun | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * @param string $animate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     public function testAnimate($noun, $animate) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $this->assertEquals($animate, Word::stemm($noun)->getAnimate()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     public static function providerNounCase() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             array('прокурор', MystemConst::NOMINATIVE), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |             array('прокуроров', MystemConst::ACCUSATIVE), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             array('прокурорам', MystemConst::DATIVE), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             array('прокурором', MystemConst::INSTRUMENTAL), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             array('прокуроре', MystemConst::PREPOSITIONAL), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      * @dataProvider providerNounCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * @param string $noun | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * @param string $case | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     public function testNounCase($noun, $case) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $this->assertEquals($case, Word::stemm($noun)->getNounCase()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     public function testUndefinedGrammeme() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         $this->assertNull(Word::stemm('летел')->getNounCase()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     public function testCheckGrammeme() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $word = Word::stemm('банка'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $this->assertTrue($word->checkGrammeme(MystemConst::FEMININE)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $this->assertTrue($word->checkGrammeme(MystemConst::MASCULINE)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $this->assertFalse($word->checkGrammeme(MystemConst::FEMININE, 1)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     public function testNoVariantsWord() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         $word = Word::stemm('ololo'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         $this->assertFalse($word->checkGrammeme(MystemConst::DATIVE)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $this->assertNull($word->getNounCase(1)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 152 |  |  | } |