public void PerformStep6(TokenSource source) { switch (source.LastChar) { case 'e': var a = source.NumberOfConsoantSequences(source.Size - 1); if (a > 1 || a == 1 && !source.HasCvcAt(source.Size - 2)) { source.Size--; } break; case 'l' when source.ContainsDoubleConsonantAt(source.Size - 1) && source.NumberOfConsoantSequences(source.Size - 2) > 0: source.Size--; break; } }
/* gets rid of plurals and -ed or -ing. e.g. * caresses -> caress * ponies -> poni * ties -> ti * caress -> caress * cats -> cat * * feed -> feed * agreed -> agree * disabled -> disable * * matting -> mat * mating -> mate * meeting -> meet * milling -> mill * messing -> mess * * meetings -> meet * */ public void PerformStep1(TokenSource source) { if (source.EndsWith('s')) { if (source.EndsWith("sses") || source.EndsWith("ies")) { source.Size -= 2; } else if (source.Size >= 2 && source.Buffer[source.Size - 2] != 's') { source.Size -= 1; } } if (source.EndsWith("eed")) { var limit = source.Size - 3; // source.Length if (source.NumberOfConsoantSequences(limit) > 0) { source.Size -= 1; } } else { var limit = 0; if (source.EndsWith("ed")) { limit = source.Size - 2; } else if (source.EndsWith("ing")) { limit = source.Size - 3; } if (limit != 0 && source.ContainsVowel(limit)) { source.Size = limit; if ( source.EndsWith("at") || source.EndsWith("bl") || source.EndsWith("iz") ) { source.InsertIntoBuffer('e'); } else if (source.EndsWithDoubleConsonant()) { var ch = source.LastChar; if (ch != 'l' && ch != 's' && ch != 'z') { source.Size--; } } else if ( source.NumberOfConsoantSequences(source.Size - 1) == 1 && source.HasCvcAt(source.Size - 1) ) { source.InsertIntoBuffer('e'); } } } }