/// <summary> /// Add a rule to the rules collection for the stemmer. /// </summary> /// <param name="rule">The rule to add.</param> public void AddRule(StemRule rule) { _rules.Add(rule); }
/// <summary> /// Apply a rule to a stem to create a new stem. /// </summary> /// <param name="stem">The stem to apply the rule to.</param> /// <param name="rule">The rule to apply to the stem.</param> /// <returns>A new stem.</returns> private string ApplyRule(string stem, StemRule rule) { return stem.Substring(0, stem.Length - rule.Ending.Length) + rule.Replacement; }
/// <summary> /// Check if a rule can be applied to a stem. /// </summary> /// <remarks> /// The application of a rule to a stem may not always result /// in a stem that makes sense linguistically. This check is /// an attempt to reduce the error in the stemming process. /// </remarks> /// <param name="stem">The stem to check application against.</param> /// <param name="rule">The rule to check.</param> /// <returns>True if the rule can be applied, false otherwise.</returns> private bool CanApplyRule(string stem, StemRule rule) { string newStem = ApplyRule(stem, rule); return WordContainsVowel(newStem); }