private static IEnumerable <RaceInfo> SortRacesBySimilarity( IEnumerable <RaceInfo> races, string raceName) { double GetSimilarityValue(string name1, string name2) { name1 = NameNormalizer.NormaliseName(name1, true, false); name2 = NameNormalizer.NormaliseName(name2, true, false); return(Levenshtein.GetSimilarityPercentage(name1, name2, true)); } var result = races.OrderByDescending(item => GetSimilarityValue(item.Name, raceName)); return(result.ToList()); }
private HorseInfo FindHorseByName(List <HorseInfo> horses, string requestName) { foreach (var horse in horses) { var curHorseNameNorm = NameNormalizer.NormaliseName($"{horse.Name}", true, false); if (Levenshtein.GetSimilarityPercentage($"{curHorseNameNorm}", requestName, true) < 0.8f) { continue; } return(horse); } throw new Exception($"Can't find horse with name: {requestName}"); }