flyerhzm / chinese_pinyin Goto Github PK
View Code? Open in Web Editor NEWtranslate chinese hanzi to pinyin
License: MIT License
translate chinese hanzi to pinyin
License: MIT License
如:
韩伟 => hán wěi
3.1.2 :001 > Pinyin.t('厦门')
=> "sha men"
tone_index 1 2 3 4 分别是 4 个声,5 是什么?而且有 91 个有 5.
如果 tone_index
是 5 的话,下面代码就会出错
tone_index = pinyin[-1].to_i
pinyin = pinyin[0...-1]
%w(a o e i u v).each { |v|
break if pinyin.tr! v, TONE_MARK[v.to_sym][tone_index]
}
代码来自 (https://github.com/flyerhzm/chinese_pinyin/blob/master/lib/chinese_pinyin.rb#L86-L90)
因为每个 TONE_MARK[v.to_sym]
都只有 5 个元素,因此会取到 nil
,再进行 tr!
就会报错。
有些字的第一个拼音的 tone
不是 5,所以不会出问题。但也有不少字的第一个拼音的 tone
是 5,
awk '$2~/5/{print $1,$2}' data/pinyin-utf8.dat
㟷 da5
了 le5
们 men5
們 men5
吗 ma5
吧 ba5
吶 ne5
呗 bei5
哟 yo5
这些字转成拼音都会报错.
Pinyin.t('呗', tonemarks: true)
# : in `tr!': no implicit conversion of nil into String (TypeError)
use Words.dat to override default behavior.
by default
Pinyin.t('广州') => "yan zhou"
add file Words.dat
广州|guang3 zhou1
set ENV['WORDS_FILE']
for Words.dat
ENV['WORDS_FILE'] = "Words.dat path"
Pinyin.t('广州') => "guang zhou"
第一行示例code,广州怎么会得出“yan zhou”
When use this library, is possible preserver all characters that aren't letters?
嗯 returns no result
嗯 is HSK6 word.
In Japanese Wiktionary, the pinyin is described as en1.
https://ja.wiktionary.org/wiki/嗯
OS: macOS Mojave ver10.14.6
ruby: ruby 2.6.3p62
chinese_pinyin (1.0.1)
require 'chinese_pinyin'
puts Pinyin.t('嗯', tonemarks: true)
# =>
(no result)
您这个版本的拼音有很多多余的,比如参字,怎么来了个den音?等等,比其他的多了很多音。
嗯,读音:ǹg、ńg、ňg
下面这个例子是现在的转换方式:
irb
irb(main):001:0> require 'chinese_pinyin'
=> true
irb(main):002:0> Pinyin.t('/(斜线)')
=> " xie xian"
可以看出,斜线(/
)和括号(()
)都被“吃掉”了。有没有办法可以保留符号呢?
ruby 2.0.0-p0 error
Is it possible to also add in the tone marks?
eg.
Pinyin.t('**', tonemarks: true) => "zhōng guó"
Please help me with this problem.
Is it a change in your library?
It would be awesome to add node.js support for the ruby library.
Hello,
Could you please include a license file in this project so that we know in what conditions we can use your library? (an MIT-license would be great)
广州 -> yan zhou
搜汉字转拼音时,从Ruby China的一个回复中,找到了这个。但是,在测试中发现一个问题。如下:
我的测试代码如下:
Pinyin.t("测试一下,Think diff", splitter: '-')
希望的结果应该如下:
"ce-shi-yi-xia-Think-diff"
但是,得到的结果确实这样的:
"ce-shi-yi-xia-,Think diff"
请看一下,这是否是个问题?
Pinyin.t('北京', initial: true) # BJ
Pinyin.t('北京', letter: true) # B
Pinyin.t('北京') do |letters|
...
end
Pinyin.t('北京').split.map { |w| w.first.upcase }.join # BJ
Pinyin.t('北京').first.upcase # B
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.