original_string: 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);
    }
code: 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);
    }
code_tokens: 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 ) ; }
docstring: Lemmatize a word
  
  @param string $word
  @param string|null $partOfSpeech
  
  @return Lemma[]
docstring_tokens: Lemmatize a word