public void EqualsTestEqualsOperator()
 {
     TermCountQuery o1 = new TermCountQuery();
     o1.Limit = 1;
     TermCountQuery o2 = new TermCountQuery();
     o2.Limit = 1;
     Assert.IsTrue(o1 == o2);
 }
 public void EqualsTestGetHasCodesEquals()
 {
     TermCountQuery o1 = new TermCountQuery();
     o1.Limit = 1;
     TermCountQuery o2 = new TermCountQuery();
     o2.Limit = 1;
     Assert.AreEqual(o1.GetHashCode(), o2.GetHashCode());
 }
 public void EqualsTestEquality()
 {
     TermCountQuery o1 = new TermCountQuery();
     o1.Limit = 1;
     TermCountQuery o2 = new TermCountQuery();
     o2.Limit = 1;
     Assert.IsTrue(o1.Equals(o2));
 }
        public void CategoryIdsTest()
        {
            TermCountQuery q = new TermCountQuery();

            List<int> categoryIds = new List<int>() { 1, 2, 3, 4 };
            q.CategoryIds = categoryIds;

            Assert.AreEqual(categoryIds, q.CategoryIds);
        }
        public void GetIndividualTermCountTestPerformanceImprovementOneTerm()
        {
            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Set some news as interesting.
            Archivist.SetNewsInterestingStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[0].Title)), true);
            Archivist.SetNewsInterestingStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[1].Title)), true);

            // Calculate the expected term frequency of all terms
            // in the two interesting news.
            Dictionary<string, int> tf0 =
                TermUtils.CalculateTermFrequency(NewsMaterial[0].Content);
            Dictionary<string, int> tf1 =
                TermUtils.CalculateTermFrequency(NewsMaterial[1].Content);

            // Combine the two dictionaries.
            foreach (KeyValuePair<string, int> t in tf1)
            {
                if (tf0.ContainsKey(t.Key))
                {
                    // Increase frequency.
                    tf0[t.Key] += t.Value;
                }
                else
                {
                    // Add term with frequency.
                    tf0.Add(t.Key, t.Value);
                }
            }

            // Expected value is equal to tf0
            Dictionary<string, int> expectedDictionary = new Dictionary<string, int>();
            expectedDictionary.Add(tf0.Keys.ElementAt(0), tf0[tf0.Keys.ElementAt(0)]);

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                Interest = InterestStatus.Interesting
            };

            tcq.Terms.Add(tf0.Keys.ElementAt(0));

            Dictionary<string, int> actualDictionary = Archivist.GetIndividualTermCount(tcq);

            CollectionAssert.AreEquivalent(expectedDictionary, actualDictionary);
        }
        public void GetIndividualTermCountTestOffset()
        {
            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Calculate the expected term frequency of terms in all news items.
            Dictionary<string, int> tf0 =
                TermUtils.CalculateTermFrequency(NewsMaterial[0].Content);
            Dictionary<string, int> tf1 =
                TermUtils.CalculateTermFrequency(NewsMaterial[1].Content);

            // Combine the dictionaries
            foreach (KeyValuePair<string, int> t in tf1)
            {
                if (tf0.ContainsKey(t.Key))
                {
                    // Increase frequency.
                    tf0[t.Key] += t.Value;
                }
                else
                {
                    // Add term with frequency.
                    tf0.Add(t.Key, t.Value);
                }
            }

            // Copy the keys to a list.
            List<string> termsToRemove = tf0.Keys.ToList();

            // Remove everything but the first 50 elements.
            termsToRemove.RemoveRange(50, termsToRemove.Count - 50);

            // Remove the strings that should not be in the dictionary.
            foreach (string term in termsToRemove)
            {
                tf0.Remove(term);
            }

            Dictionary<string, int> expectedDictionary = tf0;

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                Offset = 50
            };

            Dictionary<string, int> actualDictionary = Archivist.GetIndividualTermCount(tcq);

            CollectionAssert.AreEquivalent(expectedDictionary, actualDictionary);
        }
 public void EqualsTestObjectToNullReferenceEqualsOperator()
 {
     TermCountQuery o1 = new TermCountQuery();
     o1.Limit = 1;
     TermCountQuery o2 = null;
     Assert.IsFalse(o1 == o2);
 }
