pinyin_index

A fast Chinese characters to pinyins conversion/romanization tool for indexing use.

pinyin_index

A fast Chinese characters to pinyins conversion/romanization tool for indexing use.

It's much more convenient to type pinyin (especially the pinyin abbreviations) than Chinese characters when you search something.

npm install pinyin_index

Usage: pinyin_index(text[, options])
Returns an object by default.

var pinyin_index = require('pinyin_index');
pinyin_index('天生我材必有用,千金散尽还复来。')
// returns:
// { full: 'tianshengwocaibiyouyong,qianjinsanjinhuanfulai。',
//   abbr: 'tswcbyy qjsjhfl' }

type String

Defaults to int which is faster than object and string.

output Function (pinyin_array, replaced)

Customize output.

pinyin_index('天生我材必有用,千金散尽还复来。', {
  output: function(pinyin_array, replaced) {
    return pinyin_array;
  }
})

returns:

[ [ 'tian', 'sheng', 'wo', 'cai', 'bi', 'you', 'yong' ],
  [ 'qian', 'jin', 'san', 'jin', 'huan', 'fu', 'lai' ] ]
characterstype: 'string'type: 'int'type: 'object'
131307.8622495150436648.6450962549236067.39500122621
322936.3690578765135667.9684299637534737.647055291236
1113073.0223059329134175.5547251844332309.680108541415
296779.11085510133531194.0365099254127748.817744451426
563893.513612628321426491.3407081848622105.796098194653

Measured in ops/sec on a Mac Mini 2012 with 2.3GHz i7 CPU and 16GB RAM.

For the best performance, you may fork and simplify this repo to best suit your project.

LICENSE: MIT
Developer: caiguanhao <caiguanhao@gmail.com>