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); } }
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 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); }