public static string[] FindCitations(string text) { var stopw = new Devmasters.Core.StopWatchEx(); stopw.Start(); string[] sText = HlidacStatu.Lang.CS.Politici.Stems(text); stopw.Stop(); //Console.WriteLine($"stemmer {stopw.ExactElapsedMiliseconds} "); stopw.Restart(); List <string> found = new List <string>(); foreach (var kv in PoliticiStems) { string zkratka = kv.Item1; string[] politik = kv.Item2; for (int i = 0; i < sText.Length - (politik.Length - 1); i++) { bool same = true; for (int j = 0; j < politik.Length; j++) { if (sText[i + j] == politik[j]) { same = same & true; } else { same = false; break; } } if (same) { if (!found.Contains(zkratka)) { found.Add(zkratka); } break; } } } stopw.Stop(); //Console.WriteLine($"location {stopw.ExactElapsedMiliseconds} "); return(found.ToArray()); }
public static IEnumerable <string> FindAllIcoInMemory(string query, int limit) { string findAllIcoTimes = $"FindAllIco {query}\n"; if (string.IsNullOrEmpty(query)) { return new string[] { } } ; var items = new List <Tuple <string, decimal> >(); Devmasters.Core.StopWatchEx sw = new Devmasters.Core.StopWatchEx(); sw.Start(); var resExact = StaticData.FirmyNazvy.Get() .Where(m => m.Value.Jmeno == query) // Data.External.FirmyDB.AllFromName(query) .Select(m => new Tuple <string, decimal>(m.Key, 1m)); if (resExact.Count() > 0) { items.AddRange(resExact); } sw.Stop(); findAllIcoTimes += $"step1:{sw.ElapsedMilliseconds}\n"; string aQuery = Devmasters.Core.TextUtil.RemoveDiacritics(query).ToLower(); if (items.Count < limit) { sw.Restart(); //add more if (StaticData.FirmyNazvyOnlyAscii.ContainsKey(aQuery)) { var res = StaticData.FirmyNazvyOnlyAscii[aQuery] .Where(ico => !string.IsNullOrEmpty(ico)).Select(ico => new Tuple <string, decimal>(ico, 0.9m)) .GroupBy(g => g.Item1, v => v.Item2, (g, v) => new Tuple <string, decimal>(g, v.Max())); items.AddRange(res); } sw.Stop(); findAllIcoTimes += $"step2:{sw.ElapsedMilliseconds}\n"; } if (items.Count < limit) { sw.Restart(); //add more var res = StaticData.FirmyNazvyOnlyAscii .Where(m => m.Key.StartsWith(aQuery, StringComparison.Ordinal)) .Take(limit - items.Count) .SelectMany(m => m.Value.Where(ico => !string.IsNullOrEmpty(ico)).Select(ico => new Tuple <string, decimal>(ico, 0.5m))) .GroupBy(g => g.Item1, v => v.Item2, (g, v) => new Tuple <string, decimal>(g, v.Max())); items.AddRange(res); sw.Stop(); findAllIcoTimes += $"step3:{sw.ElapsedMilliseconds}\n"; } if (items.Count < limit && aQuery.Length >= 5) { sw.Restart(); //add more var res = StaticData.FirmyNazvyOnlyAscii .Where(m => m.Key.Contains(aQuery)) .OrderBy(m => Validators.LevenshteinDistanceCompute(m.Key, aQuery)) .Take(limit - items.Count) .Where(m => Validators.LevenshteinDistanceCompute(m.Key, aQuery) < 10) .SelectMany(m => m.Value.Where(ico => !string.IsNullOrEmpty(ico)).Select(ico => new Tuple <string, decimal>(ico, 0.5m))) .GroupBy(g => g.Item1, v => v.Item2, (g, v) => new Tuple <string, decimal>(g, v.Max())); items.AddRange(res); sw.Stop(); findAllIcoTimes += $"step4:{sw.ElapsedMilliseconds}\n"; } if (Devmasters.Core.Util.Config.GetConfigValue("LogSearchTimes") == "true") { HlidacStatu.Util.Consts.Logger.Info(findAllIcoTimes); } return(items .Take(limit) .Select(m => m.Item1)); }