Esempio n. 8
0
 /// <summary>
 /// Gets the individual term frequency of all terms matching the
 /// given <c>TermCountQuery</c>.
 /// </summary>
 /// <param name="termCountQuery">
 /// A <c>TermCountQuery</c> specifying the terms to get the term
 /// frequency of.
 /// </param>
 /// <returns>
 /// A <c>Dictionary</c> with the key being a term and the value being
 /// its frequency matching the <c>TermCountQuery</c>.
 /// </returns>
 public abstract Dictionary<string, int> GetIndividualTermCount(
     TermCountQuery termCountQuery);
        public void RemoveNewsTestTermStays()
        {
            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Adds a custom unique term to two of the newsmaterials.
            string testTerm = "FooBarDeadWhale";
            string stemmedTestTerm = (new Porter2()).stem(testTerm);
            NewsMaterial[0].Content += " " + testTerm + ".";
            NewsMaterial[1].Content += " " + testTerm + ".";

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Request to count the number of testTerm in the databae.
            TermCountQuery termRequest = new TermCountQuery();
            termRequest.Terms.Add(stemmedTestTerm);

            // Remove an item.
            Archivist.RemoveNews(gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[0].Title)));

            // The actual ammount of terms.
            int actual = Archivist.GetTermCount(termRequest);

            // The expected ammount of terms.
            int expected = 1;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 10
0
        public void HasDefaultValues()
        {
            TermCountQuery q = new TermCountQuery();

            // Expected values.
            InterestStatus interest = InterestStatus.Any;
            ReadStatus read = ReadStatus.Any;
            int limit = 100000;
            int offset = 0;
            List<int> categoryIds = new List<int>();
            List<string> terms = new List<string>();

            // Check the default values.
            Assert.AreEqual(interest, q.Interest,
                "Interest is not default. Expected " + interest + " but got " +
                q.Interest + ".");
            Assert.AreEqual(read, q.Read,
                "Read is not default. Expected " + read + " but got " +
                q.Read + ".");
            Assert.AreEqual(limit, q.Limit, "Limit is not default. Expected " +
                limit + " but got " + q.Limit + ".");
            Assert.AreEqual(offset, q.Offset, "Offset is not default. Expected " +
                offset + " but got " + q.Offset + ".");
            CollectionAssert.AreEquivalent(categoryIds, q.CategoryIds,
                "CategoryIds is not default.");
            CollectionAssert.AreEquivalent(terms, q.Terms,
                "Terms is not default.");

            // Hard to test as the DateTime for the creation of q cannot
            // be determined. Therefor the type is checked.
            Assert.IsInstanceOfType(q.NewerThan, typeof(DateTime),
                "NewerThan is not a DateTime.");
        }
Esempio n. 11
0
        public void GetTermCountTestNewerThan()
        {
            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Calculate the term frequency of the expected news item.
            Dictionary<string, int> tf2 =
                TermUtils.CalculateTermFrequency(NewsMaterial[2].Content);

            // Find the total number of terms in the news items.
            int expectedTermCount = 0;
            foreach (KeyValuePair<string, int> t in tf2)
            {
                expectedTermCount += t.Value;
            }

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                NewerThan = new DateTime(2013, 4, 27, 12, 50, 00)
            };

            int actualTermCount = Archivist.GetTermCount(tcq);

            Assert.AreEqual(expectedTermCount, actualTermCount);
        }
Esempio n. 12
0
        public void TermsTest()
        {
            TermCountQuery q = new TermCountQuery();

            List<string> terms = new List<string>() { "fnyld", "dyld", "badyld" };
            q.Terms = terms;

            CollectionAssert.AreEquivalent(terms, q.Terms);
        }
Esempio n. 13
0
        public void ReadTest()
        {
            TermCountQuery q = new TermCountQuery();

            ReadStatus read = ReadStatus.Read;
            q.Read = read;

            Assert.AreEqual(read, q.Read);
        }
Esempio n. 14
0
        public void OffsetTest()
        {
            TermCountQuery q = new TermCountQuery();

            int offset = 98;
            q.Offset = offset;

            Assert.AreEqual(offset, q.Offset);
        }
Esempio n. 15
0
        public void NewerThanTest()
        {
            TermCountQuery q = new TermCountQuery();

            DateTime newerThan = DateTime.Now;
            q.NewerThan = newerThan;

            Assert.AreEqual(newerThan, q.NewerThan);
        }
Esempio n. 16
0
        public void InterestTest()
        {
            TermCountQuery q = new TermCountQuery();

            InterestStatus interest = InterestStatus.Uninteresting;
            q.Interest = interest;

            Assert.AreEqual(interest, q.Interest);
        }
