Git Product home page Git Product logo

pinyin's Introduction

Pinyin Library for Go!

GetRuneFirstLetters

func GetRuneFirstLetters(c rune) []rune

获取单个字符的拼音首字母:

  1. 如果该字符为非打印字符, 则返回空 slice
  2. 如果该字符非汉字, 返回字符本身, 如: GetRuneFirstLetters('a') // []rune{'a'}
  3. 如果该字符为汉字, 返回拼音首字, 如: GetRuneFirstLetters('人') // []rune{'r'}
  4. 如果该字符为汉字多音字, 则返回每个音的拼音首字, 常用音在前, 如: GetRuneFirstLetters('大') // []ruse{'d', 't'}

FirstLetters

func FirstLetters(s string, sep string) string

返回字符串的拼音首字母:

忽略不可打印字符, 非汉字返回字符自身:

FirstLetters("a全\n", " ") // aq

如果包含多音字, 生成多音字的所以组合, 用sep字符隔开:

FirstLetters("大虾㚘", " ") // dxb dxh dxf dhb dhh dhf txb txh txf thb thh thf

限制

多音字只保留最常用的三个读音, 实际上超过三个读音的多音字很少, 只有 10 几个, 且都是生僻音.

只包括 unicode 编码在 0xffff 之前的汉字, 基本都是生僻字, 不影响正常使用.

Thanks

拼音数据来自于: https://github.com/mozillazg/pinyin-data

拼音词库来自于: https://github.com/janx/ruby-pinyin

pinyin's People

Contributors

redforks avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.