static IList <Entity> FilterTransactions(IEnumerable <Transaction> transactions, string description, double threshold) { // Load up our dictinoary of canonized names var wordParser = new KeywordParser("Data/Aliases.csv"); var keywords = wordParser.Parse(description); var matches = new List <Transaction>(); Console.WriteLine("Filtering transactions..."); foreach (var item in transactions) { if (String.IsNullOrWhiteSpace(item.Name)) { continue; } var words = wordParser.Parse(item.Name); if (words.Length > 0 && words.KeywordMatch(keywords) >= threshold) { matches.Add(item); } } var results = new List <Entity>(); Console.WriteLine("Aggregating transactions..."); var groups = matches.GroupBy(i => i.filer_id); foreach (var group in groups) { var entity = new Entity { Keywords = keywords, Transactions = group.ToList() }; results.Add(entity); } #if DEBUG DumpEntities(results); #endif return(results); }
static List <Entity> AggregateTransactionsByDonor(IEnumerable <Transaction> transactions) { var results = new List <Entity>(); var count = transactions.Count(); int i = 0; // Load up our dictinoary of canonized names var wordParser = new KeywordParser("Data/Aliases.csv"); using (var progress = new ProgressBar()) { Console.Write("Aggregating transactions..."); foreach (var item in transactions) { var words = wordParser.Parse(item.Description); if (words.Length > 0) { var entity = BestEntityMatch(results, words, 0.8); if (entity == null) { // If no good entity match, create a new one entity = new Entity { Keywords = words, Transactions = new List <Transaction>() }; results.Add(entity); } entity.Transactions.Add(item); } progress.Report((double)++i / count); } Console.WriteLine("Done.\n"); #if DEBUG DumpEntities(results); #endif } return(results); }