Example #1
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);
        }
Example #2
0
        public static Backstory ReadBackstoryElementResource(XElement storyElem)
        {
            Backstory backstory = new Backstory()
            {
                Title            = storyElem.Element("title", true).Value,
                TitleFemale      = storyElem.Element("titleFemale", true)?.Value,
                TitleShort       = storyElem.Element("titleShort", true).Value,
                TitleShortFemale = storyElem.Element("titleShortFemale", true)?.Value,
                Description      = storyElem.Element("baseDesc", true).Value,
                Slot             = ParseSlot(storyElem)
            };

            backstory.Id = Backstory.GetIdentifier(backstory);

            // We don't want to spoil sensitive hash function, but want to make line endings consistent
            backstory.Description = backstory.Description.Replace("\r", "").Replace("\n", "\\n");

            return(backstory);
        }