public void Start() { FindNumericOrSymbolic(); foreach (DataRow row in TestData.Rows) { CaseDetails cd = new CaseDetails(); cd.ID = row[row.Table.Columns.Count - 1].ToString(); cd.DecisionValue = row[row.Table.Columns.Count - 2].ToString(); Rules.Rules.ForEach(rule => { if (IsMatchingComplete(rule.Attributes, row))//Complete Match { cd.MatchingRules.Add(rule); } }); CompleteMatch.Add(cd); } //Partial Match CompleteMatch.Where(t => t.MatchingRules.Count == 0).ToList().ForEach(notMatched => { CaseDetails cd = new CaseDetails(); cd.ID = notMatched.ID; cd.DecisionValue = notMatched.DecisionValue; Rules.Rules.ForEach(rule => { int rowID = int.Parse(notMatched.ID); var row = TestData.Rows[rowID - 1]; var partialAttrib = IsMatchingPartial(rule.Attributes, row); if (partialAttrib.Count > 0) { var newRule = Helper.DeepCopy <Rule>(rule); newRule.Attributes = partialAttrib; newRule.CalculatedValue = Decision.CalculateValue(newRule); cd.MatchingRules.Add(newRule); } }); if (cd.MatchingRules.Count > 0) { PartialMatch.Add(cd); } } ); CompleteMatch.RemoveAll(t => t.MatchingRules.Count == 0); ClassifyRules(CompleteMatch); ClassifyRules(PartialMatch); }
public void WriteCasesStat() { if (Decision.PrintCasesStat) { StringBuilder stat = new StringBuilder(); var testData = TestData.AsEnumerable(); var concepts = testData.Select(t => t.Field <string>(TestData.Columns.Count - 2)).Distinct(); stat.AppendLine("\nHow cases associated with concepts were classified"); foreach (var concept in concepts) { stat.AppendFormat("Concept({0},{1}) :\n", TestData.Columns[TestData.Columns.Count - 2].ColumnName, concept); var tempData = testData.Where(t => t.Field <string>(TestData.Columns.Count - 2) == concept); var conceptNotClassCases = tempData.Where(t => !GetClassifiedIds().Exists(u => t.Field <string>(TestData.Columns.Count - 1).Equals(u))).Select(v => v.Field <string>("ID")).ToList(); var partIncorrCases = PartialMatch.Where(t => t.InCorrectlyClassified.Count > 0 && string.Equals(t.DecisionValue, concept)).Select(u => u.ID).ToList(); var partCorrCases = PartialMatch.Where(t => t.CorrectlyClassified.Count > 0 && string.Equals(t.DecisionValue, concept)).Select(u => u.ID).ToList(); var completeIncorrCases = CompleteMatch.Where(t => t.InCorrectlyClassified.Count > 0 && string.Equals(t.DecisionValue, concept)).Select(u => u.ID).ToList(); var completeCorrCases = CompleteMatch.Where(t => t.CorrectlyClassified.Count > 0 && string.Equals(t.DecisionValue, concept)).Select(u => u.ID).ToList(); stat.AppendFormat("List of cases that are not classified: \n"); stat.AppendLine(GetCases(conceptNotClassCases)); stat.AppendLine("\t PARTIAL MATCHING:"); stat.AppendFormat("List of cases that are incorrectly classified: \n"); stat.AppendLine(GetCases(partIncorrCases)); stat.AppendFormat("List of cases that are correctly classified:\n"); stat.AppendLine(GetCases(partCorrCases)); stat.AppendLine("\t COMPLETE MATCHING:"); stat.AppendFormat("List of cases that are incorrectly classified:\n"); stat.AppendLine(GetCases(completeIncorrCases)); stat.AppendFormat("List of cases that are correctly classified: \n"); stat.AppendLine(GetCases(completeCorrCases)); stat.AppendLine(); } stat.AppendLine("------------------------------------------------------------"); Console.WriteLine(stat.ToString()); } }
public void WriteConceptStat() { if (Decision.PrintConceptStat) { StringBuilder stat = new StringBuilder(); var testData = TestData.AsEnumerable(); var concepts = testData.Select(t => t.Field <string>(TestData.Columns.Count - 2)).Distinct(); stat.AppendLine("\nConcept Statistics"); foreach (var concept in concepts) { stat.AppendFormat("Concept({0},{1}) :\n", TestData.Columns[TestData.Columns.Count - 2].ColumnName, concept); var tempData = testData.Where(t => t.Field <string>(TestData.Columns.Count - 2) == concept); var conceptNotClassCount = tempData.Where(t => !GetClassifiedIds().Exists(u => t.Field <string>(TestData.Columns.Count - 1).Equals(u))).Count(); var partIncorrCount = PartialMatch.Where(t => t.InCorrectlyClassified.Count > 0 && string.Equals(t.DecisionValue, concept)).Sum(u => u.InCorrectlyClassified.Count); var partCorrCount = PartialMatch.Where(t => t.CorrectlyClassified.Count > 0 && string.Equals(t.DecisionValue, concept)).Sum(u => u.CorrectlyClassified.Count); var completeIncorrCount = CompleteMatch.Where(t => t.InCorrectlyClassified.Count > 0 && string.Equals(t.DecisionValue, concept)).Sum(u => u.InCorrectlyClassified.Count); var completeCorrCount = CompleteMatch.Where(t => t.CorrectlyClassified.Count > 0 && string.Equals(t.DecisionValue, concept)).Sum(u => u.CorrectlyClassified.Count); stat.AppendFormat("The total number of cases that are not classified: {0} \n", conceptNotClassCount); stat.AppendLine("\t PARTIAL MATCHING:"); stat.AppendFormat(" The total number of cases that are incorrectly classified: {0} \n", partIncorrCount); stat.AppendFormat(" The total number of cases that are correctly classified: {0} \n", partCorrCount); stat.AppendLine("\t COMPLETE MATCHING:"); stat.AppendFormat(" The total number of cases that are incorrectly classified: {0} \n", completeIncorrCount); stat.AppendFormat(" total number of cases that are correctly classified: {0} \n", completeCorrCount); stat.AppendFormat("The total number of cases in the concept: {0}", tempData.Count()); stat.AppendLine(); stat.AppendLine(); } stat.AppendLine("------------------------------------------------------------"); Console.WriteLine(stat.ToString()); } }