public static double isMatched(int matched, int searchLen, int nameLen, fuzzinesSettings f = null) { if (f == null) { return(matched == searchLen ? 1000 : 0); } double rez = 0; rez = nameLen > searchLen ? 1000 - (f.times_coef * (nameLen / searchLen)) - (f.length_diff_coef * (nameLen - searchLen)) : 1000 - (f.times_coef * (searchLen / nameLen)) - (f.length_diff_coef * (searchLen - nameLen)); if (matched >= searchLen * f.matched_to_search_length_pass) { rez = rez * ((matched * 1.0) / (searchLen * 1.0)); } else { rez = 0; } return(rez); }
public static List <TermMatch> Find(List <TermMatch> options, string name, fuzzinesSettings f, bool all = false, bool ignoreEmpty = true) { if (string.IsNullOrEmpty(name)) { return(new List <TermMatch>()); } name = name.ToLower().Trim(); var r2 = FindStartAndContain(options, name); var rez = new List <TermMatch>(); var theOne = new List <TermMatch>(); FilterByAllComponArrange(name, r2, rez, theOne, f, ignoreEmpty); if (theOne.Count == 1 && !all) { rez = theOne; } return(rez); }
public override void Process(opis message) { opis ms = SpecLocalRunAll(); var fs = new fuzzinesSettings(ms[fuzz]); message.PartitionKind = ""; message.CopyArr(Search(ms[options].ListPartitions().Select(x => new TermMatch() { term = x }).ToList(), fs, ms.V(word))); }
public static opis Search(List <TermMatch> options, fuzzinesSettings fs, string word) { var rez = SearchLogic.Find(options, word, fs, true); rez = SearchLogic.SortByRelevance(rez, word); if (rez.Count > fs.optimization_boundary) { var lim = rez.First().MatchingPoints - fs.remove_points_offset; rez = rez.Where(x => x.MatchingPoints > lim).ToList(); } opis found = new opis(); rez.ForEach(x => found.Vset(x.term, "")); return(found); }
static void FilterByAllComponArrange(string name, List <TermMatch> foundRange, List <TermMatch> rez, List <TermMatch> theOne, fuzzinesSettings f = null, bool ignoreEmpty = true) { var watch = System.Diagnostics.Stopwatch.StartNew(); var arr = NamingTransformations.SplitSearchGroupName(name); double substr_coef = f == null ? 1.5 : f.substring_coef; if (foundRange != null && foundRange.Count > 0) { foreach (var itm in foundRange) { int okcou = 0; var itmArr = NamingTransformations.SplitSearchGroupName(itm.term); okcou = NamingTransformations.Alike(arr, itm.term); double mathchPerc; if ((mathchPerc = isMatched(okcou, arr.Length, itmArr.Length, f)) > 0 && (!ignoreEmpty || itm.NotValid == 0)) { if (f != null) { itm.MatchingPoints = (int)(mathchPerc + (itm.term.ToLower().Contains(name) ? mathchPerc * substr_coef : 0)); } rez.Add(itm); if (ArraysAreEqual(itmArr, arr)) { theOne.Add(itm); } } } } watch.Stop(); var elapsedMs2 = watch.ElapsedMilliseconds; }