public bool Load(MySqlDataManipulator manipulator, int companyId) { if (ContainedGroups.Count > 0) { ContainedGroups.Clear(); } List <KeywordGroupEntry> toLoad = manipulator.GetCompanyComplaintGroups(companyId); if (toLoad == null) { return(false); } foreach (KeywordGroupEntry entry in toLoad) { string def = entry.GroupDefinition; string[] definition = def.Split(" "); KeywordGroup g = new KeywordGroup(definition[0]); for (int i = 1; i < definition.Length; i++) { g.SelectedKeywords.AddKeyword(definition[i]); } ContainedGroups.Add(g); } return(true); }
public double CalculateSimilarityScore(KeywordGroup otherGroup) { double ret = 0; foreach (ClaimableKeywordExample x in ContainedMembers) { if (otherGroup.ContainedMembers.Contains(x)) { ret += 1; } } return(ret / ContainedMembers.Count); }
/**<summary>Generates all sub groups of the current group. A sub group is created if a quarter of the keywords contained within its examples are the same. If so, * then those keywords are added to its definition, and it becomes a new group. As a note, its parent group still exists as well.</summary>*/ public List <KeywordGroup> GenerateSubGroups(int maxGroupSize, double minimumMembers) { double globalThreshold = .25; HashSet <KeywordGroup> ret = new HashSet <KeywordGroup>(); foreach (string keyword in ContainedKeywords.Keys) { if (!SelectedKeywords.Contains(keyword)) { if (ContainedKeywords[keyword] / (double)ContainedMembers.Count >= globalThreshold) { var keywords = SelectedKeywords.ContainedKeywords; keywords.MoveNext(); KeywordGroup temp = new KeywordGroup(keywords.Current); while (keywords.MoveNext()) { temp.SelectedKeywords.AddKeyword(keywords.Current); } temp.SelectedKeywords.AddKeyword(keyword); temp.UpdateMembers(ContainedMembers); if (temp.ContainedMembers.Count < minimumMembers) { temp.DeleteClaims(); continue; } foreach (KeywordGroup tempSubGroup in temp.GenerateSubGroups(maxGroupSize, minimumMembers)) { if (!ret.Add(tempSubGroup)) { tempSubGroup.DeleteClaims(); } } ret.Add(temp); } } } return(new List <KeywordGroup>(ret)); }
private static KeywordGroup RetrieveGroupWithLeastSimilarity(Dictionary <KeywordGroup, Dictionary <KeywordGroup, double> > rankingDictionaries) { KeywordGroup leastSimilarGroup = null; double minimumSimilarity = double.MaxValue; foreach (KeyValuePair <KeywordGroup, Dictionary <KeywordGroup, double> > topPair in rankingDictionaries) { double totalSimilarity = 0.0; foreach (KeyValuePair <KeywordGroup, double> similarityPair in topPair.Value) { if (similarityPair.Value == -1) { continue; } totalSimilarity += similarityPair.Value; } if (totalSimilarity < minimumSimilarity) { minimumSimilarity = totalSimilarity; leastSimilarGroup = topPair.Key; } } return(leastSimilarGroup); }
public GroupSimilarity(KeywordGroup groupIn, double similarity) { ContainedGroup = groupIn; Similarity = similarity; }