public static void InterestFilterTestClassInitialize(TestContext testContext) { // Initialize the archivist. Archivist = new SqlCeArchivist("testDb"); Archivist.Open(); Archivist.TruncateData(); Filter = new InterestFilter(); }
/// <summary> /// Curates undread news from the given <c>Archivist</c> instance based /// on a maximum reading time, a maximum individual item reading time /// and a limit. /// </summary> /// <param name="archivist"> /// The <c>Archivist</c> instance giving access to the news that /// should be curated. /// </param> /// <param name="limit"> /// The maximum number of news to return. /// </param> /// <param name="maxTime"> /// The maximum reading time for the curated news. /// </param> /// <param name="maxItemTime"> /// The maximum reading time per news item. /// </param> /// <returns> /// A list of unread, curated <c>NewsItem</c>s received from the /// <c>Archivist</c> instance. /// </returns> public static List<NewsItem> GetCuratedNews(Archivist archivist, int limit, int maxTime = -1, int maxItemTime = - 1) { // Get cached data and update if null. List<NewsItem> curatedNews = CachedNews; if (curatedNews == null) { // Update needed. NewsQuery query = new NewsQuery(); // Only fetch unread news. query.Read = ReadStatus.Unread; query.OrderDateDesc = true; query.Limit = 100; curatedNews = archivist.GetNews(query); // If no news was found then there's no need to filter them. if (curatedNews.Count == 0) { return curatedNews; } // Filter for interesting news. InterestFilter interestFilter = new InterestFilter(); curatedNews = interestFilter.Filter(archivist, curatedNews); // Filter redundancy. RedundancyFilter redundancyFilter = new RedundancyFilter(); curatedNews = redundancyFilter.Filter(archivist, curatedNews); // Update cache. CachedNews = curatedNews; } // Filter quantity. QuantityFilter quantityFilter = new QuantityFilter(limit, maxTime, maxItemTime); curatedNews = quantityFilter.Filter(archivist, curatedNews); // Return curated list. return curatedNews; }
/// <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(); }
public void FilterTestInterestFilterAllInteresting() { // Mark football interesting, tennis uninteresting. List<Category> categories = Archivist.GetCategories(); int sportsId = categories.First(p => p.Name.Equals("sports")).Id; int politicsId = categories.First(p => p.Name.Equals("politics")).Id; Archivist.MarkCategoryInteresting( categories.First(p => p.Name.Equals("sports")), true); Archivist.MarkCategoryInteresting( categories.First(p => p.Name.Equals("politics")), true); // Add news to list. NewsMaterial news1 = new NewsMaterial(); news1.Author = "author"; news1.Content = "Manchester United manager Sir Alex Ferguson says David Luiz deliberately got Rafael sent off in Chelsea's 1-0 win at Old Trafford on Sunday. Rafael was sent off for a kick at his Brazil team-mate, but Ferguson feels Luiz engineered the dismissal. “He then rolls about like a dying swan, and that convinces the referee” Sir Alex Ferguson on David Luiz's reaction to Rafael's kick \" [Rafael] retaliates but [Luiz] quite clearly elbows him twice,\" Ferguson told BBC's MOTD2 programme. \" He then rolls about like a dying swan, and that convinces the referee. He was smiling. That is bad.\" Ferguson added: \" What kind of professional is that?\" Chelsea interim manager Rafael Benitez said he did not see either Luiz's elbow or Rafael's retaliatory kick, but insisted such incidents were not unusual in football. \" I am not very interested,\" he said. \" I have seen 200 incidents in the Premier League this year and it will change nothing.\" A Phil Jones own goal in the 87th minute from a deflected Juan Mata shot gave Chelsea a victory that lifts them to third in the Premier League table, but Ferguson was disappointed by the lacklustre performance of his team. Why David Luiz is the long-pass master \" There is always an expectation that we should do better. We expected a better performance. After the goal we had no time to get back in the game,\" he said. Ferguson made five changes to the side that drew 1-1 with Arsenal at Emirates Stadium last week, with Ryan Giggs, Anderson and Tom Cleverley all starting and Wayne Rooney dropping to the bench. However, the United manager said the changes were no excuse for such a below-par performance against highly motivated opponents hoping to secure a Champions League place. \" It was difficult for players coming in. Chelsea had everything to play for. They [some of our players] haven't played for quite a while, but that being said, we should be doing better,\" he said. Also related to this story"; news1.Date = DateTime.Now; news1.Guid = "guid1"; news1.Publisher = "publisher"; news1.Url = new Uri("http://www.foo.bar"); news1.Summary = "summary"; news1.Title = "Sir Alex Ferguson accuses David Luiz of getting Rafael sent off"; Archivist.AddNews(news1, sportsId); NewsMaterial news2 = new NewsMaterial(); news2.Author = "author"; news2.Content = "Robin van Persie is April's Premier League Player of the Month Robin van Persie, recently overlooked for two major awards, has been named as Barclays Player of the Month for April. Bale also fought off Van Persie to land the PFA Player of the Year award. The Dutchman's six goals in April helped United to secure their 20th league title with four games to spare. Van Persie, 29, has hit 25 league goals since moving from Arsenal for £24m last August. His hat-trick in the 3-0 win against Aston Villa on 22 April saw United clinch the title ahead of Manchester City, who tried to sign Van Persie last summer. Earlier this season, City boss Roberto Mancini said his failure to land Van Persie was the difference between the two teams in the title race. United boss Sir Alex Ferguson said: \"I remember Arsenal manager Arsene Wenger saying to me 'he's better than you think' when we concluded the deal. He was right.\" Also related to this story"; news2.Date = DateTime.Now; news2.Guid = "guid2"; news2.Publisher = "publisher"; news2.Url = new Uri("http://www.foo.bar"); news2.Summary = "summary"; news2.Title = "Robin van Persie is April's Premier League Player of the Month"; Archivist.AddNews(news2, sportsId); NewsMaterial news3 = new NewsMaterial(); news3.Author = "author"; news3.Content = "Former Tory chancellor Lord Lawson calls for UK to exit EU The former chancellor of the exchequer, Lord Lawson, has called for the UK to leave the European Union. Writing in the Times, he said British economic gains from an exit \"would substantially outweigh the costs\". He predicted any changes achieved by David Cameron's attempts to renegotiate the terms of the UK's relations with the EU would be \"inconsequential\". But Downing Street said the prime minister remained \"confident\" that his strategy \"will deliver results\". Mr Cameron is facing calls to bring forward a promised referendum on the UK's EU membership. He says he will hold a vote early in the next parliament - should the Conservatives win the next general election - but only after renegotiating the terms of the UK's relationship with the EU. However, Lord Lawson said any such renegotiations would be \"inconsequential\" as \"any powers ceded by the member states to the EU are ceded irrevocably\". The BBC's political editor Nick Robinson said Lord Lawson's intervention was a \"big moment\" in the EU debate. Regulatory 'frenzy' The peer - who was Margaret Thatcher's chancellor for six years - voted to stay in the European Common Market, as the EU was known in 1975, but said: \"I shall be voting 'out' in 2017.\" He said he \"strongly\" suspected there would be a \"positive economic advantage to the UK in leaving the single market\". Continue reading the main story “Start Quote You do not need to be within the single market to be able to export to the European Union, as we see from the wide range of goods on our shelves every day” End Quote Lord Lawson Far from hitting business hard, it would instead be a wake-up call for those who had been too content in \"the warm embrace of the European single market\" when the great export opportunities lay in the developing world, particularly Asia. \"Over the past decade, UK exports to the EU have risen in cash terms by some 40%. Over the same period, exports to the EU from those outside it have risen by 75%,\" he added. Withdrawing from the EU would also save the City of London from a \"frenzy of regulatory activism\", such as the financial transactions tax that Brussels is seeking to impose. Lord Lawson said his argument had \"nothing to do with being anti-European\". \"The heart of the matter is that the very nature of the European Union, and of this country's relationship with it, has fundamentally changed after the coming into being of the European monetary union and the creation of the eurozone, of which - quite rightly - we are not a part. \"Not only do our interests increasingly differ from those of the eurozone members but, while never 'at the heart of Europe' (as our political leaders have from time to time foolishly claimed), we are now becoming increasingly marginalised as we are doomed to being consistently outvoted by the eurozone bloc.\" 'Clear timetable' At the local elections last week, the UK Independence Party - which campaigns for the UK to leave the EU - made substantial gains, while the Conservatives lost control of 10 councils. The UKIP surge prompted a call from senior Tory MP David Davis to bring forward the planned referendum - while other Conservatives, including former chairman Lord Tebbit, urged Mr Cameron to take steps to give the public more confidence that a referendum would indeed take place if he wins the next general election. Reacting to Lord Lawson's comments, a Downing Street spokesman said: \"The PM has always been clear: we need a Europe that is more open, more competitive, and more flexible; a Europe that wakes up to the modern world of competition. In short, Europe has to reform. \"But our continued membership must have the consent of the British people, which is why the PM has set out a clear timetable on this issue.\" Deputy Prime Minister Nick Clegg said that leaving the European Union would \"make us less safe because we cooperate in the European Union to go after criminal gangs that cross borders\". He said it could put 3m jobs at risk and made it difficult to deal with cross border threats like climate change and would also see Britain \"taken less seriously in Washington, Beijing, Tokyo\". Political commentator and Times' comment editor Tim Montgomerie told BBC Radio 4's Today programme the article would add fuel to the debate on Europe within the Conservative Party that Mr Cameron had hoped could wait until further down the line. \"Lord Lawson will give much more confidence to those people who do want to leave the EU to go public with those views,\" he added. "; news3.Date = DateTime.Now; news3.Guid = "guid3"; news3.Publisher = "publisher"; news3.Url = new Uri("http://www.foo.bar"); news3.Summary = "summary"; news3.Title = "Former Tory chancellor Lord Lawson calls for UK to exit EU"; Archivist.AddNews(news3, politicsId); NewsMaterial news4 = new NewsMaterial(); news4.Author = "author"; news4.Content = "David Cameron to host Somalia conference Suicide bombs remain a constant threat in Somalia Connecting capital UK Prime Minister David Cameron is to host an international conference in London to help Somalia end more than two decades of conflict. The conference will focus on rebuilding its security forces and tackling rape - a largely taboo subject in Somalia. Somalia is widely regarded as a failed state, hit by an Islamist insurgency, piracy and a famine from 2010 to 2012. At least seven people were killed in a car bomb attack in the capital, Mogadishu, on Sunday. Al-Shabab, which is part of al-Qaeda, said it carried out the attack. Tuesday's meeting - which Mr Cameron will co-host with Somalia's President Hassan Sheikh Mohamud - follows similar conferences in London and the Turkish city of Istanbul last year, amid growing international concern that Somalia has turned into a haven for al-Qaeda-linked militants. 'Dramatic change' \"I hope we can all get behind a long-term security plan - one that ends the Shabab's reign of terror forever,\" Mr Cameron said. Analysis Andrew Harding Africa correspondent A year ago, Afgoye was under the control of Somalia's Islamist militant group, al-Shabab, which held most of the countryside beyond Mogadishu. But if they have lost control of many key towns these days, al-Shabab can still cause trouble. Minutes after I'd flown into Mogadishu, a car bomb exploded up the road at a busy roundabout, killing or injuring more than 30 people. Read more from Andrew \"I also hope we can improve transparency and accountability so people know where resources are going. We also need to continue the process of rebuilding the Somali state, with all the regions of Somalia around the table and the neighbouring countries too.\" BBC Somalia analyst Mary Harper says there has been a dramatic change in the country in the past year. There is a new government - the first one in more than two decades to be recognised by the United States, the International Monetary Fund (IMF) and other key players, she says. Al-Shabab has lost control of the major towns, pirate attacks off the Somali coast have fallen dramatically and the famine, which the United Nations estimates claimed nearly 260,000 lives, is over, she adds. However, massive challenges remain, as al-Shabab still has the capacity to carry out attacks and the government depends on about 18,000 African Union (AU) troops for its security, our correspondent says. Somalia is also divided into a patchwork of self-governing regions, many of them hostile to the central government. The breakaway state of Somaliland and the semi-autonomous region of Puntland say they will boycott the conference. The conference will address an issue that was until recently completely taboo in Somalia - rape, especially of women living in camps for displaced people, our correspondent says. Somali aid worker Halima Ali Adan told the BBC the decision to tackle the issue at the conference was a big step forward. \"Sexual violence is something that was not ever spoken about in Somalia,\" she said. \"The international community themselves have seen the importance of this issue to be addressed as soon as possible because it is actually overwhelming.\" Delegates from more than 50 countries and organisations are expected to attend the meeting. On Monday, Qatar said Sunday's suicide attack in Mogadishu had targeted its officials, Qatar's official QNA news agency reported. The four officials were travelling in armoured vehicles belonging to the Somali government when the convoy was attacked, it said. None of the Qatari nationals were injured, QNA reported. However, 10 other people were wounded in the attack, according to a BBC correspondent in Mogadishu. More on This Story"; news4.Date = DateTime.Now; news4.Guid = "guid4"; news4.Publisher = "publisher"; news4.Url = new Uri("http://www.foo.bar"); news4.Summary = "summary"; news4.Title = "David Cameron to host Somalia conference"; Archivist.AddNews(news4, politicsId); // Fetch items from database. NewsQuery query = new NewsQuery(); query.Limit = 4; query.NewerThan = DateTime.Now.Subtract(new TimeSpan(2, 0, 0)); List<NewsItem> news = Archivist.GetNews(query); List<NewsItem> expected = news; InterestFilter filter = new InterestFilter(); List<NewsItem> sortedList = filter.Filter(Archivist, news); CollectionAssert.AreEqual(expected, sortedList); }