Example #1
0
        public void TestEmptySource()
        {
            wordsDataSource = new SimpleWordsDataSource();
            WordProbability wp = wordsDataSource.GetWordProbability("myWord");

            Assert.IsNull(wp);
        }
Example #2
0
        public void TestAddNonMatch()
        {
            wordsDataSource = new SimpleWordsDataSource();
            wordsDataSource.AddNonMatch("myWord");
            WordProbability wp = wordsDataSource.GetWordProbability("myWord");

            Assert.IsNotNull(wp);
            Assert.AreEqual(0, wp.MatchingCount);
            Assert.AreEqual(1, wp.NonMatchingCount);

            wordsDataSource.AddNonMatch("myWord");

            wp = wordsDataSource.GetWordProbability("myWord");
            Assert.IsNotNull(wp);
            Assert.AreEqual(0, wp.MatchingCount);
            Assert.AreEqual(2, wp.NonMatchingCount);
        }
 public void TestAddMultipleNonMatches()
 {
     wordsDataSource = new SimpleWordsDataSource();
     string word = "myWord";
     int count = 10;
     for (int i = 0; i < count; i++)
         wordsDataSource.AddNonMatch(word);
     WordProbability wp = wordsDataSource.GetWordProbability(word);
     Assert.IsNotNull(wp);
     Assert.AreEqual(count, wp.NonMatchingCount);
 }
        public void TestAddMatch()
        {
            wordsDataSource = new SimpleWordsDataSource();
            wordsDataSource.AddMatch("myWord");
            WordProbability wp = wordsDataSource.GetWordProbability("myWord");
            Assert.IsNotNull(wp);
            Assert.AreEqual(1, wp.MatchingCount);
            Assert.AreEqual(0, wp.NonMatchingCount);

            wordsDataSource.AddMatch("myWord");

            Assert.AreEqual(2, wp.MatchingCount);
            Assert.AreEqual(0, wp.NonMatchingCount);
        }
Example #5
0
        public void TestAddMultipleNonMatches()
        {
            wordsDataSource = new SimpleWordsDataSource();
            string word  = "myWord";
            int    count = 10;

            for (int i = 0; i < count; i++)
            {
                wordsDataSource.AddNonMatch(word);
            }
            WordProbability wp = wordsDataSource.GetWordProbability(word);

            Assert.IsNotNull(wp);
            Assert.AreEqual(count, wp.NonMatchingCount);
        }
        public void TestAddMultipleMatches()
        {
            wordsDataSource = new SimpleWordsDataSource();
            var word  = "myWord";
            var count = 10;

            for (var i = 0; i < count; i++)
            {
                wordsDataSource.AddMatch(word);
            }
            var wp = wordsDataSource.GetWordProbability(word);

            Assert.IsNotNull(wp);
            Assert.AreEqual(count, wp.MatchingCount);
        }
Example #7
0
        private WordProbability[] CalcWordsProbability(string category, string[] words)
        {
            if (category == null)
            {
                throw new ArgumentNullException("Category cannot be null.");
            }

            bool categorize = false;

            if (_wordsData is ICategorizedWordsDataSource)
            {
                categorize = true;
            }

            CheckCategoriesSupported(category);

            if (words == null)
            {
                return(new WordProbability[0]);
            }
            else
            {
                ArrayList wps = new ArrayList();
                for (int i = 0; i < words.Length; i++)
                {
                    if (IsClassifiableWord(words[i]))
                    {
                        WordProbability wp = null;
                        if (categorize)
                        {
                            wp = ((ICategorizedWordsDataSource)_wordsData).GetWordProbability(category, TransformWord(words[i]));
                        }
                        else
                        {
                            wp = _wordsData.GetWordProbability(TransformWord(words[i]));
                        }

                        if (wp != null)
                        {
                            wps.Add(wp);
                        }
                    }
                }
                return((WordProbability[])wps.ToArray(typeof(WordProbability)));
            }
        }
Example #8
0
        private IList <WordProbability> CalcWordsProbability(string category, string[] words)
        {
            if (category == null)
            {
                throw new ArgumentNullException("Category cannot be null.");
            }

            var categorizedWordsDataSource = _wordsData as ICategorizedWordsDataSource;

            CheckCategoriesSupported(category);

            if (words == null)
            {
                return(new WordProbability[0]);
            }

            var wps = new List <WordProbability>();

            for (var i = 0; i < words.Length; i++)
            {
                if (IsClassifiableWord(words[i]))
                {
                    WordProbability wp = null;
                    if (categorizedWordsDataSource == null)
                    {
                        wp = _wordsData.GetWordProbability(TransformWord(words[i]));
                    }
                    else
                    {
                        wp = categorizedWordsDataSource.GetWordProbability(category, TransformWord(words[i]));
                    }

                    if (wp != null)
                    {
                        wps.Add(wp);
                    }
                }
            }

            return(wps);
        }
 public void TestEmptySource()
 {
     wordsDataSource = new SimpleWordsDataSource();
     WordProbability wp = wordsDataSource.GetWordProbability("myWord");
     Assert.IsNull(wp);
 }