微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ChinesePinyin 安装用法Polyphone Issue

程序名称:ChinesePinyin

授权协议: MIT

操作系统: 跨平台

开发语言: Ruby

ChinesePinyin 介绍

chinese_pinyin 是一款将汉字转化为拼音的应用。

安装

gem install chinese_pinyin

或者在Gemfile中添加

gem 'chinese_pinyin'

用法

命令行

$ ch2py -h
Usage: ch2py [opts]
    -c, --camelcase                  Camelcase of each word
    -i, --stdin                      Read from stdard input
    -t, --tone                       Show tone at end of word
    -m, --tonemarks                  Show tone at top of letter, this
would cover -t option
    -s, --splitter <splitter>        Splitter of each word, use a space
by default
    -v, --version                    Show version
    -h, --help                       Show this help

$ ch2py 中文
zhong wen

代码

require 'chinese_pinyin'

Pinyin.t('中国')  => zhong guo
Pinyin.t('你好world') => ni hao world
Pinyin.t('中国', splitter: '-') => zhong-guo
Pinyin.t('中国', splitter: '') => zhongguo
Pinyin.t('中国', tone: true) => zhong1 guo2
Pinyin.t('中国', tonemarks: true) => zhōng guó
Pinyin.t('北京') { |letters| letters[0].upcase } => 'BJ'
Pinyin.t('北京') { |letters, i| letters[0].upcase if i == 0 } => 'B'

polyphone Issue

使用Words.dat覆盖认行为

认配置

Pinyin.t('广州') => yan zhou

增加 Words.dat 文件

广州|guang3 zhou1

为 Words.dat 设置 ENV[‘WORDS_FILE’]

ENV['WORDS_FILE'] = Words.dat path
Pinyin.t('广州') => guang zhou

ChinesePinyin 官网

https://github.com/flyerhzm/chinese_pinyin

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