Beispiel #1
0
        private static string GetHint(Backstory backstory)
        {
            StringBuilder hintBuilder = new StringBuilder();

            if (Backstory.IsSolid(backstory))
            {
                hintBuilder.Append($"{backstory.FirstName} ");

                if (!string.IsNullOrEmpty(backstory.NickName))
                {
                    hintBuilder.Append($"\"{backstory.NickName}\" ");
                }

                hintBuilder.Append($"{backstory.LastName}");

                if (!string.IsNullOrEmpty(backstory.Gender))
                {
                    hintBuilder.Append($", {backstory.Gender}");
                }

                hintBuilder.Append($", {backstory.Slot}");
            }
            else
            {
                if (!string.IsNullOrEmpty(backstory.Category))
                {
                    hintBuilder.Append($"{backstory.Category}");
                }
            }

            return(hintBuilder.ToString());
        }
Beispiel #2
0
        private static Backstory FindBestMatch(HashSet <Backstory> backstories, Backstory backstory)
        {
            string    id        = Backstory.GetIdentifier(backstory);
            Backstory matchById = backstories.FirstOrDefault(bs => Backstory.GetIdentifier(bs) == id);

            if (matchById != null)
            {
                return(matchById);
            }

            if (Backstory.IsSolid(backstory))
            {
                Backstory matchBySolidName = backstories.FirstOrDefault(bs => bs.FirstName == backstory.FirstName && bs.LastName == backstory.LastName && bs.Slot == backstory.Slot);

                if (matchBySolidName != null)
                {
                    return(matchBySolidName);
                }
            }

            Levenshtein backstoryLevenshtein = new Levenshtein(backstory.Description);

            Backstory matchByDescription = backstories.MinValue(bs => backstoryLevenshtein.DistanceFrom(bs.Description), out int minDist);

            if (matchByDescription != null && minDist < 0.5f * backstory.Description.Length)
            {
                return(matchByDescription);
            }

            return(null);
        }