Пример #1
0
        public WordListTree ParseWordList()
        {
            var list = new WordListTree();

            using (var fileReader = new StreamReader(string.Format("WordLists/{0}", fileName)))
            {
                string word;
                while ((word = fileReader.ReadLine()) != null)
                {
                    list.Parse(word);
                }
            }
            return(list);
        }
Пример #2
0
        public Dictionary <string, List <string> > SearchString(string phrasePortion, WordListTree dictionary)
        {
            var results = new Dictionary <string, List <string> >();

            if (phrasePortion.Length == 0)
            {
                if (ResolvedWord != null)
                {
                    var item = new List <string> {
                        ResolvedWord
                    };
                    var hash = item.Hash();
                    if (!results.ContainsKey(hash))
                    {
                        results.Add(hash, item);
                    }
                }
            }
            foreach (var c in phrasePortion)
            {
                var resolved = Children.FirstOrDefault(r => r.IndexLetter == c);
                if (resolved != null)
                {
                    if (ResolvedWord != null)
                    {
                        //restart search at beginning of dictionary
                        var r = dictionary.Search(phrasePortion);
                        foreach (var x in r.Values)
                        {
                            // have to jam the resolved word into the generated results
                            x.Insert(0, ResolvedWord);

                            var hash = x.Hash();
                            if (!results.ContainsKey(hash))
                            {
                                results.Add(hash, x);
                            }
                        }
                    }

                    // Crop it down, removing that letter
                    var remainder = phrasePortion.Substring(0, phrasePortion.IndexOf(c)) +
                                    phrasePortion.Substring(phrasePortion.IndexOf(c) + 1,
                                                            phrasePortion.Length - (phrasePortion.IndexOf(c) + 1));

                    var tempResults = resolved.SearchString(remainder, dictionary);

                    foreach (var x in tempResults.Values)
                    {
                        var hash = x.Hash();
                        if (!results.ContainsKey(hash))
                        {
                            results.Add(hash, x);
                        }
                    }
                }
            }
            return(results);
        }