Beispiel #1
0
        public bool addLexWords(params string[] vargs)
        {
            ICollection <LexWord> lexWords = CollectionFactory.CreateQueue <LexWord>();
            bool containsKey = false;

            // number of arguments must be key (1) + lexWord pairs ( x * 2 )
            if (vargs.Length % 2 != 1)
            {
                return(false);
            }

            string key = vargs[0].ToUpper();

            if (this.ContainsKey(key))
            {
                containsKey = true;
            }

            for (int i = 1; i < vargs.Length; ++i)
            {
                try
                {
                    if (containsKey)
                    {
                        this.Get(key).Add(new LexWord(vargs[i],
                                                      TextFactory.ParseFloat(vargs[i + 1])));
                    }
                    else
                    {
                        lexWords.Add(new LexWord(vargs[i],
                                                 TextFactory.ParseFloat(vargs[i + 1])));
                    }
                    ++i;
                }
                catch (NumberFormatException)
                {
                    System.Console.WriteLine("Supplied args have incorrect format.");
                    return(false);
                }
            }
            if (!containsKey)
            {
                this.Put(key, lexWords);
            }
            return(true);
        }