/// <summary> /// /// </summary> public List <IRankedCategory> GetTrainingSuggestions() { List <IRankedCategory> ret = new List <IRankedCategory>(); Dictionary <int, int> wordCounts = new Dictionary <int, int>(); foreach (IToken phrase in Model.Tokens) { foreach (IRank rank in phrase.Scores) { ICategory cat = Model.GetCategory(rank.Id); if (wordCounts.ContainsKey(cat.Id)) { wordCounts[cat.Id]++; } else { wordCounts.Add(cat.Id, 1); } IRankedCategory c = new RankedCategory() { Id = cat.Id, Name = cat.Name, }; int index = ret.IndexOf(c); if (index < 0) { ret.Add(c); } else { ret[index].Score++; } } } foreach (IRankedCategory cat in ret) { cat.Score = cat.Score / wordCounts[((ICategory)cat).Id]; } ret.Sort(); ret.Reverse(); return(ret); }
private void btnAddCategory_Click(object sender, EventArgs e) { string catName = null; if (InputBox.Show("Add Category", "Add a new category for this block of text", ref catName) == System.Windows.Forms.DialogResult.OK) { if (!string.IsNullOrEmpty(catName)) { var existing = categories.FirstOrDefault(c => c.Name == catName); if (existing == null) { var cat = Program.Classifier.Model.AddCategory(catName); existing = RankedCategory.FromCategory(cat); categories.Add(existing); } UpdateCategoriesPanel(true); } } }