Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加phrases选项,可选择关闭词组匹配,减少内存消耗,加快运行速度 #26

Closed
wants to merge 11 commits into from

Conversation

TooBug
Copy link

@TooBug TooBug commented Dec 12, 2014

添加phrases选项,可选择关闭词组匹配,减少内存消耗,加快运行

var options = {
    style:pinyin.STYLE_NORMAL,
    heteronym:true,
    phrases:false //这里可以选择关闭词组匹配
};
var pinyinArr = pinyin(str,options);

本机对“你好”测试结果:

开启词组匹配耗时1361ms,关闭后162ms,耗时为原来的11.9%

内存占用没下载工具定量测,从服务器上旧版本(2.2.1)来看,可减少120m左右内存消耗。

@TooBug
Copy link
Author

TooBug commented Dec 12, 2014

对了,测试那里没看懂要怎么加,好像只有phrases_test.js中有一条跟选项有关的测试,其它的测试全部是测STYLE的。

@hotoo
Copy link
Owner

hotoo commented Dec 12, 2014

对于你这种情况,我觉得只需要:

var isNode = false;

就可以了。

@TooBug
Copy link
Author

TooBug commented Dec 12, 2014

但isNode是在内部定义的,外部无法改变呀。而且isNode为false时貌似只包含精简字库?

@hotoo
Copy link
Owner

hotoo commented Dec 12, 2014

是的,常用字库。
既然你不需要分词解决多音字的问题,我想应该也比较少遇到需要生僻字的场景。

@TooBug
Copy link
Author

TooBug commented Dec 12, 2014

这个倒不一定,其实我是用在姓名匹配上,在生成拼音数据的时候这个词组库参考意义不大。但是姓名里面生僻字还是会时不时碰到的。

另外,即使如你所说,只需要isNode=false的情况,我要怎么指定呢?因为isNode是在pinyin.js中判断process,在外部影响不了。

@hotoo
Copy link
Owner

hotoo commented Dec 12, 2014

嗯,你这种情况比较特殊,我要好好想想。。

  1. 姓氏里有些多音字的读音是特别而且确定的。
  2. 名字里的多音字一般无法通过分词来解决。

现有的分词模块中有区分姓名的功能,之前就有想法针对姓名做针对性处理。

@hotoo
Copy link
Owner

hotoo commented Dec 12, 2014

你可以先使用 fork 的这份修改版。

@TooBug
Copy link
Author

TooBug commented Dec 15, 2014

OK。另外还是补充一下这个场景,我的场景中是不要求100%准确的。比如“孙行者”,我会先存下来“|sunxingzhe|sunhangzhe|”,用户查询的时候输入“孙航着”,转成“sunhangzhe”查询即可。也就是说我的使用场景中拼音是作为查询辅助依据,只要能匹配任何一种可能的音节就行,不需要100%精确。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants