Skip to content

Commit

Permalink
Merge pull request #58 from hotoo/initials
Browse files Browse the repository at this point in the history
fix(initials): 'y', 'w' is not initials. fixed #57
  • Loading branch information
hotoo committed Aug 22, 2015
2 parents 8a9692e + 7c76aa5 commit 128c154
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 256 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"block-scoped-var": 0,
"brace-style": [0, "1tbs"],
"camelcase": 0,
"comma-dangle": 0,
"comma-dangle": [2, "always-multiline"],
"comma-spacing": 2,
"comma-style": 0,
"complexity": [0, 11],
Expand All @@ -146,7 +146,7 @@
"guard-for-in": 0,
"handle-callback-err": 0,
"indent": 0,
"key-spacing": [2, {
"key-spacing": [0, {
"beforeColon": false,
"afterColon": true
}],
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ test-npm:
./node_modules/.bin/_mocha \
-- \
--harmony \
--require should \
--reporter spec \
--timeout 2000 \
--inline-diffs \
Expand All @@ -51,7 +52,7 @@ test-spm:
@spm test

lint:
@./node_modules/eslint/bin/eslint.js ./src/pinyin.js
@./node_modules/eslint/bin/eslint.js ./src/pinyin.js ./tests/

test: lint test-spm test-npm test-cli benchmark

Expand Down
3 changes: 1 addition & 2 deletions src/dict-zi-web.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global module */
module.exports = {
"èr":"二贰",
"shí":"十时实蚀",
Expand Down Expand Up @@ -1541,5 +1540,5 @@ module.exports = {
"bó,bù":"簿",
"bìn":"鬓",
"suǐ":"髓",
"ráng":"瓤"
"ráng":"瓤",
};
2 changes: 1 addition & 1 deletion src/phonetic-symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ module.exports = {
"ǜ": "v4",
"ń": "n2",
"ň": "n3",
"": "m2"
"": "m2",
};
2 changes: 1 addition & 1 deletion src/phrases-dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -41119,5 +41119,5 @@ module.exports = {
"做好做恶": [["zuò"], ["hǎo"], ["zuò"], ["è"]],
"做一日和尚撞一日钟": [["zuò"], ["yī"], ["rì"], ["hé"], ["shàng"], ["zhuàng"], ["yī"], ["rì"], ["zhōng"]],
"做一日和尚撞一天钟": [["zuò"], ["yī"], ["rì"], ["hé"], ["shàng"], ["zhuàng"], ["yī"], ["tiān"], ["zhōng"]],
"做一天和尚撞一天钟": [["zuò"], ["yī"], ["tiān"], ["hé"], ["shàng"], ["zhuàng"], ["yī"], ["tiān"], ["zhōng"]]
"做一天和尚撞一天钟": [["zuò"], ["yī"], ["tiān"], ["hé"], ["shàng"], ["zhuàng"], ["yī"], ["tiān"], ["zhōng"]],
};
2 changes: 1 addition & 1 deletion src/pinyin-dict-combo.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/pinyin-dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* XXX: 34 个未知读音字(部分通过 Google Translage 查询到读音,2 个未查到):
* [硳硛猠鞥旕乥怾穒椧莻夞巼喸闏朩哛兺迲囕栍虄縇襨屗曢桛烪聁艈虲蝊闧瓲龥]
*/
define({
module.exports = {
"吖": "yā,ā",
"阿": "ā,ē",
"呵": "hē,a,kē",
Expand Down Expand Up @@ -20856,5 +20856,5 @@ define({
"葄": "zuò",
"袏": "zuò",
"蓙": "zuò",
"鈼": "zuó"
});
"鈼": "zuó",
};
12 changes: 6 additions & 6 deletions src/pinyin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ if(isNode){


// 声母表。
var INITIALS = "zh,ch,sh,b,p,m,f,d,t,n,l,g,k,h,j,q,x,r,z,c,s,y,w".split(",");
var INITIALS = "b,p,m,f,d,t,n,l,g,k,h,j,q,x,r,zh,ch,sh,z,c,s".split(",");
// 韵母表。
//var FINALS = "ang,eng,ing,ong,an,en,in,un,er,ai,ei,ui,ao,ou,iu,ie,ve,a,o,e,i,u,v".split(",");
var PINYIN_STYLE = {
NORMAL: 0, // 普通风格,不带音标。
TONE: 1, // 标准风格,音标在韵母的第一个字母上。
TONE2: 2, // 声调中拼音之后,使用数字 1~4 标识。
INITIALS: 3,// 仅需要声母部分。
FIRST_LETTER: 4 // 仅保留首字母。
FIRST_LETTER: 4, // 仅保留首字母。
};
// 带音标字符。
var PHONETIC_SYMBOL = require("./phonetic-symbol.js");
Expand All @@ -75,7 +75,7 @@ var RE_TONE2 = /([aeoiuvnm])([0-4])$/;
var DEFAULT_OPTIONS = {
style: PINYIN_STYLE.TONE, // 风格
segment: false, // 分词。
heteronym: false // 多音字
heteronym: false, // 多音字
};


Expand Down Expand Up @@ -246,9 +246,9 @@ function pinyin(hans, options){
// 格式化为声母(Initials)、韵母(Finals)。
// @param {String}
// @return {String}
function initials(pinyin){
for(var i = 0, l = INITIALS.length; i < l; i++){
if(pinyin.indexOf(INITIALS[i]) === 0){
function initials(pinyin) {
for (var i = 0, l = INITIALS.length; i < l; i++){
if (pinyin.indexOf(INITIALS[i]) === 0) {
return INITIALS[i];
}
}
Expand Down
46 changes: 23 additions & 23 deletions tests/benchmark.test.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@

var memory = process.memoryUsage().rss;
var Benchmark = require('benchmark');
var pinyin = require('../');
var Benchmark = require("benchmark");
var pinyin = require("../");

var pkg = require('../package.json');
console.log(pkg.name + '@' + pkg.version);
var pkg = require("../package.json");
console.log(pkg.name + "@" + pkg.version);

function formatNunber(num){
return String(num).replace(/(\d)(?=(\d{3})+$)/g, '$1,')
return String(num).replace(/(\d)(?=(\d{3})+$)/g, "$1,");
}

var suite = new Benchmark.Suite();

suite.add('pinyin 中文', function(){
return pinyin('中文');
suite.add("pinyin 中文", function(){
return pinyin("中文");
})
.add('pinyin --heteronym 中文', function(){
return pinyin('中文', {
.add("pinyin --heteronym 中文", function(){
return pinyin("中文", {
heteronym: true,
});
})
.add('pinyin --style NORMAL --heteronym 中文', function(){
return pinyin('中文', {
.add("pinyin --style NORMAL --heteronym 中文", function(){
return pinyin("中文", {
heteronym: true,
style: 'NORMAL',
style: "NORMAL",
});
})
.add('pinyin --segment 中文', function(){
return pinyin('中文', {
.add("pinyin --segment 中文", function(){
return pinyin("中文", {
segment: true,
});
})
.add('pinyin --segment --heteronym 中文', function(){
return pinyin('中文', {
.add("pinyin --segment --heteronym 中文", function(){
return pinyin("中文", {
heteronym: true,
segment: true,
});
})
.add('pinyin --segment --heteronym --style NORMAL 中文', function(){
return pinyin('中文', {
.add("pinyin --segment --heteronym --style NORMAL 中文", function(){
return pinyin("中文", {
heteronym: true,
segment: true,
style: 'NORMAL',
style: "NORMAL",
});
})
.on('cycle', function(event) {
.on("cycle", function(event) {
var mem = process.memoryUsage().rss;
console.log(String(event.target) + ' memory usage: %s bytes.', formatNunber(mem - memory));
console.log(String(event.target) + " memory usage: %s bytes.", formatNunber(mem - memory));
memory = mem;
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
.on("complete", function() {
console.log("Fastest is " + this.filter("fastest").pluck("name"));
})
.run();
51 changes: 25 additions & 26 deletions tests/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@

var should = require("should");
var child_process = require("child_process");
var pinyin = require("../src/pinyin");

var testcases = [
{
command: 'pinyin 中国',
stdout: 'zhōng guó'
command: "pinyin 中国",
stdout: "zhōng guó",
},
{
command: 'pinyin -h 中国',
stdout: 'zhōng,zhòng guó'
command: "pinyin -h 中国",
stdout: "zhōng,zhòng guó",
},
{
command: 'pinyin -hS 中国',
stdout: 'zhōng guó'
command: "pinyin -hS 中国",
stdout: "zhōng guó",
},
{
command: 'pinyin -S 中国',
stdout: 'zhōng guó'
command: "pinyin -S 中国",
stdout: "zhōng guó",
},
{
command: 'pinyin 重心',
stdout: 'zhòng xīn'
command: "pinyin 重心",
stdout: "zhòng xīn",
},
{
command: 'pinyin 重复',
stdout: 'zhòng fù'
command: "pinyin 重复",
stdout: "zhòng fù",
},
{
command: 'pinyin -h 重复',
stdout: 'zhòng,chóng fù'
command: "pinyin -h 重复",
stdout: "zhòng,chóng fù",
},
{
command: 'pinyin -hS 重复',
stdout: 'chóng fù'
command: "pinyin -hS 重复",
stdout: "chóng fù",
},
{
command: 'pinyin -hS -s NORMAL 重复',
stdout: 'chong fu'
command: "pinyin -hS -s NORMAL 重复",
stdout: "chong fu",
},
{
command: 'pinyin -s INITIALS 重复',
stdout: 'zh f'
command: "pinyin -s INITIALS 重复",
stdout: "zh f",
},
]
];

describe('cli: command line interface.', function() {
describe("cli: command line interface.", function() {

testcases.forEach(function(testcase) {

it('$ ' + testcase.command, function(done) {
child_process.exec('bin/' + testcase.command, function(err, stdout) {
it("$ " + testcase.command, function(done) {
child_process.exec("bin/" + testcase.command, function(err, stdout) {
should.not.exist(err);
stdout.should.eql(testcase.stdout + '\n');
stdout.should.eql(testcase.stdout + "\n");
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/phrases_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ var hans = [
"中国(china)",
];

for(var i=0,l=hans.length; i<l; i++){
console.log(hans[i], pinyin(hans[i], {heteronym:true}));
for(var i = 0, l = hans.length; i < l; i++){
console.log(hans[i], pinyin(hans[i], { heteronym: true }));
}
Loading

0 comments on commit 128c154

Please sign in to comment.