public static void GetAllPersons() { var humans = new List <Human>(); var errors = new List <Tuple <int, Exception> >(); var responseBody = File.ReadAllText(WdqResponse); var wdqRequestor = new WdqRequestor(); Console.WriteLine("Getting human instance references."); var wdqResult = wdqRequestor.ResultFromString(responseBody); Console.WriteLine("Found {0} human instances.", wdqResult.items.Length); var humanFactory = new HumanFactory(); foreach (var id in wdqResult.items) { try { if (humans.Count % 10 == 0) { Console.Write("\r{0}/{1} completed.", humans.Count, wdqResult.items.Count()); } var human = humanFactory.FromEntityId(id); humans.Add(human); } catch (Exception ex) { var t = new Tuple <int, Exception>(id, ex); errors.Add(t); } } Console.WriteLine(); Console.WriteLine("{0} humans found.", humans.Count); Console.WriteLine("Writing reports."); var livingSb = new StringBuilder(); livingSb.AppendFormat("Name\tDoB\tAge\tLink"); livingSb.AppendLine(); var living = humans.Where(h => h.DateOfBirth != null && h.DateOfDeath == null).OrderByDescending(h => h.Age()); foreach (var l in living) { livingSb.AppendFormat("{0}\t{1}\t{2}\t{3}", l.Label, l.DateOfBirth, l.Age(), l.WikiLink); livingSb.AppendLine(); } File.WriteAllText("Living.txt", livingSb.ToString()); Console.WriteLine("Reports finished."); }
public static void FillCache() { var errors = new ConcurrentBag <Tuple <int, Exception> >(); var responseBody = File.ReadAllText(WdqResponse); var wdqRequestor = new WdqRequestor(); Console.WriteLine("Getting human instance references."); var wdqResult = wdqRequestor.ResultFromString(responseBody); Console.WriteLine("Found {0} human instances.", wdqResult.items.Length); var wikiDataRequestor = WikiDataRequestor.Create(); int count = 0; var partitions = new List <IEnumerable <int> >(); Parallel.ForEach(wdqResult.items, new ParallelOptions() { MaxDegreeOfParallelism = 20 }, id => { try { var humanUrl = wikiDataRequestor.GetEntityUrl(id); wikiDataRequestor.WebCache.FillCache(humanUrl); var c = Interlocked.Increment(ref count); if (c % 100 == 0) { Console.Write("\r{0}/{1} completed.", c, wdqResult.items.Count()); } } catch (Exception ex) { var t = new Tuple <int, Exception>(id, ex); errors.Add(t); } }); Console.WriteLine(); Console.WriteLine("{0} humans found.", count); Console.WriteLine("Cache fill finished."); }
public void Init() { requestor = new WdqRequestor(); }