Example #1
0
 function clear()
 {
     parent::clear();
     $this->collected = 0;
     $this->used_poses = array();
 }
 /**
  * @return bool
  */
 function isInUpperCase()
 {
     $actual_result = $this->getCommonMorphier()->getHelper()->getGraminfo()->isInUpperCase();
     if (null !== $actual_result) {
         return $actual_result;
     }
     $fsa = $this->getCommonMorphier()->getFinder()->getFsa();
     $collector = new phpMorphy_Fsa_WordsCollector(10);
     $fsa->collect($fsa->getRootTrans(), $collector->getCallback(), false);
     $words = array_keys($collector->getItems());
     if (!count($words)) {
         throw new phpMorphy_Exception("Can`t find first word");
     }
     if (!extension_loaded('mbstring')) {
         throw new phpMorphy_Exception("phpMorphy::isInUpperCase requires mb_string extension");
     }
     $encoding = $this->getEncoding();
     $lower_count = 1;
     $upper_count = 1;
     $mix_count = 1;
     foreach ($words as $word) {
         if (mb_convert_case($word, MB_CASE_UPPER, $encoding) === $word) {
             $upper_count++;
         } else {
             if (mb_convert_case($word, MB_CASE_LOWER, $encoding) === $word) {
                 $lower_count++;
             } else {
                 $mix_count++;
             }
         }
     }
     // TODO: that ugly
     return $upper_count / $lower_count > 2;
 }