public function getLemmas($word, $partOfSpeech = null) {
    if($partOfSpeech !== null && !isset(self::$partsOfSpeech[$partOfSpeech])) {
      $posAsString = implode(' or ', array_keys(self::$partsOfSpeech));
      throw new InvalidArgumentException("partsOfSpeech must be {$posAsString}.");
    }

    $wordEntity = new Word($word);
    if($partOfSpeech !== null) {
      $pos = $this->getPos($partOfSpeech);
      $lemmas = $this->getBaseForm($wordEntity, $pos);
      if(!$lemmas) {
        $lemmas[] = new Lemma($word, $partOfSpeech);
      }
    } else {
      $lemmas = [];
      /** @var PartOfSpeech $pos */
      foreach(self::$partsOfSpeech as $pos) {
        $lemmas = array_merge($lemmas, $this->getBaseForm($wordEntity, $pos));
      }

      if(!$lemmas) {
        /** @var PartOfSpeech $pos */
        foreach(self::$partsOfSpeech as $pos) {
          if(isset($pos->getWordsList()[$word])) {
            $lemmas[] = new Lemma($word, $pos->getPartOfSpeechAsString());
          }
        }
      }

      if(!$lemmas) {
        $lemmas[] = new Lemma($word);
      }
    }

    return array_unique($lemmas, SORT_REGULAR);
  }
public function getLemmas($word, $partOfSpeech = null) {
    if($partOfSpeech !== null && !isset(self::$partsOfSpeech[$partOfSpeech])) {
      $posAsString = implode(' or ', array_keys(self::$partsOfSpeech));
      throw new InvalidArgumentException("partsOfSpeech must be {$posAsString}.");
    }

    $wordEntity = new Word($word);
    if($partOfSpeech !== null) {
      $pos = $this->getPos($partOfSpeech);
      $lemmas = $this->getBaseForm($wordEntity, $pos);
      if(!$lemmas) {
        $lemmas[] = new Lemma($word, $partOfSpeech);
      }
    } else {
      $lemmas = [];
      /** @var PartOfSpeech $pos */
      foreach(self::$partsOfSpeech as $pos) {
        $lemmas = array_merge($lemmas, $this->getBaseForm($wordEntity, $pos));
      }

      if(!$lemmas) {
        /** @var PartOfSpeech $pos */
        foreach(self::$partsOfSpeech as $pos) {
          if(isset($pos->getWordsList()[$word])) {
            $lemmas[] = new Lemma($word, $pos->getPartOfSpeechAsString());
          }
        }
      }

      if(!$lemmas) {
        $lemmas[] = new Lemma($word);
      }
    }

    return array_unique($lemmas, SORT_REGULAR);
  }
public function getLemmas ( $ word , $ partOfSpeech = null ) { if ( $ partOfSpeech !== null && ! isset ( self :: $ partsOfSpeech [ $ partOfSpeech ] ) ) { $ posAsString = implode ( ' or ' , array_keys ( self :: $ partsOfSpeech ) ) ; throw new InvalidArgumentException ( "partsOfSpeech must be {$posAsString}." ) ; } $ wordEntity = new Word ( $ word ) ; if ( $ partOfSpeech !== null ) { $ pos = $ this -> getPos ( $ partOfSpeech ) ; $ lemmas = $ this -> getBaseForm ( $ wordEntity , $ pos ) ; if ( ! $ lemmas ) { $ lemmas [ ] = new Lemma ( $ word , $ partOfSpeech ) ; } } else { $ lemmas = [ ] ; /** @var PartOfSpeech $pos */ foreach ( self :: $ partsOfSpeech as $ pos ) { $ lemmas = array_merge ( $ lemmas , $ this -> getBaseForm ( $ wordEntity , $ pos ) ) ; } if ( ! $ lemmas ) { /** @var PartOfSpeech $pos */ foreach ( self :: $ partsOfSpeech as $ pos ) { if ( isset ( $ pos -> getWordsList ( ) [ $ word ] ) ) { $ lemmas [ ] = new Lemma ( $ word , $ pos -> getPartOfSpeechAsString ( ) ) ; } } } if ( ! $ lemmas ) { $ lemmas [ ] = new Lemma ( $ word ) ; } } return array_unique ( $ lemmas , SORT_REGULAR ) ; }
Lemmatize a word

@param string $word
@param string|null $partOfSpeech

@return Lemma[]
Lemmatize a word