private string Apply(string name, Case @case, Rule rule) { foreach (var @char in FindCaseModificator(@case, rule)) { switch (@char) { case '.': break; case '-': name = name.Substring(0, name.Length - 1); break; default: name += @char; break; } } return name; }
private string FindCaseModificator(Case @case, Rule rule) { switch (@case) { case Case.Nominative: return "."; case Case.Genitive: return rule.ModSuffixes[0]; case Case.Dative: return rule.ModSuffixes[1]; case Case.Accusative: return rule.ModSuffixes[2]; case Case.Instrumental: return rule.ModSuffixes[3]; case Case.Prepositional: return rule.ModSuffixes[4]; default: throw new NotSupportedException(string.Format("Unknown grammatical case: {0}", @case)); } }
private bool MatchRule(string name, Rule rule, bool matchWholeWord, HashSet<string> tags) { if ((rule.Tags ?? new List<string>()).Except(tags).Any()) return false; Gender genderRule; if (Enum.TryParse(rule.Gender, true, out genderRule) && ((genderRule == Gender.Male && gender == Gender.Female) || (genderRule == Gender.Female && gender != Gender.Female))) { return false; } name = name.ToLower(); return new SuffixMatching(rule.TestSuffixes, matchWholeWord).IsMatched(name); }
private bool MatchRule(string name, Rule rule, bool matchWholeWord, HashSet<string> tags) { if ((rule.Tags ?? new List<string>()).Except(tags).Any()) return false; Gender genderRule; if (Enum.TryParse(rule.Gender, true, out genderRule) && ((genderRule == Gender.Male && gender == Gender.Female) || (genderRule == Gender.Female && gender != Gender.Female))) { return false; } name = name.ToLower(); foreach (var chars in rule.TestSuffixes) { string test = matchWholeWord ? name : name.Substring(new []{0, name.Length - chars.Length}.Max()); if (test.Equals(chars)) return true; } return false; }