public bool CheckMatchByStringCompare(RowPrototype objOther) { int intCountSame = 0; string strOtherId = objOther.m_strIdString; for (int i = 0; i < Math.Min(strOtherId.Length, MyIdString.Length); ++i) { if (strOtherId[i] == m_strIdString[i]) { ++intCountSame; } } if (((double)intCountSame / (double)MyIdString.Length) > 0.8f) return true; else return false; }
//move to engine /// <summary> /// creats a report based on counting repetitions of the same lines /// saves the report to a Cvs file /// </summary> /// <param name="csvFileName"></param> /// <param name="method"></param> private void GenerateReport(string csvFileName, ReportGenMethod method) { List<RowPrototype> colProts = new List<RowPrototype>(); foreach (var drRow in _dvMainView) { string strRowStr = drRow.Info + drRow.ErrorInfo; RowPrototype objFoundPrototype = null; //test each row on the prototypes we have seen until now RowPrototype currRow = new RowPrototype(drRow); foreach (RowPrototype prototype in colProts) { bool isMatch = false; if (method == ReportGenMethod.ByTrigram) isMatch = prototype.CheckMatchByTrigrams(currRow); else if (method == ReportGenMethod.ByStringCompare) isMatch = prototype.CheckMatchByStringCompare(currRow); if (isMatch) { ++prototype.MyCount; objFoundPrototype = prototype; break; } } //new prototype found if (objFoundPrototype == null) { RowPrototype prot1 = new RowPrototype(drRow); colProts.Add(prot1); } } colProts.Sort((Comparison<RowPrototype>)delegate(RowPrototype a, RowPrototype b) { return -a.MyCount.CompareTo(b.MyCount); }); ExportToCsvFile(csvFileName, colProts); }
public bool CheckMatchByTrigrams(RowPrototype objOther) { int intCountSame = 0; Dictionary<string, int> colOtherTrigrams = objOther.m_colTrigrams; foreach (string tri in m_colTrigrams.Keys) { if (colOtherTrigrams.ContainsKey(tri) && colOtherTrigrams[tri] == m_colTrigrams[tri]) { ++intCountSame; } } if (((double)intCountSame / (double)colOtherTrigrams.Count) > 0.8f) return true; else return false; }