public function stem($word)
    {
        if(empty(trim($word))) { 
            return null;
        }
        
        $this->originalToken = $word;
        
        //only iterate out loop if a rule is applied        
        do {
            $ruleApplied = false;
            $lookupChar = $word[strlen($word)-1];

            //check that the last character is in the index, if not return the origin token
            if(!array_key_exists($lookupChar, $this->indexedRules)){
                return $word;
            }
            foreach($this->indexedRules[$lookupChar] as $rule)
            {
                if(strrpos($word, substr($rule[self::ENDING_STRING],-1)) === 
                        (strlen($word)-strlen($rule[self::ENDING_STRING]))){

                    
                    if(!empty($rule[self::INTACT_FLAG])){ 
                        
                        if($this->originalToken == $word && 
                            $this->isAcceptable($word, (int)$rule[self::REMOVE_TOTAL])){

                            $word = $this->applyRule($word, $rule);
                            $ruleApplied = true;
                            if($rule[self::CONTINUE_FLAG] === '.'){
                                return $word;
                            } 
                            break;
                        }
                    } elseif($this->isAcceptable($word, (int)$rule[self::REMOVE_TOTAL])){
                        $word = $this->applyRule($word, $rule);
                        $ruleApplied = true;
                        if($rule[self::CONTINUE_FLAG] === '.'){
                            return $word;
                        }
                        break;
                    }
                } else {
                    $ruleApplied = false;
                }
            }
        } while($ruleApplied);
        
        return $word;
                        
    }
public function stem($word)
    {
        if(empty(trim($word))) { 
            return null;
        }
        
        $this->originalToken = $word;
        
        //only iterate out loop if a rule is applied        
        do {
            $ruleApplied = false;
            $lookupChar = $word[strlen($word)-1];

            //check that the last character is in the index, if not return the origin token
            if(!array_key_exists($lookupChar, $this->indexedRules)){
                return $word;
            }
            foreach($this->indexedRules[$lookupChar] as $rule)
            {
                if(strrpos($word, substr($rule[self::ENDING_STRING],-1)) === 
                        (strlen($word)-strlen($rule[self::ENDING_STRING]))){

                    
                    if(!empty($rule[self::INTACT_FLAG])){ 
                        
                        if($this->originalToken == $word && 
                            $this->isAcceptable($word, (int)$rule[self::REMOVE_TOTAL])){

                            $word = $this->applyRule($word, $rule);
                            $ruleApplied = true;
                            if($rule[self::CONTINUE_FLAG] === '.'){
                                return $word;
                            } 
                            break;
                        }
                    } elseif($this->isAcceptable($word, (int)$rule[self::REMOVE_TOTAL])){
                        $word = $this->applyRule($word, $rule);
                        $ruleApplied = true;
                        if($rule[self::CONTINUE_FLAG] === '.'){
                            return $word;
                        }
                        break;
                    }
                } else {
                    $ruleApplied = false;
                }
            }
        } while($ruleApplied);
        
        return $word;
                        
    }
public function stem ( $ word ) { if ( empty ( trim ( $ word ) ) ) { return null ; } $ this -> originalToken = $ word ; //only iterate out loop if a rule is applied         do { $ ruleApplied = false ; $ lookupChar = $ word [ strlen ( $ word ) - 1 ] ; //check that the last character is in the index, if not return the origin token if ( ! array_key_exists ( $ lookupChar , $ this -> indexedRules ) ) { return $ word ; } foreach ( $ this -> indexedRules [ $ lookupChar ] as $ rule ) { if ( strrpos ( $ word , substr ( $ rule [ self :: ENDING_STRING ] , - 1 ) ) === ( strlen ( $ word ) - strlen ( $ rule [ self :: ENDING_STRING ] ) ) ) { if ( ! empty ( $ rule [ self :: INTACT_FLAG ] ) ) { if ( $ this -> originalToken == $ word && $ this -> isAcceptable ( $ word , ( int ) $ rule [ self :: REMOVE_TOTAL ] ) ) { $ word = $ this -> applyRule ( $ word , $ rule ) ; $ ruleApplied = true ; if ( $ rule [ self :: CONTINUE_FLAG ] === '.' ) { return $ word ; } break ; } } elseif ( $ this -> isAcceptable ( $ word , ( int ) $ rule [ self :: REMOVE_TOTAL ] ) ) { $ word = $ this -> applyRule ( $ word , $ rule ) ; $ ruleApplied = true ; if ( $ rule [ self :: CONTINUE_FLAG ] === '.' ) { return $ word ; } break ; } } else { $ ruleApplied = false ; } } } while ( $ ruleApplied ) ; return $ word ; }
Performs a Lancaster stem on the giving word
@param string $word The word that gets stemmed
@return string|null The stemmed word
Performs a Lancaster stem on the giving word