Ejemplo n.º 1
0
        public List<string> getPossibleWords(String unsorted)
        {
            string possibleChars = sortString(unsorted);
            var wordsdic = new Dictionary<int, List<string>>();
            for (int a = unsorted.Length; a > 0; a--)
            {
                wordsdic.Add(a, new List<string>());
            }

            Dictionary<char, int> pch = getWordCount(possibleChars);

            //get all the words
            foreach (var kvp in words)
            {
                bool found = true;

                Dictionary<char, int> pch2 = getWordCount(kvp.Key);

                foreach (var p in pch2)
                {
                    if (pch.ContainsKey(p.Key) == false || p.Value > pch[p.Key])
                    {
                        found = false;
                        break;
                    }
                }

                if (found)
                {
                    List<string> newlist = wordsdic[kvp.Key.Length];

                    foreach (string s in kvp.Value)
                    {
                        if (newlist.Contains(s) == false)
                        {
                            newlist.Add(s);
                        }
                    }
                    wordsdic[kvp.Key.Length] = newlist;
                }
            }

            var outlist = new List<string>();
            foreach (var ll in wordsdic.Values)
            {
                outlist.AddRange(ll);
            }

            return outlist;
        }
Ejemplo n.º 2
0
        public Dictionary(String filename)
        {
            try
            {
                words = new Dictionary<string, List<string>>();
                var FS = new FileStream(filename, FileMode.Open);
                var SR = new StreamReader(FS);

                string file = SR.ReadToEnd();
                fileName = filename;

                var filesplit = file.Split('\n').Select(s => s.Trim()).ToList();

                foreach (string s in filesplit)
                {
                    if (s.Length < 3)
                        continue;

                    string sortedKey = sortString(s);

                    if (words.ContainsKey(sortedKey))
                    {
                        List<string> existing = words[sortedKey];
                        if (existing.Contains(s) == false)
                            existing.Add(s);
                        words[sortedKey] = existing;
                    }
                    else
                    {
                        var newlist = new List<string>();
                        newlist.Add(s);
                        words[sortedKey] = newlist;
                    }
                }

                SR.Close();
                FS.Close();
            }
            catch
            {
                MessageBox.Show("Error adding dictionary file:" + filename);
            }
        }
Ejemplo n.º 3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Licensing.LicensingForm(this, menuStrip1, HelpString, OtherText);
            LoadConfig();

            string p = Path.GetDirectoryName(Application.ExecutablePath);
            Directory.SetCurrentDirectory(p);

            d = new Dictionary("default.txt");
        }
Ejemplo n.º 4
0
        private Dictionary<char, int> getWordCount(String charlist)
        {
            var pch = new Dictionary<char, int>();
            foreach (char c in charlist)
            {
                if (pch.ContainsKey(c) == false)
                    pch[c] = 0;

                pch[c] = pch[c] + 1;
            }
            return pch;
        }