🦮 Keep it simple, and stupid.
🐂 保持简单,保持拙朴。
prettier 是毫无品味的程序员的裹脚布。
:cn: 汉字拼音 ➜ hàn zì pīn yīn
Home Page: https://pinyin.js.org/
建立在 localeCompare()
以中文拼音顺序排序的基础上(如果这个可靠性不能保证,崩塌)。
关键字序列
。A
与排序后的关键字序列 B
进行 localeCompare()
比较,找到 A 在 B 序列中的位置,并由此得到 A 的拼音。localeCompare()
可靠性问题,及 locale 参数支持程度。web页面上的demo无法运行,貌似是找不到url这个模块呢。。
好像没有实例页面。我的项目不是用nodejs写,该怎么引用,求指教
total 88
drwxr-xr-x 17 fdhuang staff 578B Nov 19 13:36 .
drwxr-xr-x 4 fdhuang staff 136B Nov 19 13:36 ..
-rw-r--r-- 1 fdhuang staff 5.0K Aug 23 08:29 .eslintrc
-rw-r--r-- 1 fdhuang staff 56B Oct 22 2014 .npmignore
-rw-r--r-- 1 fdhuang staff 2.4K Aug 25 09:33 CHANGELOG.md
-rw-r--r-- 1 fdhuang staff 1.9K Aug 25 09:36 Makefile
-rw-r--r-- 1 fdhuang staff 4.4K Aug 4 08:42 README-us_EN.md
-rw-r--r-- 1 fdhuang staff 5.0K Aug 4 08:42 README.md
drwxr-xr-x 17 fdhuang staff 578B Nov 19 13:35 _site
drwxr-xr-x 3 fdhuang staff 102B Aug 24 10:12 bin
drwxr-xr-x 6 fdhuang staff 204B Nov 19 13:35 coverage
drwxr-xr-x 3 fdhuang staff 102B Jun 9 07:44 dist
drwxr-xr-x 3 fdhuang staff 102B Aug 24 10:12 examples
-rw-r--r-- 1 fdhuang staff 43B Aug 24 10:12 index.js
drwxr-xr-x 4 fdhuang staff 136B Nov 19 13:36 node_modules
-rw-r--r-- 1 fdhuang staff 1.9K Nov 19 13:36 package.json
drwxr-xr-x 9 fdhuang staff 306B Nov 19 13:36 src
This file is large 8029.931 kb
but
https://github.com/hotoo/pinyin/blob/master/tools/dict/error.log
Last login: Mon Feb 17 11:56:33 on ttys004
[hotoo@hotoo node-pinyin]$make dict-node
404, Not Matched. 0x3404 㐄 http://www.zdic.net/z/e/js/3404.htm
404, Not Matched. 0x3403 㐃 http://www.zdic.net/z/e/js/3403.htm
404, Not Matched. 0x3415 㐕 http://www.zdic.net/z/e/js/3415.htm
404, Not Matched. 0x341b 㐛 http://www.zdic.net/z/e/js/341b.htm
404, Not Matched. 0x3420 㐠 http://www.zdic.net/z/e/js/3420.htm
404, Not Matched. 0x3427 㐧 http://www.zdic.net/z/e/js/3427.htm
404, Not Matched. 0x342a 㐪 http://www.zdic.net/z/e/js/342a.htm
404, Not Matched. 0x342e 㐮 http://www.zdic.net/z/e/js/342e.htm
404, Not Matched. 0x342f 㐯 http://www.zdic.net/z/e/js/342f.htm
404, Not Matched. 0x3434 㐴 http://www.zdic.net/z/e/js/3434.htm
404, Not Matched. 0x3435 㐵 http://www.zdic.net/z/e/js/3435.htm
404, Not Matched. 0x3436 㐶 http://www.zdic.net/z/e/js/3436.htm
404, Not Matched. 0x343d 㐽 http://www.zdic.net/z/e/js/343d.htm
404, Not Matched. 0x343f 㐿 http://www.zdic.net/z/e/js/343f.htm
404, Not Matched. 0x3441 㑁 http://www.zdic.net/z/e/js/3441.htm
404, Not Matched. 0x3446 㑆 http://www.zdic.net/z/e/js/3446.htm
404, Not Matched. 0x344c 㑌 http://www.zdic.net/z/e/js/344c.htm
404, Not Matched. 0x3450 㑐 http://www.zdic.net/z/e/js/3450.htm
At least it's not ok to be put into npm module. I think it's better to remove it from the repo:
http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-git-repo
测试了下虽然性能不错,但对于经常要查询拼音的应用,最好还是后端有个DB异步查询。是否可以加入Redis或Mongodb做为字典存储的功能?
nodejs下,转换四个汉字比如“新建文档”需要1秒左右,有提高的空间吗
code: wordsGroups = pinyin(hanzi, { heteronym: true, style: pinyin.STYLE_NORMAL })
下载的时候发现哈希值不对...
npm http GET https://registry.npmjs.org/pinyin
npm http 304 https://registry.npmjs.org/pinyin
npm http GET https://registry.npmjs.org/pinyin/-/pinyin-2.3.0.tgz
npm http 200 https://registry.npmjs.org/pinyin/-/pinyin-2.3.0.tgz
npm ERR! Error: shasum check failed for C:\Users\ADMINI~1\AppData\Local\Temp\npm-10888-PvyKzWjp\1400
305010327-0.3144137696363032\tmp.tgz
npm ERR! Expected: c33d179d6edebee2a82c06f8c7e2750f0ec080df
npm ERR! Actual: 26ddf7356672b9aa8810f88a6e977eca85d39906
npm ERR! From: https://registry.npmjs.org/pinyin/-/pinyin-2.3.0.tgz
[root@pan miniyunjs]# npm install pinyin
npm WARN engine [email protected]: wanted: {"node":"0.10.x"} (current: > {"node":"2.2.1","npm":"2.11.0"})
|
[email protected] install /home/data/miniyunjs/node_modules/pinyin/node_modules/nodejieba
node-gyp rebuild
make: Entering directory `/home/data/miniyunjs/node_modules/pinyin/node_modules/nodejieba/build'
CXX(target) Release/obj.target/segment/src/segment.o
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algobase.h:66,
from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/string:42,
from ../node_modules/nan/nan.h:37,
from ../src/utils.h:6,
from ../src/mix_segment.h:4,
from ../src/segment.cpp:1:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h: In constructor ‘std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U1 = size_t&, _U2 = long int, _T1 = long unsigned int, _T2 = const CppJieba::DictUnit*]’:
../src/CppJieba/Trie.hpp:101: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h:90: 错误:从类型‘long int’到类型‘const CppJieba::DictUnit*’的转换无效
make: *** [Release/obj.target/segment/src/segment.o] 错误 1
make: Leaving directory `/home/data/miniyunjs/node_modules/pinyin/node_modules/nodejieba/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/data/iojs-v2.2.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:199:12)
gyp ERR! System Linux 2.6.32-504.16.2.el6.x86_64
gyp ERR! command "/home/data/iojs-v2.2.1-linux-x64/bin/iojs" "/home/data/iojs-v2.2.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/data/miniyunjs/node_modules/pinyin/node_modules/nodejieba
gyp ERR! node -v v2.2.1
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok
npm ERR! Linux 2.6.32-504.16.2.el6.x86_64
npm ERR! argv "/home/data/iojs-v2.2.1-linux-x64/bin/iojs" "/usr/local/bin/npm" "install" "pinyin"
npm ERR! node v2.2.1
npm ERR! npm v2.11.0
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the nodejieba package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls nodejieba
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/data/miniyunjs/npm-debug.log
npm WARN engine [email protected]: wanted: {"node":"0.10.x"} (current: {"node":"0.12.0","npm":"2.5.1"})
-
> [email protected] install /home/rccoder/code/HIT-International/node_modules/pinyin/node_modules/nodejieba
> node-gyp rebuild
child_process: customFds option is deprecated, use stdio instead.
Usage: gyp_main.py [options ...] [build_file ...]
gyp_main.py: error: no such option: --no-parallel
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 2
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:343:16)
gyp ERR! stack at ChildProcess.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
gyp ERR! System Linux 3.19.0-18-generic
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/rccoder/code/HIT-International/node_modules/pinyin/node_modules/nodejieba
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok
npm ERR! Linux 3.19.0-18-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "pinyin"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the nodejieba package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls nodejieba
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/rccoder/code/HIT-International/npm-debug.log
IDE总是试图索引这些巨大无比的js,
这些不是代码,是数据
有不依赖Seajs的版本或者编译选项嗎?
或者node版本做成像别的库那种兼容web和node的方式也成.现在node版本直接外部依赖segment,所以也不太容易手工改成web版本.
当使用无声调的几种转换模式的时候
[āáǎà] 这几个字符会直接在结果中输出,并不会转化为a
我使用的是压缩过的字典,并工作在NodeJS环境下
这是否是一个BUG呢
Web 版目前是根据国家教育部发布的 《现代汉语常用字表》 收录的 2500个常用字,和 1000个次常用字表来做的字典,这导致很多不在常用和次常用字表中,但仍然挺常用的字无法进行转换。
考虑到实用性,计划扩充 Web 版的拼音库:
如果有需要,可以回复本 issue,或者提交新的 issue 来讨论其他的非常用字是否默认添加到拼音库中。
另外你也可以自行处理这些非常用字。
之前自己搜集了汉字包括拼音和注音、笔顺、部首、结构分析、异体字、五笔码、仓颉码等等方面的数据,虽然多出来的部分已经不在拼音的范畴内,传上来看能不能用得上,做扩展插件或者加强版之类的。
非常感谢这个项目!
http://pan.baidu.com/s/1dFcM5iD
2017.03.30 更新了一次,修正了一些数据中的错误。
如果不需要的话请管理员删除。
便宜,biàn yí
词库是一个长期维护的过程。( http://www.atool.org/hanzi2pinyin.php )
{ city: 'zhongqing', text: '重庆', code: 500100, jp: 'zq' },
当包含"数字+套"字时 前者无法正确转换为缩写和拼音
例如:
0套价 -> 0套j 而不是 0tj
将拼音库中同音字进行合并。多音字多个拼音算一个拼音进行合并,避免多音字的多个拼音优先级不同,无法将更常用的拼音放在前面进行匹配。
每个汉字的拼音独立存储,334KB.
完全同音的汉字进行合并存储,115KB.
所有同音字合并存储(多音字的各个读音拆分合并),81KB.
因为pinyin/src/phrases-dict.js
中有这一航
···
"朝阳": [["zhāo"], ["yáng"]],
···
所以chao2 yang2不能找到“朝阳”,只有zhao yang才能找到“朝阳”。
**有好几个城市都有“朝阳区”,习惯上这些区都被叫做chao2 yang2区,而不是zhao1 yang2区。
删掉这一行能解决这个问题。
> pinyin = require('pinyin');
{ [Function: pinyin]
STYLE_NORMAL: 0,
STYLE_TONE: 1,
STYLE_TONE2: 2,
STYLE_INITIALS: 3,
STYLE_FIRST_LETTER: 4 }
> pinyin('经济'); // prints invalid pinyin below
[ [ 'jīngjì' ] ]
>
## here's a grep of invalid pinyin lookups
Darwin 2 kaizhu@kais-MacBook-Air:/tmp/node_modules/pinyin $ shGrep grave
./src/phrases-dict.js:7196:"节烈": [["jiéliè"]],
./src/phrases-dict.js:7517:"经济": [["jīngjì"]],
./src/phrases-dict.js:10697:"强韧": [["qiángrèn"]],
./src/phrases-dict.js:12421:"说话": [["shuōhuà"]],
./src/phrases-dict.js:15890:"怨毒": [["yuàndú"]],
./src/phrases-dict.js:17052:"撰著": [["zhuànzhù"]],
./tools/dict/dict-ci.js:8648:"额定": ["édìng"],
./tools/dict/dict-ci.js:17387:"节烈": ["jiéliè"],
./tools/dict/dict-ci.js:18056:"经济": ["jīngjì"],
./tools/dict/dict-ci.js:18652:"跼促": ["júcù"],
./tools/dict/dict-ci.js:21645:"凌驾": ["língjià"],
./tools/dict/dict-ci.js:24657:"涅槃": ["nièpán"],
./tools/dict/dict-ci.js:25698:"嘌呤": ["piàolíng"],
./tools/dict/dict-ci.js:27018:"强韧": ["qiángrèn"],
./tools/dict/dict-ci.js:28866:"三废": ["sān-fèi"],
./tools/dict/dict-ci.js:32093:"说话": ["shuōhuà"],
./tools/dict/dict-ci.js:35466:"未定": ["wèidìng"],
./tools/dict/dict-ci.js:42335:"怨毒": ["yuàndú"],
./tools/dict/dict-ci.js:44660:"众望": ["zhòngwàng"],
./tools/dict/dict-ci.js:45315:"撰著": ["zhuànzhù"],
./tools/dict/dict-ci.js:47525:"报话机": ["bàohuàjī"],
./tools/dict/dict-ci.js:62077:"警惕性": ["jǐngtìxìng"],
Darwin 2 kaizhu@kais-MacBook-Air:/tmp/node_modules/pinyin $
安装spm实在太慢,依赖太重
在nodejs版可以
基本信息
只有一个“不”字或“不”字后面紧接着的字为非第四声时,读音为四声bù;
例如:不(bù)法(fǎ)之徒
但是如果后面的字也是四声,需要变调,变成bú。
例如:不(bú)是;不(bú)对
但从标音角度讲,变调不应作为一种标音规则,不(bù)才是正确的标音。
这样大家能方便地选择不同的库,个人认为比较有意义.
现在依赖的node-jieba需要node-gyp,在Windows环境中非常麻烦。实际上很多应用可能并不需要分词,是否可以考虑提供一个不包含分词的npm包?比如名为pinyin-lite之类的。
非常感谢!
这要是完善了用处可大了啊。
pinyin("新闻",{style: pinyin.STYLE_INITIALS})
[ [ 'x' ], [ '' ] ]
0: Array[1]
0: "重"
length: 1
proto: Array[0]
1: Array[1]
0: "点"
length: 1
proto: Array[0]
http://registry.npmjs.org/pinyin/2.3.1 上声明的是 "shasum": "5e2937083d2ab706331ed68a07ce9e4c691b8963" , 但下载下来实际是
$ shasum pinyin-2.3.1.tgz 03ec304233ddbc76b94bf1c2e11c3f328881d224 pinyin-2.3.1.tgz
$ npm install pinyin
npm http GET https://registry.npmjs.org/pinyin
npm http 200 https://registry.npmjs.org/pinyin
npm http GET https://registry.npmjs.org/pinyin/-/pinyin-2.3.1.tgz
npm http 200 https://registry.npmjs.org/pinyin/-/pinyin-2.3.1.tgz
npm ERR! Error: shasum check failed for /var/folders/5h/x4h0t8rs6w300g_wnzbx47km0000gn/T/npm-20912-4Ei4eW63/1401180705236-0.6836859425529838/tmp.tgz
npm ERR! Expected: 5e2937083d2ab706331ed68a07ce9e4c691b8963
npm ERR! Actual: 03ec304233ddbc76b94bf1c2e11c3f328881d224
npm ERR! at /Users/mk2/node_modules/npm/node_modules/sha/index.js:38:8
npm ERR! at ReadStream.<anonymous> (/Users/mk2/node_modules/npm/node_modules/sha/index.js:85:7)
npm ERR! at ReadStream.EventEmitter.emit (events.js:126:20)
npm ERR! at _stream_readable.js:895:16
npm ERR! at process._tickCallback (node.js:339:11)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! System Darwin 13.2.0
npm ERR! command "node" "/Users/mk2/node_modules/.bin/npm" "install" "pinyin"
npm ERR! cwd /private/tmp
npm ERR! node -v v0.11.12
npm ERR! npm -v 1.4.6
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /private/tmp/npm-debug.log
npm ERR! not ok code 0
这个是怎么回事儿
在词组字典中找到记录后,也加上toFixed处理
function phrases_pinyin(phrases, options){
options = extend(DEFAULT_OPTIONS, options);
if(PHRASES_DICT.hasOwnProperty(phrases)){
pinyins = PHRASES_DICT[phrases];
for (var i in pinyins) {
pinyins[i] = toFixed(pinyins[i], options.style);
}
return pinyins;
}
var py = [];
for(var i=0,l=phrases.length; i<l; i++){
py.push(single_pinyin(phrases[i], options));
}
return py;
}
知道这是什么原因吗?
汉字“哦”,返回结果依旧汉字“哦”
类似香港特别行政区
的这些专有名词词库,作者是建库不完整,还是什么?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.