Beispiel #1
0
 public static void CuratorTestClassInitialize(TestContext testContext)
 {
     // Initialize the archivist.
     Archivist = new SqlCeArchivist("testDb");
     Archivist.Open();
     Archivist.TruncateData();
 }
        public static void InterestFilterTestClassInitialize(TestContext testContext)
        {
            // Initialize the archivist.
            Archivist = new SqlCeArchivist("testDb");
            Archivist.Open();
            Archivist.TruncateData();

            Filter = new RedundancyFilter();
        }
Beispiel #3
0
 static void Main(string[] args)
 {
     SqlCeArchivist a = new SqlCeArchivist(@"smallDatabase.sdf");
     a.Open();
     //NewsQuery q = new NewsQuery();
     //q.Limit = 1;
     //a.GetTfIdfVector(a.GetNews(q)[0]);
     a.TruncateData();
     string dataDir = @"C:\Users\Andreas Petersen\Documents\GitHub\NyhedsfilterP2\System\NewsTrainer\data";
     DBSeeder.SeedDatabaseWithNews(a, dataDir, 1);
     //string newsSourcesDir = @"C:\Users\mkaloer\Documents\GitHub\NyhedsfilterP2\System\NewsTrainer\sources.json";
     //DBSeeder.SeedNewsSources(a, newsSourcesDir);
     a.Close();
     return;
 }
        /// <summary>
        /// The main test method.
        /// </summary>
        public static void Test()
        {
            SqlCeArchivist archivist = new SqlCeArchivist("db.sdf");
            archivist.Open();
            archivist.TruncateData();
            string dataDir = @"C:\Users\mads\Desktop\data";
            DBSeeder.SeedDatabaseWithNews(archivist, dataDir, 500);

            // Mark sports category as interesting, business as uninteresting.
            List<Category> categories = archivist.GetCategories();
            archivist.MarkCategoryInteresting(categories.First(p => p.Name.Equals("sports")), true);
            archivist.MarkCategoryInteresting(categories.First(p => p.Name.Equals("business")), false);

            _random = new Random(42);

            // Generate lists of news items.
            List<NewsMaterial> interestingNews = new List<NewsMaterial>();
            for (int i = 0; i < 500; i++)
            {
                interestingNews.Add(GenerateNewsMaterial(true));
            }
            List<NewsMaterial> uninterestingNews = new List<NewsMaterial>();
            for (int i = 0; i < 500; i++)
            {
                uninterestingNews.Add(GenerateNewsMaterial(false));
            }
            // Add news to db and save ids.
            List<int> interestingNewsIds = archivist.AddNews(interestingNews);
            List<int> uninterestingNewsIds = archivist.AddNews(uninterestingNews);

            List<int> allNewsIds = new List<int>(interestingNewsIds);
            allNewsIds.AddRange(uninterestingNewsIds);

            // Get news to filter.
            NewsQuery query = new NewsQuery();
            query.Read = ReadStatus.Unread;
            List<NewsItem> news = archivist.GetNews(query);
            // Filter news.
            InterestFilter filter = new InterestFilter();
            news = filter.Filter(archivist, news);

            int correctCount = 0;
            int falseCount = 0;
            // Compare ids and count number of correct values.
            foreach (NewsItem item in news)
            {
                if (interestingNewsIds.Contains(item.Id))
                {
                    correctCount++;
                }
                else if (uninterestingNewsIds.Contains(item.Id))
                {
                    falseCount++;
                }
            }

            Console.WriteLine("Through filter: {0}", news.Count);
            Console.WriteLine("False positive count: {0}", falseCount);
            // Print result in console.
            Console.WriteLine("{0}/{1}={2}%", correctCount,
                interestingNews.Count,
                (double) correctCount / (interestingNews.Count) * 100.0);
            Console.ReadLine();
        }