Esempio n. 17
0
        public void GetIndividualTermCountTestPerformanceImprovementTwoTermsSpecificCategory()
        {
            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Set some news as interesting.
            Archivist.SetNewsInterestingStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[0].Title)), true);
            Archivist.SetNewsInterestingStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[2].Title)), true);

            // Calculate the expected term frequency of all terms
            // in the interesting news item from category 0.
            Dictionary<string, int> tf0 =
                TermUtils.CalculateTermFrequency(NewsMaterial[0].Content);

            // Expected value is equal to tf0.
            Dictionary<string, int> expectedDictionary = new Dictionary<string, int>();
            expectedDictionary.Add(tf0.Keys.ElementAt(0), tf0[tf0.Keys.ElementAt(0)]);
            expectedDictionary.Add(tf0.Keys.ElementAt(1), tf0[tf0.Keys.ElementAt(1)]);

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                Interest = InterestStatus.Interesting
            };

            tcq.Terms.Add(tf0.Keys.ElementAt(0));
            tcq.Terms.Add(tf0.Keys.ElementAt(1));

            tcq.CategoryIds.Add(Categories[0].Id);

            Dictionary<string, int> actualDictionary = Archivist.GetIndividualTermCount(tcq);

            CollectionAssert.AreEquivalent(expectedDictionary, actualDictionary);
        }
Esempio n. 18
0
        public void GetTermCountTestOffset()
        {
            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Calculate the expected term frequency of terms in all news items.
            Dictionary<string, int> tf0 =
                TermUtils.CalculateTermFrequency(NewsMaterial[0].Content);
            Dictionary<string, int> tf1 =
                TermUtils.CalculateTermFrequency(NewsMaterial[1].Content);

            // Combine the dictionaries
            foreach (KeyValuePair<string, int> t in tf1)
            {
                if (tf0.ContainsKey(t.Key))
                {
                    // Increase frequency.
                    tf0[t.Key] += t.Value;
                }
                else
                {
                    // Add term with frequency.
                    tf0.Add(t.Key, t.Value);
                }
            }

            // Copy the keys to a list.
            List<string> terms = tf0.Keys.ToList();

            // Remove the first 50 terms.
            terms.RemoveRange(0, 50);

            // Find the total number of terms in the news items.
            int expectedTermCount = 0;
            foreach (KeyValuePair<string, int> t in tf0)
            {
                if (terms.Contains(t.Key))
                {
                    expectedTermCount += t.Value;
                }
            }

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                Offset = 50
            };

            int actualTermCount = Archivist.GetTermCount(tcq);

            Assert.AreEqual(expectedTermCount, actualTermCount);
        }
Esempio n. 19
0
        public void GetTermCountTestMisc()
        {
            // The term to search for.
            string termToSearchFor1 = "poni";
            string termToSearchFor2 = "vermont";

            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Set some news as interesting.
            Archivist.SetNewsInterestingStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[0].Title)), true);
            Archivist.SetNewsInterestingStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[1].Title)), true);
            Archivist.SetNewsInterestingStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[3].Title)), true);

            // Set some news as read.
            Archivist.SetNewsReadStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[0].Title)), true);

            // Calculate the expected term frequency.
            Dictionary<string, int> tf0 =
                TermUtils.CalculateTermFrequency(NewsMaterial[0].Content);

            // Find the frequency of the term to search for.
            int expectedTermCount = 0;
            foreach (KeyValuePair<string, int> t in tf0)
            {
                if (t.Key.Equals(termToSearchFor1))
                {
                    expectedTermCount += t.Value;
                }
            }

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                Interest = InterestStatus.Interesting,
                Read = ReadStatus.Read,
                CategoryIds = new List<int>() { Categories[0].Id },
                Terms = new List<string>()
                {
                    termToSearchFor1,
                    termToSearchFor2
                }
            };

            int actualTermCount = Archivist.GetTermCount(tcq);

            Assert.AreEqual(expectedTermCount, actualTermCount);
        }
