private void t_Tick(object sender, EventArgs e) { t.Enabled = false; var len = inputWords.Count; var entity = inputWords[r.Next(len)]; var s = entity.sentenses[r.Next(entity.sentenses.Count)]; var original_s = s; bool doModify = (r.Next(2) == 0); if (doModify && tbMAXMistakes.Value > 0) { s = swapWords(s, r.Next(tbSWwords.Value + 1)); if (LevenshteinDistance.Compute(original_s, s) < tbMAXMistakes.Value) { s = swapChars(s, r.Next(tbSWchars.Value + 1)); } if (LevenshteinDistance.Compute(original_s, s) < tbMAXMistakes.Value) { s = changeChars(s, r.Next(tbRchars.Value + 1)); } } if (LevenshteinDistance.Compute(original_s, s) < tbMAXMistakes.Value) { s = addWordsAtTheEnd(s, r.Next(tbAWend.Value + 1)); } if (LevenshteinDistance.Compute(original_s, s) < tbMAXMistakes.Value) { s = addWordsAtTheBegin(s, r.Next(tbAWstart.Value + 1)); } if (LevenshteinDistance.Compute(original_s, s) < tbMAXMistakes.Value) { s = addWordsAtTheCenter(s, r.Next(tbAWmiddle.Value + 1)); } comparers.ForEach(fe => { var sw = Stopwatch.StartNew(); ICompareResult result = null; for (var i = 0; i < 10; ++i) { result = fe.search(s); } sw.Stop(); this.results.Add(new SearchResult { isModified = true, method = fe, originalEntity = entity, result = result, sentense = original_s, ms = sw.ElapsedMilliseconds, founded = entity.id == (result?.BestResult?.id ?? Guid.Empty) }); }); l.Text = $"There are {this.results.Count} results "; { var lr = this.results.Where(w => w.method.name == "LevenshtainComparer").ToList(); var founded = (double)lr.Where(w => w.founded).Count() / (double)lr.Count * 100; var atime = (double)lr.Sum(s1 => s1.ms) / (double)lr.Count; ll.Text = $"Levenshtain: Average time: { atime:0.00}, founded: {founded:0.00}%"; } { var lr = this.results.Where(w => w.method.name == "Sift4DistanceComparer").ToList(); var founded = (double)lr.Where(w => w.founded).Count() / (double)lr.Count * 100; var atime = (double)lr.Sum(s1 => s1.ms) / (double)lr.Count; d4.Text = $"Sift4DistanceComparer: Average time: { atime:0.00}, founded: {founded:0.00}%"; } { var lr = this.results.Where(w => w.method.name == "CompareOrdinalComparer").ToList(); var founded = (double)lr.Where(w => w.founded).Count() / (double)lr.Count * 100; var atime = (double)lr.Sum(s1 => s1.ms) / (double)lr.Count; lco.Text = $"CompareOrdinalComparer: Average time: { atime:0.00}, founded: {founded:0.00}%"; } { var lr = this.results.Where(w => w.method.name == "JaroWinklerComparer").ToList(); var founded = (double)lr.Where(w => w.founded).Count() / (double)lr.Count * 100; var atime = (double)lr.Sum(s1 => s1.ms) / (double)lr.Count; lJaro.Text = $"JaroWinklerComparer: Average time: { atime:0.00}, founded: {founded:0.00}%"; } { var lr = this.results.Where(w => w.method.name == "HammingComparer").ToList(); var founded = (double)lr.Where(w => w.founded).Count() / (double)lr.Count * 100; var atime = (double)lr.Sum(s1 => s1.ms) / (double)lr.Count; lHamm.Text = $"HammingComparer: Average time: { atime:0.00}, founded: {founded:0.00}%"; } { var lr = this.results.Where(w => w.method.name == "DamerauLevenshteinComparer").ToList(); var founded = (double)lr.Where(w => w.founded).Count() / (double)lr.Count * 100; var atime = (double)lr.Sum(s1 => s1.ms) / (double)lr.Count; lDamer.Text = $"DamerauLevenshteinComparer: Average time: { atime:0.00}, founded: {founded:0.00}%"; } { var lr = this.results.Where(w => w.method.name == "SorensenDiceComparer").ToList(); var founded = (double)lr.Where(w => w.founded).Count() / (double)lr.Count * 100; var atime = (double)lr.Sum(s1 => s1.ms) / (double)lr.Count; lBitap.Text = $"SorensenDiceComparer: Average time: { atime:0.00}, founded: {founded:0.00}%"; } t.Enabled = true; }
private static int CompareItemsForFinalSorting(ICompareResult x, ICompareResult y) { if (x == null) { if (y == null) { return(0); } else { return(-1); } } else { if (y == null) { return(1); } return(((int)x.Action == (int)y.Action) ? 0 : (((int)x.Action < (int)y.Action) ? -1 : 1)); //// this is less efficient, however, this technique will work with concepts beyond enums... //// notice this is built backwards, next time reverse the values(-1,1) and build the switch/if..else statements in order. //switch (x.Action) //{ // case CompareAction.Remove: // if (y.Action == CompareAction.Remove) { return 0; } // return 1; // case CompareAction.Update: // if (y.Action == CompareAction.Update) { return 0; } // if (y.Action == CompareAction.Remove) { return -1; } // return 1; // case CompareAction.Old: // if (y.Action == CompareAction.Old) { return 0; } // if (y.Action == CompareAction.Remove) { return -1; } // if (y.Action == CompareAction.Update) { return -1; } // return 1; // case CompareAction.New: // if (y.Action == CompareAction.New) { return 0; } // if (y.Action == CompareAction.Remove) { return -1; } // if (y.Action == CompareAction.Update) { return -1; } // if (y.Action == CompareAction.Old) { return -1; } // return 1; // case CompareAction.Ok: // if (y.Action == CompareAction.Ok) { return 0; } // if (y.Action == CompareAction.Remove) { return -1; } // if (y.Action == CompareAction.Update) { return -1; } // if (y.Action == CompareAction.Old) { return -1; } // if (y.Action == CompareAction.New) { return -1; } // return 1; // case CompareAction.Unknown: // if (y.Action == CompareAction.Unknown) { return 0; } // if (y.Action == CompareAction.Remove) { return -1; } // if (y.Action == CompareAction.Update) { return -1; } // if (y.Action == CompareAction.Old) { return -1; } // if (y.Action == CompareAction.New) { return -1; } // if (y.Action == CompareAction.Ok) { return -1; } // return 1; // technically, this line should be unreachable. // default: // return 1; // technically, this line should be unreachable. //} } }