Refactoring pinyin

1. use custom patched pinyin library Pinyin4Net
2. fix memory leak on startup: 360mb -> 160mb when using vs15 debugger
This commit is contained in:
bao-qian
2016-04-24 00:37:25 +01:00
parent 952b5fab89
commit b600bce23f
16 changed files with 198 additions and 691 deletions

View File

@@ -9,24 +9,7 @@ namespace Wox.Plugin.Program
public class Program
{
private static readonly Regex AbbrRegexp = new Regex("[^A-Z0-9]", RegexOptions.Compiled);
private string m_Title;
public string Title
{
get
{
return m_Title;
}
set
{
m_Title = value;
string pinyin = m_Title.Unidecode();
PinyinTitle = pinyin;
AbbrTitle = AbbrRegexp.Replace(Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(pinyin), "");
if (AbbrTitle.Length < 2) AbbrTitle = null;
}
}
public string PinyinTitle { get; private set; }
public string AbbrTitle { get; private set; }
public string Title { get; set; }
public string IcoPath { get; set; }
public string ExecutePath { get; set; }
public string ExecuteName { get; set; }

View File

@@ -50,33 +50,34 @@ namespace Wox.Plugin.Program
public List<Result> Query(Query query)
{
var fuzzyMather = FuzzyMatcher.Create(query.Search);
var results = _programs.AsParallel()
.Where(p => MatchProgram(p, fuzzyMather))
.Where(p => Score(p, query.Search) > 0)
.Select(ScoreFilter)
.OrderByDescending(p => p.Score)
.Select(c => new Result
.Select(p => new Result
{
Title = c.Title,
SubTitle = c.ExecutePath,
IcoPath = c.IcoPath,
Score = c.Score,
ContextData = c,
Title = p.Title,
SubTitle = p.ExecutePath,
IcoPath = p.IcoPath,
Score = p.Score,
ContextData = p,
Action = e =>
{
var hide = StartProcess(new ProcessStartInfo(c.ExecutePath));
var hide = StartProcess(new ProcessStartInfo(p.ExecutePath));
return hide;
}
}).ToList();
return results;
}
private bool MatchProgram(Program program, FuzzyMatcher matcher)
private int Score(Program program, string query)
{
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;
var score1 = StringMatcher.Score(program.Title, query);
var score2 = StringMatcher.ScoreForPinyin(program.Title, query);
var score3 = StringMatcher.Score(program.ExecuteName, query);
var score = new[] {score1, score2, score3}.Max();
program.Score = score;
return score;
}
public void Init(PluginInitContext context)