Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- def pinyin_to_hanzi(pinyin)
- `curl -s "http://olime.baidu.com/py?py=#{pinyin}" | iconv -f gb18030 -t utf8`[/"[^"]*/][1..-1]
- end
- STDIN.lines do |l|
- pinyins = l.gsub(' ', "").split /[^a-z]/
- puts pinyins.inject([]) { |a, p| a << pinyin_to_hanzi(p) }.join ' '
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement