pinyin

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2014 License: MIT Imports: 2 Imported by: 0

README

go-pinyin

Build Status Coverage Status GoDoc

汉语拼音转换工具 Go 版。

Installation

go get -u github.com/mozillazg/go-pinyin

install CLI tool:

go get -u github.com/mozillazg/go-pinyin/pinyin
$ pinyin 中国人
zhōng guó rén

Usage

package main

import (
	"fmt"
	"github.com/mozillazg/go-pinyin"
)

func main() {
	hans := "中国人"
    // 默认输出 [[zhong] [guo] [ren]]
	fmt.Println(pinyin.Pinyin(hans, pinyin.Args{}))
    // 包含声调 [[zhōng] [guó] [rén]]
	fmt.Println(pinyin.Pinyin(hans, pinyin.Args{Style: pinyin.TONE}))
    // 声调用数字表示 [[zho1ng] [guo2] [re2n]]
	fmt.Println(pinyin.Pinyin(hans, pinyin.Args{Style: pinyin.TONE2}))
    // 开启多音字模式 [[zhong zhong] [guo] [ren]]
	fmt.Println(pinyin.Pinyin(hans, pinyin.Args{Heteronym: true}))
    // [[zho1ng zho4ng] [guo2] [re2n]]
	fmt.Println(pinyin.Pinyin(hans, pinyin.Args{Style: pinyin.TONE2, Heteronym: true}))
}

Documentation

Index

Constants

View Source
const (
	Version   = "0.1.1"
	Author    = "mozillazg, 闲耘"
	License   = "MIT"
	Copyright = "Copyright (c) 2014 mozillazg, 闲耘"
)

Meta

View Source
const (
	NORMAL       = 0 // 普通风格,不带声调(默认风格)。如: pin yin
	TONE         = 1 // 声调风格1,拼音声调在韵母第一个字母上。如: pīn yīn
	TONE2        = 2 // 声调风格2,即拼音声调在各个拼音之后,用数字 [0-4] 进行表示。如: pi1n yi1n
	INITIALS     = 3 // 声母风格,只返回各个拼音的声母部分。如: 中国 的拼音 zh g
	FIRST_LETTER = 4 // 首字母风格,只返回拼音的首字母部分。如: p y
	FINALS       = 5 // 韵母风格1,只返回各个拼音的韵母部分,不带声调。如: ong uo
	FINALS_TONE  = 6 // 韵母风格2,带声调,声调在韵母第一个字母上。如: ōng uó
	FINALS_TONE2 = 7 // 韵母风格2,带声调,声调在各个拼音之后,用数字 [0-4] 进行表示。如: o1ng uo2
)

拼音风格

Variables

View Source
var PinyinDict map[int]string = map[int]string{}/* 42013 elements not displayed */

Functions

func LazyPinyin

func LazyPinyin(s string, a Args) []string

func Pinyin

func Pinyin(s string, a Args) [][]string

func SinglePinyin

func SinglePinyin(r rune, a Args) []string

func Slug

func Slug(s string, a Args) string

Types

type Args

type Args struct {
	Style     int    // 拼音风格(默认: NORMAL)
	Heteronym bool   // 是否启用多音字模式(默认:禁用)
	Separator string // Slug 中使用的分隔符(默认:-)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL