示例#1
0
        public IEnumerable <string> Transform(string start, string end, bool substitutionsOnly)
        {
            Validate.IsNotNullOrEmpty(start);
            Validate.IsNotNullOrEmpty(end);
            Validate.IsTrue(
                !substitutionsOnly || start.Length == end.Length,
                "When only substitutions are allowed, the start and end words must be the same length.");

            if (substitutionsOnly)
            {
                return(RestrictedGraphSearcher.FindPath(
                           start,
                           end,
                           word => EditDistance.CalculateHamming(word, end)
                           ));
            }
            else
            {
                return(FullGraphSearcher.FindPath(
                           start,
                           end,
                           word => EditDistance.CalculateLevenshtein(word, end)
                           ));
            }
        }
示例#2
0
        private void AddValidEdges(IEnumerable <Tuple <string, string> > wordPairs)
        {
            foreach (var pair in wordPairs)
            {
                string a = pair.Item1;
                string b = pair.Item2;

                if (EditDistance.AreLevenshteinAdjacent(a, b))
                {
                    AddEdge(a, b);
                    AddEdge(b, a);
                }
            }
        }