Giter Site home page Giter Site logo

go-pinyin's Introduction

pinyin

Go的汉字转拼音库

使用了以下项目中的拼音数据 :

Usage

package main

import "github.com/hubenchang0515/go-pinyin"

func main() {
	var py = pinyin.NewPinyin()
	py.Parse("重庆有很多体重非常重的人")
	println(py.String("-", py.Initial))
	println(py.String("-", py.Normal))
	println(py.String("-", py.Tune))
}

初始化

func NewPinyin() *Pinyin

注册一个词语的读音

func (py *Pinyin) Register(word string, pinyin []string)
  • 参数
    • word - 汉语词汇
    • pinyin - 拼音,{"chong", "qing"}
  • 示例
    • py.Register("重庆", {"chong", "qing"})

解析一串中文

func (py *Pinyin) Parse(chinese string) bool
  • 参数
    • chinese - 中文内容
  • 示例
    • py.Parse("重庆有很多体重非常重的人")

获得拼音的数组

func (py *Pinyin) Array() []string

获得拼音的字符串

func (py *Pinyin) String(interval string, flag int) string 
  • 参数
    • interval - 间隔字符串
    • flag - 表示形式
  • 示例
    • py.String("-", py.Normal)

flag的取值 :

const (
	Tune = iota    // 带声调
	Normal         // 不带声调
	Initial        // 仅声母
	First          // 仅首字母(不带声调)
)

go-pinyin's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

phos2023

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.