Esempio n. 20
0
        public void GetTermCountTestRead()
        {
            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Set some news as read.
            Archivist.SetNewsReadStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[1].Title)), true);
            Archivist.SetNewsReadStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[2].Title)), true);

            // Calculate the expected term frequency of all terms
            // in the two read news.
            Dictionary<string, int> tf1 =
                TermUtils.CalculateTermFrequency(NewsMaterial[1].Content);
            Dictionary<string, int> tf2 =
                TermUtils.CalculateTermFrequency(NewsMaterial[2].Content);

            // Combine the two dictionaries.
            foreach (KeyValuePair<string, int> t in tf2)
            {
                if (tf1.ContainsKey(t.Key))
                {
                    // Increase frequency.
                    tf1[t.Key] += t.Value;
                }
                else
                {
                    // Add term with frequency.
                    tf1.Add(t.Key, t.Value);
                }
            }

            // Find the total number of terms in the news items.
            int expectedTermCount = 0;
            foreach (KeyValuePair<string, int> t in tf1)
            {
                expectedTermCount += t.Value;
            }

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                Read = ReadStatus.Read
            };

            int actualTermCount = Archivist.GetTermCount(tcq);

            Assert.AreEqual(expectedTermCount, actualTermCount);
        }
Esempio n. 21
0
        public void GetTermCountTestNoTermsFetched()
        {
            // The term to search for.
            string termToSearchFor1 = "poni";
            string termToSearchFor2 = "vermont";

            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Set some news as interesting.
            Archivist.SetNewsInterestingStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[1].Title)), true);
            Archivist.SetNewsInterestingStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[3].Title)), true);

            // Set some news as read.
            Archivist.SetNewsReadStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[0].Title)), true);
            Archivist.SetNewsReadStatus(
                gottenNewsItems.Find(n => n.Title.Equals(NewsMaterial[3].Title)), true);

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                Interest = InterestStatus.Interesting,
                Read = ReadStatus.Read,
                CategoryIds = new List<int>() { Categories[0].Id },
                Terms = new List<string>()
                {
                    termToSearchFor1,
                    termToSearchFor2
                }
            };

            int actualTermCount = Archivist.GetTermCount(tcq);

            Assert.AreEqual(0, actualTermCount);
        }
Esempio n. 22
0
 public void EqualsTestReferenceEquals()
 {
     TermCountQuery o1 = new TermCountQuery();
     o1.Limit = 1;
     TermCountQuery o2 = o1;
     Assert.IsTrue(o1.Equals(o2));
 }
Esempio n. 23
0
        public void GetTermCountTestOneTerm()
        {
            // The term to search for.
            string termToSearchFor = "poni";

            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Calculate the term frequency of news items with the term
            // to search for.
            Dictionary<string, int> tf0 =
                TermUtils.CalculateTermFrequency(NewsMaterial[0].Content);

            // Find the frequency of the term to search for.
            int expectedTermCount = 0;
            foreach (KeyValuePair<string, int> t in tf0)
            {
                if (t.Key.Equals(termToSearchFor))
                {
                    expectedTermCount += t.Value;
                }
            }

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                Terms = new List<string>() { termToSearchFor }
            };

            int actualTermCount = Archivist.GetTermCount(tcq);

            Assert.AreEqual(expectedTermCount, actualTermCount);
        }
Esempio n. 24
0
 public void EqualsTestInequality()
 {
     TermCountQuery o1 = new TermCountQuery();
     o1.Limit = 1;
     TermCountQuery o2 = new TermCountQuery();
     o1.Limit = 2;
     Assert.IsFalse(o1.Equals(o2));
 }
Esempio n. 25
0
        public void GetTermCountTestTwoTerms()
        {
            // The term to search for.
            string termToSearchFor1 = "poni";
            string termToSearchFor2 = "vermont";

            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Calculate the expected term frequency.
            Dictionary<string, int> tf0 =
                TermUtils.CalculateTermFrequency(NewsMaterial[0].Content);
            Dictionary<string, int> tf1 =
                TermUtils.CalculateTermFrequency(NewsMaterial[1].Content);

            // Combine the two dictionaries.
            foreach (KeyValuePair<string, int> t in tf1)
            {
                if (tf0.ContainsKey(t.Key))
                {
                    // Increase frequency.
                    tf0[t.Key] += t.Value;
                }
                else
                {
                    // Add term with frequency.
                    tf0.Add(t.Key, t.Value);
                }
            }

            // Find the frequency of the term to search for.
            int expectedTermCount = 0;
            foreach (KeyValuePair<string, int> t in tf0)
            {
                if (t.Key.Equals(termToSearchFor1) ||
                    t.Key.Equals(termToSearchFor2))
                {
                    expectedTermCount += t.Value;
                }
            }

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                Terms = new List<string>()
                {
                    termToSearchFor1,
                    termToSearchFor2
                }
            };

            int actualTermCount = Archivist.GetTermCount(tcq);

            Assert.AreEqual(expectedTermCount, actualTermCount);
        }
