/**
  * @param phpMorphy_Paradigm_ParadigmInterface[] $paradigmsCollection
  * @param phpMorphy_UserDict_Pattern $pattern
  * @param bool $isMatchOnlyLemmas
  * @return array(0 => phpMorphy_WordForm_WordFormAbstract[], 1 => int[])
  */
 function findSuitableFormsByPattern($paradigmsCollection, phpMorphy_UserDict_Pattern $pattern, $isMatchOnlyLemmas)
 {
     $result = array();
     $forms_idx = array();
     foreach ($paradigmsCollection as $paradigm) {
         if ($isMatchOnlyLemmas) {
             $lemma = $paradigm->getLemma();
             if ($pattern->matchWord($lemma)) {
                 $word_form = $paradigm->getWordForm(0);
                 $match_result = $pattern->match($word_form->getWord(), $word_form->getPartOfSpeech(), $word_form->getGrammems());
                 if ($match_result) {
                     $result[] = $word_form;
                     $forms_idx[] = 0;
                 }
             }
         } else {
             $form_no = 0;
             foreach ($paradigm as $word_form) {
                 $match_result = $pattern->match($word_form->getWord(), $word_form->getPartOfSpeech(), $word_form->getGrammems());
                 if ($match_result) {
                     $result[] = $word_form;
                     $forms_idx[] = $form_no;
                 }
                 $form_no++;
             }
         }
     }
     return array($result, $forms_idx);
 }
Esempio n. 2
0
 /**
  * @param phpMorphy_UserDict_Pattern $pattern
  * @return bool
  */
 protected function deleteLexemInternal(phpMorphy_UserDict_Pattern $pattern, phpMorphy_UserDict_LogInterface $log)
 {
     $para_indeces = null;
     if (false === ($paradigms = $this->findWordInternal($pattern->getWord(), $para_indeces))) {
         return false;
     }
     $form_index = null;
     try {
         if (false === ($form = $this->findSuitableFormByPattern($paradigms, $pattern, $form_index))) {
             return false;
         }
     } catch (phpMorphy_UserDict_PatternMatcher_AmbiguityException $e) {
         $log->errorAmbiguity($e->getPattern(), $e->getSuitableForms());
         return false;
     }
     $this->paradigms_container->delete($para_indeces[$form_index]);
     return true;
 }
Esempio n. 3
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;
 }
 /**
  * @todo Implement testMatch().
  */
 public function testMatch()
 {
     $this->assertTrue($this->object->match('test', 'pos', array('a', 'c', 'b')));
 }