예제 #1
0
        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());
        }
예제 #2
0
        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}");
        }