Example #1
0
 /**
  * @param phpMorphy_Paradigm_MutableDecorator $paradigm
  * @return void
  */
 function apply(phpMorphy_Paradigm_MutableDecorator $paradigm)
 {
     list($forms, $indices) = $this->pattern_matcher->findSuitableFormsByPattern(array($paradigm), $this->pattern, false);
     foreach ($indices as $idx) {
         $paradigm->deleteWordForm($idx);
     }
     $paradigm->updateBases();
 }
Example #2
0
 /**
  * @param string $newLexem
  * @param phpMorphy_UserDict_Pattern $pattern
  * @param phpMorphy_UserDict_LogInterface $log
  * @return bool
  */
 function execute($newLexem, phpMorphy_UserDict_Pattern $pattern, phpMorphy_UserDict_LogInterface $log)
 {
     $paradigms = false;
     if (false === ($paradigms = $this->findWordMorphy($pattern->getWord()))) {
         if (false === ($paradigms = $this->findWordInternal($pattern->getWord()))) {
             $log->errorPatternNotFound($pattern);
             return false;
         }
     }
     try {
         if (false === ($form = $this->findSuitableFormByPattern($paradigms, $pattern))) {
             $log->errorPatternNotFound($pattern);
             return false;
         }
     } catch (phpMorphy_UserDict_PatternMatcher_AmbiguityException $e) {
         $log->errorAmbiguity($e->getPattern(), $e->getSuitableForms());
         return false;
     }
     $common_prefix = '';
     if (self::USE_COMMON_PREFIXES_FOR_NEW_LEMMA) {
         $common_prefix = $this->getCommonPrefixByTemplateWord($newLexem, $form);
     }
     if (false === ($base = $this->getBaseStringByTemplateWord($newLexem, $form, $common_prefix))) {
         $pattern_word = $pattern->getWord();
         $log->errorCantDeduceForm($pattern_word);
         return false;
     }
     $paradigm = new phpMorphy_Paradigm_MutableDecorator($form->getParadigm());
     $paradigm->setRetrieveAllObjectsAsMutable(true);
     foreach ($paradigm as $wf) {
         $wf->setBase($base);
         $wf->setCommonPrefix($common_prefix . $wf->getCommonPrefix());
     }
     $this->appendParadigmRecursive($paradigm);
     return true;
 }