lib/natural/stemmers/lancaster_stemmer.js
function applyRuleSection(token, intact) {
    var section = token.substr( - 1);
    var rules = ruleTable[section];

    if (rules) {
        for (var i = 0; i < rules.length; i++) {
            if ((intact || !rules[i].intact)
            // only apply intact rules to intact tokens
            && token.substr(0 - rules[i].pattern.length) == rules[i].pattern) {
                // hack off only as much as the rule indicates
                var result = token.substr(0, token.length - rules[i].size);

                // if the rules wants us to apply an appendage do so
                if (rules[i].appendage)
                    result += rules[i].appendage;

                if (acceptable(result)) {
                    token = result;

                    // see what the rules wants to do next
                    if (rules[i].continuation) {
                        // this rule thinks there still might be stem left. keep at it.
                        // since we've applied a change we'll pass false in for intact
                        return applyRuleSection(result, false);
                    } else {
                        // the rule thinks we're done stemming. drop out.
                        return result;
                    }
                }
            }
        }
    }

    return token;
}
function applyRuleSection(token, intact) {
    var section = token.substr( - 1);
    var rules = ruleTable[section];

    if (rules) {
        for (var i = 0; i < rules.length; i++) {
            if ((intact || !rules[i].intact)
            // only apply intact rules to intact tokens
            && token.substr(0 - rules[i].pattern.length) == rules[i].pattern) {
                // hack off only as much as the rule indicates
                var result = token.substr(0, token.length - rules[i].size);

                // if the rules wants us to apply an appendage do so
                if (rules[i].appendage)
                    result += rules[i].appendage;

                if (acceptable(result)) {
                    token = result;

                    // see what the rules wants to do next
                    if (rules[i].continuation) {
                        // this rule thinks there still might be stem left. keep at it.
                        // since we've applied a change we'll pass false in for intact
                        return applyRuleSection(result, false);
                    } else {
                        // the rule thinks we're done stemming. drop out.
                        return result;
                    }
                }
            }
        }
    }

    return token;
}
function applyRuleSection ( token , intact ) { var section = token . substr ( - 1 ) ; var rules = ruleTable [ section ] ; if ( rules ) { for ( var i = 0 ; i < rules . length ; i ++ ) { if ( ( intact || ! rules [ i ] . intact ) // only apply intact rules to intact tokens && token . substr ( 0 - rules [ i ] . pattern . length ) == rules [ i ] . pattern ) { // hack off only as much as the rule indicates var result = token . substr ( 0 , token . length - rules [ i ] . size ) ; // if the rules wants us to apply an appendage do so if ( rules [ i ] . appendage ) result += rules [ i ] . appendage ; if ( acceptable ( result ) ) { token = result ; // see what the rules wants to do next if ( rules [ i ] . continuation ) { // this rule thinks there still might be stem left. keep at it. // since we've applied a change we'll pass false in for intact return applyRuleSection ( result , false ) ; } else { // the rule thinks we're done stemming. drop out. return result ; } } } } } return token ; }
take a token, look up the applicatble rule section and attempt some stemming!
take a token look up the applicatble rule section and attempt some stemming!