コード例 #1
0
        public WordTreeNodeEnumerator(WordTree tree, byte[] digits)
        {
            this.rootNode = tree.RootNode;
            this.curNode  = rootNode;

            this.digits   = digits;
            this.maxDepth = digits.Length;
        }
コード例 #2
0
        private void displayWords()
        {
            string               phoneString = phoneNumberTextBox.Text;
            WordTree             tree        = MainForm.Tree;
            IEnumerable <string> words       = tree.GetAlphanumericWords(
                phoneString,
                (int)maxDigitsUpDown.Value,
                cacheUsageCheckBox.Checked);
            bool didFindWords = words.Count() > 0;

            if (didFindWords)
            {
                string digitsStr = null;
                switch ((int)maxDigitsUpDown.Value)
                {
                case 0:
                    digitsStr = "no digits";
                    break;

                case 1:
                    digitsStr = "up to one digit";
                    break;

                default:
                    digitsStr = "up to " + ((int)maxDigitsUpDown.Value).ToString() + " digits";
                    break;
                }
                wordsLabel.Text = "Words spelled in "
                                  + "\"" + phoneString + "\""
                                  + " with " + digitsStr + ":";
            }
            else
            {
                wordsLabel.Text = "Words spelled:";
            }
            wordsTextBox.Text = (words.Count() == 0)
                ? "No words found"
                : String.Join(Environment.NewLine, words);
        }
コード例 #3
0
ファイル: WordTree.cs プロジェクト: jaycoskey/Spellephone
        /// <summary>
        ///     Retrieve a list of words corresponding to a given phone number.
        /// </summary>
        /// <param name="phoneString">The phone number to be used.  Punctuation marks are ignored.</param>
        /// <param name="maxDigitsInResult">Maximum number of digits allowed in the words found.</param>
        /// <param name="doUseResultsCache">Use a cache to store the results of an internal function, to prevent duplicate computation.</param>
        /// <returns></returns>
        public IEnumerable <string> GetAlphanumericWords(
            string phoneString,
            int maxDigitsInResult  = int.MaxValue,
            bool doUseResultsCache = false)
        {
            byte[] digits = WordTree.GetDigits(phoneString);
            Dictionary <WordTree.Bounds, List <string> > alphaWordsDict;

            getAlphaWordsDict(digits, out alphaWordsDict);

            // Debug.Write(alphaWordsDict.ToString_Debug());
            Dictionary <int, List <string> > resultsCache = null;

            if (doUseResultsCache)
            {
                resultsCache = new Dictionary <int, List <string> >();
            }
            List <string> words = getAlphanumericWordsImpl(alphaWordsDict, digits, 0, ref resultsCache);

            words = words.Distinct().ToList();  // Prevent duplicates, such as "ago" and "a" + "go".
            words = words.Where(word => word.Count(c => Char.IsDigit(c)) <= maxDigitsInResult).ToList();
            return(words);
        }
コード例 #4
0
        private void mainForm_Load(object sender, EventArgs e)
        {
            addTooltips();
            wordsTextBox.Text = "Loading dictionary....";
            string fileName = doLoadTestWords_Debug
                ? "../../Resources/testWords.txt"
                : "../../Resources/mobyWords.txt";

            try
            {
                fileName = String.Format(fileName);
                Tree     = new WordTree(fileName);
                // Debug.Print(Tree.ToString());
            }
            catch (Exception ex)
            {
                wordsTextBox.Text = "Could not read file: "
                                    + fileName + ".  "
                                    + ex.Message + Environment.NewLine;
            }
            wordsTextBox.Text = String.Format("Loaded {0:d} words.{1:s}",
                                              Tree.WordCount(int.MaxValue),
                                              Environment.NewLine);
            if (doDumpLoadedWords_Debug)
            {
                #pragma warning disable 0162
                Debug.WriteLine(String.Join(Environment.NewLine, Tree.GetAllWords()));
                #pragma warning restore 0162
            }
            if (doDumpTree_Debug)
            {
                #pragma warning disable 0162
                Debug.WriteLine(Tree.ToString());
                #pragma warning restore 0162
            }
            this.ActiveControl = phoneNumberTextBox;
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: jaycoskey/Spellephone
 private void mainForm_Load(object sender, EventArgs e)
 {
     addTooltips();
     wordsTextBox.Text = "Loading dictionary....";
     string fileName = doLoadTestWords_Debug
         ? "../../Resources/testWords.txt"
         : "../../Resources/mobyWords.txt";
     try
     {
         fileName = String.Format(fileName);
         Tree = new WordTree(fileName);
         // Debug.Print(Tree.ToString());
     }
     catch (Exception ex)
     {
         wordsTextBox.Text = "Could not read file: "
             + fileName + ".  "
             + ex.Message + Environment.NewLine;
     }
     wordsTextBox.Text = String.Format("Loaded {0:d} words.{1:s}",
         Tree.WordCount(int.MaxValue),
         Environment.NewLine);
     if (doDumpLoadedWords_Debug)
     {
         #pragma warning disable 0162
         Debug.WriteLine(String.Join(Environment.NewLine, Tree.GetAllWords()));
         #pragma warning restore 0162
     }
     if (doDumpTree_Debug)
     {
         #pragma warning disable 0162
         Debug.WriteLine(Tree.ToString());
         #pragma warning restore 0162
     }
     this.ActiveControl = phoneNumberTextBox;
 }
コード例 #6
0
 public WordTreeNodeEnumerable(WordTree tree, IEnumerable <byte> digits)
 {
     this.digits = digits.ToArray();
     this.tree   = tree;
 }