public function getMorph($word, $pos = '')
    {
        if(mb_strlen($word) < 3) {
            return "";
        }
        
        $searchForFuncWithPos = function(ExceptionMap $exceptionMap) use($word, $pos)
        {
            return $exceptionMap->getPos() === $pos && in_array($word, $exceptionMap->getExceptionList());
        };
        
        $searchForFuncWithoutPos = function(ExceptionMap $exceptionMap) use($word)
        {
            return in_array($word, $exceptionMap->getExceptionList());
        };        

        $found = [];
        
        
        if(!empty($pos)) {
            $found = array_filter($this->getWordnetCorpus()->getExceptionsMap(), $searchForFuncWithPos);
        } else {
            $found = array_filter($this->getWordnetCorpus()->getExceptionsMap(), $searchForFuncWithoutPos);
        }
        
        // found a match in the exceptions data
        if(!empty($found)) { 
            return array_values($found)[0]->getTarget();
        }
        
        foreach($this->getMorphilogicalSubstitutions() as $keyPos => $keyValues)
        {            
            foreach($keyValues as $key => $value) 
            {
                if(Text::endsWith($word, $key)) {   
                    $morphedWord = substr($word, 0, -strlen($key)).$value;
                    $r = $this->getLemma($morphedWord, $keyPos);
                    if(!empty($r)) { 
                        $found += array_map(function($lemma){ return $lemma->getWord();}, $r);
                        return $found[0];
                    }
                }
            }
        }
        if(empty($found)) {
            return "";
        }
        
        return $found[0];
    }
public function getMorph($word, $pos = '')
    {
        if(mb_strlen($word) < 3) {
            return "";
        }
        
        $searchForFuncWithPos = function(ExceptionMap $exceptionMap) use($word, $pos)
        {
            return $exceptionMap->getPos() === $pos && in_array($word, $exceptionMap->getExceptionList());
        };
        
        $searchForFuncWithoutPos = function(ExceptionMap $exceptionMap) use($word)
        {
            return in_array($word, $exceptionMap->getExceptionList());
        };        

        $found = [];
        
        
        if(!empty($pos)) {
            $found = array_filter($this->getWordnetCorpus()->getExceptionsMap(), $searchForFuncWithPos);
        } else {
            $found = array_filter($this->getWordnetCorpus()->getExceptionsMap(), $searchForFuncWithoutPos);
        }
        
        // found a match in the exceptions data
        if(!empty($found)) { 
            return array_values($found)[0]->getTarget();
        }
        
        foreach($this->getMorphilogicalSubstitutions() as $keyPos => $keyValues)
        {            
            foreach($keyValues as $key => $value) 
            {
                if(Text::endsWith($word, $key)) {   
                    $morphedWord = substr($word, 0, -strlen($key)).$value;
                    $r = $this->getLemma($morphedWord, $keyPos);
                    if(!empty($r)) { 
                        $found += array_map(function($lemma){ return $lemma->getWord();}, $r);
                        return $found[0];
                    }
                }
            }
        }
        if(empty($found)) {
            return "";
        }
        
        return $found[0];
    }
public function getMorph ( $ word , $ pos = '' ) { if ( mb_strlen ( $ word ) < 3 ) { return "" ; } $ searchForFuncWithPos = function ( ExceptionMap $ exceptionMap ) use ( $ word , $ pos ) { return $ exceptionMap -> getPos ( ) === $ pos && in_array ( $ word , $ exceptionMap -> getExceptionList ( ) ) ; } ; $ searchForFuncWithoutPos = function ( ExceptionMap $ exceptionMap ) use ( $ word ) { return in_array ( $ word , $ exceptionMap -> getExceptionList ( ) ) ; } ; $ found = [ ] ; if ( ! empty ( $ pos ) ) { $ found = array_filter ( $ this -> getWordnetCorpus ( ) -> getExceptionsMap ( ) , $ searchForFuncWithPos ) ; } else { $ found = array_filter ( $ this -> getWordnetCorpus ( ) -> getExceptionsMap ( ) , $ searchForFuncWithoutPos ) ; } // found a match in the exceptions data if ( ! empty ( $ found ) ) { return array_values ( $ found ) [ 0 ] -> getTarget ( ) ; } foreach ( $ this -> getMorphilogicalSubstitutions ( ) as $ keyPos => $ keyValues ) { foreach ( $ keyValues as $ key => $ value ) { if ( Text :: endsWith ( $ word , $ key ) ) { $ morphedWord = substr ( $ word , 0 , - strlen ( $ key ) ) . $ value ; $ r = $ this -> getLemma ( $ morphedWord , $ keyPos ) ; if ( ! empty ( $ r ) ) { $ found += array_map ( function ( $ lemma ) { return $ lemma -> getWord ( ) ; } , $ r ) ; return $ found [ 0 ] ; } } } } if ( empty ( $ found ) ) { return "" ; } return $ found [ 0 ] ; }
Concept taken from nltk
Find a possible base form for the given form, with the given
part of speech, by checking WordNet's list of exceptional
forms, and by recursively stripping affixes for this part of
speech until a form in WordNet is found.
@todo improve the algorithm, it is really slow
@param string $word
@param string|null $pos
@return string return the base word
Concept taken from nltk Find a possible base form for the given form with the given part of speech by checking WordNet s list of exceptional forms and by recursively stripping affixes for this part of speech until a form in WordNet is found .