Esempio n. 26
0
        public void GetIndividualTermCountTestCategoryIds()
        {
            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Calculate the expected term frequency.
            Dictionary<string, int> tf0 =
                TermUtils.CalculateTermFrequency(NewsMaterial[0].Content);
            Dictionary<string, int> tf1 =
                TermUtils.CalculateTermFrequency(NewsMaterial[1].Content);

            // Combine the two dictionaries.
            foreach (KeyValuePair<string, int> t in tf1)
            {
                if (tf0.ContainsKey(t.Key))
                {
                    // Increase frequency.
                    tf0[t.Key] += t.Value;
                }
                else
                {
                    // Add term with frequency.
                    tf0.Add(t.Key, t.Value);
                }
            }

            Dictionary<string, int> expectedDictionary = tf0;

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                CategoryIds = new List<int> { Categories[0].Id }
            };

            Dictionary<string, int> actualDictionary = Archivist.GetIndividualTermCount(tcq);

            CollectionAssert.AreEquivalent(expectedDictionary, actualDictionary);
        }
Esempio n. 27
0
        /// <summary>
        /// Counts the number of documents satisfying the parameter values.
        /// </summary>
        /// <param name="archivist">
        /// The <c>Archivist</c> instance with database access.
        /// </param>
        /// <param name="terms">
        /// A list of terms the documents should contain.
        /// </param>
        /// <param name="category">
        /// A <c>Category</c> the documents should belong to.
        /// </param>
        /// <param name="interesting">
        /// Whether the documents should be marked interesting or not.
        /// </param>
        /// <returns>
        /// The number of documents satisfying the parameter values.
        /// </returns>
        private Dictionary<string, int> CountTermsWithQuery(Archivist archivist, List<string> terms,
                              Category category, bool interesting)
        {
            // Create query instance.
            TermCountQuery termQuery = new TermCountQuery();

            // Add term to query if not null.
            if (terms != null)
            {
                termQuery.Terms = terms;
            }

            // Set category if not null.
            if (category != null)
            {
                termQuery.CategoryIds = new List<int> { category.Id };
            }

            termQuery.Interest = interesting ?
                Database.InterestStatus.Interesting :
                Database.InterestStatus.Uninteresting;

            // Send query and return result.
            return archivist.GetIndividualTermCount(termQuery);
        }
Esempio n. 28
0
        public void GetIndividualTermCountTestNewerThan()
        {
            // Add categories and news sources.
            foreach (Category c in Categories)
            {
                c.Id = Archivist.AddCategory(c.Name);
            }
            Archivist.AddNewsSources(NewsSources);

            // Add news with forced categories.
            Archivist.AddNews(NewsMaterial[0], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[1], Categories[0].Id);
            Archivist.AddNews(NewsMaterial[2], Categories[1].Id);
            Archivist.AddNews(NewsMaterial[3], Categories[2].Id);

            // Get all the news items.
            List<NewsItem> gottenNewsItems = Archivist.GetNews(new NewsQuery());

            // Calculate the term frequency of the expected news item.
            Dictionary<string, int> tf2 =
                TermUtils.CalculateTermFrequency(NewsMaterial[2].Content);

            Dictionary<string, int> expectedDictionary = tf2;

            // Create a term count query.
            TermCountQuery tcq = new TermCountQuery()
            {
                NewerThan = new DateTime(2013, 4, 27, 12, 50, 00)
            };

            Dictionary<string, int> actualDictionary = Archivist.GetIndividualTermCount(tcq);

            CollectionAssert.AreEquivalent(expectedDictionary, actualDictionary);
        }
Esempio n. 29
0
 /// <summary>
 /// Gets the sum of the term frequencies of all the terms that
 /// match the given <c>TermCountQuery</c>.
 /// </summary>
 /// <param name="termCountQuery">
 /// A <c>TermCountQuery</c> specifying the terms to get the term
 /// frequency of.
 /// </param>
 /// <returns>
 /// The sum of the term frequencies of all the terms that match
 /// the given <c>TermCountQuery</c>.
 /// </returns>
 public abstract int GetTermCount(TermCountQuery termCountQuery);
Esempio n. 30
0
 public void EqualsTestObjectReferenceEquality()
 {
     TermCountQuery o1 = new TermCountQuery();
     o1.Limit = 1;
     TermCountQuery o2 = new TermCountQuery();
     o2.Limit = 1;
     Assert.IsTrue(o1.Equals((Object) o2));
 }