public static int ScoreForPinyin(string source, string target) { if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(target)) { return(0); } if (source.Length > 40) { Log.Debug($"|Wox.Infrastructure.StringMatcher.ScoreForPinyin|skip too long string: {source}"); return(0); } if (!Alphabet.ContainsChinese(source)) { return(0); } FuzzyMatcher matcher = FuzzyMatcher.Create(target); var combination = Alphabet.PinyinComination(source); var pinyinScore = combination.Select(pinyin => matcher.Evaluate(string.Join("", pinyin)).Score) .Max(); var acronymScore = combination.Select(Alphabet.Acronym) .Select(pinyin => matcher.Evaluate(pinyin).Score) .Max(); var score = Math.Max(pinyinScore, acronymScore); return(score); }
public static int ScoreForPinyin(string source, string target) { if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target)) { FuzzyMatcher matcher = FuzzyMatcher.Create(target); //todo happlebao currently generate pinyin on every query, should be generate on startup/index if (Alphabet.ContainsChinese(source)) { var combination = Alphabet.PinyinComination(source); var pinyinScore = combination.Select(pinyin => matcher.Evaluate(string.Join("", pinyin)).Score) .Max(); var acronymScore = combination.Select(Alphabet.Acronym) .Select(pinyin => matcher.Evaluate(pinyin).Score) .Max(); var score = Math.Max(pinyinScore, acronymScore); return(score); } else { return(0); } } else { return(0); } }
public static int ScoreForPinyin(string source, string target) { if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target)) { FuzzyMatcher matcher = FuzzyMatcher.Create(target); if (Alphabet.ContainsChinese(source)) { var combination = Alphabet.PinyinComination(source); var pinyinScore = combination.Select(pinyin => matcher.Evaluate(string.Join("", pinyin)).Score) .Max(); var acronymScore = combination.Select(Alphabet.Acronym) .Select(pinyin => matcher.Evaluate(pinyin).Score) .Max(); var score = Math.Max(pinyinScore, acronymScore); return(score); } else { return(0); } } else { return(0); } }
private bool MatchProgram(Bookmark bookmark, FuzzyMatcher matcher) { if ((bookmark.Score = matcher.Evaluate(bookmark.Name).Score) > 0) return true; if ((bookmark.Score = matcher.Evaluate(bookmark.PinyinName).Score) > 0) return true; if ((bookmark.Score = matcher.Evaluate(bookmark.Url).Score / 10) > 0) return true; return false; }
private bool MatchProgram(Program program, FuzzyMatcher matcher) { if ((program.Score = matcher.Evaluate(program.Title).Score) > 0) return true; if ((program.Score = matcher.Evaluate(program.PinyinTitle).Score) > 0) return true; if (program.AbbrTitle != null && (program.Score = matcher.Evaluate(program.AbbrTitle).Score) > 0) return true; if (program.ExecuteName != null && (program.Score = matcher.Evaluate(program.ExecuteName).Score) > 0) return true; return false; }
private bool MatchProgram(ControlPanelItem item, FuzzyMatcher matcher) { if (item.LocalizedString != null && (item.Score = matcher.Evaluate(item.LocalizedString).Score) > 0) return true; if (item.InfoTip != null && (item.Score = matcher.Evaluate(item.InfoTip).Score) > 0) return true; if (item.LocalizedString != null && (item.Score = matcher.Evaluate(item.LocalizedString.Unidecode()).Score) > 0) return true; return false; }
public static int Score(string source, string target) { if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target)) { var matcher = FuzzyMatcher.Create(target); var score = matcher.Evaluate(source).Score; return(score); } return(0); }
/// <summary> /// Check if a candidate is match with the source /// </summary> /// <param name="source"></param> /// <param name="candidate"></param> /// <returns>Match score</returns> public static int Match(string source, string candidate) { if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(candidate)) { return(0); } FuzzyMatcher matcher = FuzzyMatcher.Create(candidate); int score = matcher.Evaluate(source).Score; if (score > 0) { return(score); } score = matcher.Evaluate(source.Unidecode()).Score; return(score); }
public static int ScoreForPinyinOrEng(string source, string target) { if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target)) { if (source.Length > 40) { Log.Debug($"|Wox.Infrastructure.StringMatcher.ScoreForPinyin|skip too long string: {source}"); return(0); } if (Alphabet.ContainsChinese(source)) { var matcher = FuzzyMatcher.Create(target); var combination = Alphabet.PinyinComination(source); return(matcher.Evaluate(combination).Score); } return(Score(source, target)); } return(0); }
private bool MatchProgram(Program program, FuzzyMatcher matcher) { var scores = new List<string> { program.Title, program.PinyinTitle, program.AbbrTitle, program.ExecuteName }; program.Score = scores.Select(s => matcher.Evaluate(s ?? string.Empty).Score).Max(); return program.Score > 0; }
private bool MatchProgram(Program program, FuzzyMatcher matcher) { program.Score = matcher.Score(program.Title); if (program.Score > 0) return true; program.Score = matcher.Score(ChineseToPinYin.ToPinYin(program.Title).Replace(" ", "")); if (program.Score > 0) return true; return false; }
private bool MatchProgram(Program program, FuzzyMatcher matcher) { if (program.AbbrTitle != null && (program.Score = matcher.Score(program.AbbrTitle)) > 0) return true; if ((program.Score = matcher.Score(program.Title)) > 0) return true; if ((program.Score = matcher.Score(program.PinyinTitle)) > 0) return true; return false; }