gimei

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 9 Imported by: 15

README

go-gimei

Build Status Codecov GoDoc Go Report Card

This project is a golang port of Ruby's gimei. Import as library or use as CLI.

go-gimei generates fake data that people's name and address in Japanese and supports furigana phonetic renderings of kanji.

The project name comes from Japanese '偽名' means a false name.

Usage

package main

import (
	"fmt"

	"github.com/mattn/go-gimei"
)

func main() {
	name := gimei.NewName()
	fmt.Println(name)                  // 斎藤 陽菜
	fmt.Println(name.Kanji())          // 斎藤 陽菜
	fmt.Println(name.Hiragana())       // さいとう はるな
	fmt.Println(name.Katakana())       // サイトウ ハルナ
	fmt.Println(name.Romaji())         // Haruna Saito
	fmt.Println(name.Last.Kanji())     // 斎藤
	fmt.Println(name.Last.Hiragana())  // さいとう
	fmt.Println(name.Last.Katakana())  // サイトウ
	fmt.Println(name.Last.Romaji())    // Saito
	fmt.Println(name.First.Kanji())    // 陽菜
	fmt.Println(name.First.Hiragana()) // はるな
	fmt.Println(name.First.Katakana()) // ハルナ
	fmt.Println(name.First.Romaji())   // Haruna
	fmt.Println(name.Sex)              // 女
	fmt.Println(name.IsMale())         // false

	male := gimei.NewMale()
	fmt.Println(male)            // 小林 顕士
	fmt.Println(male.IsMale())   // true
	fmt.Println(male.IsFemale()) // false

	address := gimei.NewAddress()
	fmt.Println(address)                       // 岡山県大島郡大和村稲木町
	fmt.Println(address.Kanji())               // 岡山県大島郡大和村稲木町
	fmt.Println(address.Hiragana())            // おかやまけんおおしまぐんやまとそんいなぎちょう
	fmt.Println(address.Katakana())            // オカヤマケンオオシマグンヤマトソンイナギチョウ
	fmt.Println(address.Prefecture)            // 岡山県
	fmt.Println(address.Prefecture.Kanji())    // 岡山県
	fmt.Println(address.Prefecture.Hiragana()) // おかやまけん
	fmt.Println(address.Prefecture.Katakana()) // オカヤマケン
	fmt.Println(address.City)                  // 大島郡大和村
	fmt.Println(address.City.Kanji())          // 大島郡大和村
	fmt.Println(address.City.Hiragana())       // おおしまぐんやまとそん
	fmt.Println(address.City.Katakana())       // オオシマグンヤマトソン
	fmt.Println(address.Town)                  // 稲木町
	fmt.Println(address.Town.Kanji())          // 稲木町
	fmt.Println(address.Town.Hiragana())       // いなぎちょう
	fmt.Println(address.Town.Katakana())       // イナギチョウ

	prefecture := gimei.NewPrefecture()
	fmt.Println(prefecture) // 青森県
}
Deterministic Random

go-gimei supports seeding of its pseudo-random number generator to provide deterministic output of repeated method calls.

import "math/rand"

gimei.SetRandom(rand.New(rand.NewSource(42)))
fmt.Println(gimei.NewName())    // 前川 永麻
fmt.Println(gimei.NewAddress()) // 佐賀県斜里郡斜里町浄法寺町樋口

gimei.SetRandom(rand.New(rand.NewSource(42)))
fmt.Println(gimei.NewName())    // 前川 永麻
fmt.Println(gimei.NewAddress()) // 佐賀県斜里郡斜里町浄法寺町樋口

CLI Usage

$ gimei [OPTIONS] [ARGS]

Omitting ARGS is equivalent to specifying name:kanji.

OPTIONS
-sep string
    specify string used to separate fields(default: ", ").
-n number
    display number record(s).
-count
    display records read from embedded yaml files and exit.
-h, -help
    display usage and exit.
ARGS

Argument for a personal name:

name|male|female[:NAME_DISPLAY_OPTION]

NAME_DISPLAY_OPTION list

to display full name:
    'kanji', (is equivalent to omitting NAME_DISPLAY_OPTION)
    'hiragana',
    'katakana',
    'romaji'
to display last name:
    'last-kanji',
    'last-hiragana',
    'last-katakana',
    'last-romaji'
to display first name:
    'first-kanji',
    'first-hiragana',
    'first-katakana',
    'first-romaji'
to display which it is male/female:
    'is-male',
    'is-female'

Argument for an address:

address[:ADDRESS_DISPLAY_OPTION]

ADDRESS_DISPLAY_OPTION list

to display address:
    'kanji', (is eqivalent ot omitting ADDRESS_DISPLAY_OPTION)
    'hiragana',
    'katakana'
to display prefecture:
    'prefecture-kanji',
    'prefecture-hiragana',
    'prefecture-katakana'
to display city:
    'city-kanji',
    'city-hiragana',
    'city-katakana'
to display town:
    'town-kanji',
    'town-hiragana',
    'town-katakana'
EXAMPLES
$ gimei
古賀 正浩
$ gimei name:kanji name:katakana
中村 紳一, ナカムラ シンイチ
$ gimei -sep '/' address:prefecture-kanji address:town-kanji
滋賀県/田所町
$ gimei -n 3 name name:hiragana
白川 彰花, しらかわ あきか
関根 勇一, せきね ゆういち
大場 星良, おおば きらら

Requirements

golang

Installation

Install the library.

$ go get github.com/mattn/go-gimei
CLI installation

On Go version 1.16 or later, this command works:

$ go install github.com/mattn/go-gimei/cmd/gimei@latest

Running Tests

To run all the tests, do:

$ go test

License

MIT

Dictionary YAML file is generated from naist-jdic.

Author

Yasuhiro Matsumoto (a.k.a mattn)

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountData

func CountData() string

func SetRandom

func SetRandom(rnd *rand.Rand)

SetRandom set a pointer to rand.Rand that uses to generate random values.

Types

type Address

type Address struct {
	Prefecture Item
	City       Item
	Town       Item
}

Address store address that is pointed by prefecture/city/town.

Example
address := gimei.FindAddressByKanji("岡山県大島郡大和村稲木町")
fmt.Println(address)
fmt.Println(address.Kanji())
fmt.Println(address.Hiragana())
fmt.Println(address.Katakana())
fmt.Println(address.Prefecture.Kanji())
fmt.Println(address.Prefecture.Hiragana())
fmt.Println(address.Prefecture.Katakana())
fmt.Println(address.City.Kanji())
fmt.Println(address.City.Hiragana())
fmt.Println(address.City.Katakana())
fmt.Println(address.Town.Kanji())
fmt.Println(address.Town.Hiragana())
fmt.Println(address.Town.Katakana())
Output:

岡山県大島郡大和村稲木町
岡山県大島郡大和村稲木町
おかやまけんおおしまぐんやまとそんいなぎちょう
オカヤマケンオオシマグンヤマトソンイナギチョウ
岡山県
おかやまけん
オカヤマケン
大島郡大和村
おおしまぐんやまとそん
オオシマグンヤマトソン
稲木町
いなぎちょう
イナギチョウ

func FindAddressByHiragana

func FindAddressByHiragana(hiragana string) *Address

FindAddressByHiragana find Address by hiragana.

func FindAddressByKanji

func FindAddressByKanji(kanji string) *Address

FindAddressByKanji find Address by kanji.

func FindAddressByKatakana

func FindAddressByKatakana(katakana string) *Address

FindAddressByKatakana find Address by katakana.

func NewAddress

func NewAddress() *Address

NewAddress return new instance of address.

func (*Address) Hiragana

func (a *Address) Hiragana() string

Hiragana return string of Address as hiragana.

func (*Address) Kanji

func (a *Address) Kanji() string

Kanji return string of Address as kanji.

func (*Address) Katakana

func (a *Address) Katakana() string

Katakana return string of Address as katakana.

func (*Address) String

func (a *Address) String() string

String implement Stringer.

type Item

type Item []string

Item take four figure for japanese. Kanji/Hiragana/Katakana/Romaji. It's not only the difference of sounds, it just letters.

func NewCity

func NewCity() Item

NewCity return new instance of city.

func NewPrefecture

func NewPrefecture() Item

NewPrefecture return new instance of prefecture.

func NewTown

func NewTown() Item

NewTown return new instance of town.

func (Item) Hiragana

func (i Item) Hiragana() string

Hiragana return string of Item as hiragana.

func (Item) Kanji

func (i Item) Kanji() string

Kanji return string of Item as kanji.

func (Item) Katakana

func (i Item) Katakana() string

Katakana return string of Item as katakana.

func (Item) Romaji

func (i Item) Romaji() string

Romaji return string of Item as romaji.

func (Item) String

func (i Item) String() string

String implement Stringer

type Name

type Name struct {
	First Item
	Last  Item
	Sex   Sex
}

Name store name and sex for a person.

Example
name := gimei.FindNameByKanji("小林 顕士")
fmt.Println(name)
fmt.Println(name.Kanji())
fmt.Println(name.Hiragana())
fmt.Println(name.Katakana())
fmt.Println(name.Romaji())
fmt.Println(name.Last.Kanji())
fmt.Println(name.Last.Hiragana())
fmt.Println(name.Last.Katakana())
fmt.Println(name.Last.Romaji())
fmt.Println(name.First.Kanji())
fmt.Println(name.First.Hiragana())
fmt.Println(name.First.Katakana())
fmt.Println(name.First.Romaji())
fmt.Println(name.Sex)
Output:

小林 顕士
小林 顕士
こばやし けんじ
コバヤシ ケンジ
Kenji Kobayashi
小林
こばやし
コバヤシ
Kobayashi
顕士
けんじ
ケンジ
Kenji
男

func FindNameByHiragana

func FindNameByHiragana(hiragana string) *Name

FindNameByHiragana find Name by hiragana.

func FindNameByKanji

func FindNameByKanji(kanji string) *Name

FindNameByKanji find Name by kanji.

func FindNameByKatakana

func FindNameByKatakana(katakana string) *Name

FindNameByKatakana find Name by katakana.

func FindNameByRomaji

func FindNameByRomaji(romaji string) *Name

FindNameByRomaji find Name by romaji.

func NewCat

func NewCat() *Name

NewCat return new instance of person whose last name begins "neko".

func NewDog

func NewDog() *Name

NewDog return new instance of person whose last name begins "inu".

func NewFemale

func NewFemale() *Name

NewFemale return new instance of person that is female.

func NewFemaleCat

func NewFemaleCat() *Name

NewFemaleCat return new instance of female person whose last name begins "neko".

func NewFemaleDog

func NewFemaleDog() *Name

NewFemaleDog return new instance of female person whose last name begins "inu".

func NewMale

func NewMale() *Name

NewMale return new instance of person that is male.

func NewMaleCat

func NewMaleCat() *Name

NewMaleCat return new instance of male person whose last name begins "neko".

func NewMaleDog

func NewMaleDog() *Name

NewMaleDog return new instance of male person whose last name begins "inu".

func NewName

func NewName() *Name

NewName return new instance of person.

func (*Name) Hiragana

func (n *Name) Hiragana() string

Hiragana return string of Name as hiragana.

func (*Name) IsFemale

func (n *Name) IsFemale() bool

IsFemale return true if she is female.

func (*Name) IsMale

func (n *Name) IsMale() bool

IsMale return true if he is male.

func (*Name) Kanji

func (n *Name) Kanji() string

Kanji return string of Name as kanji.

func (*Name) Katakana

func (n *Name) Katakana() string

Katakana return string of Name as katakana.

func (*Name) Romaji

func (n *Name) Romaji() string

Romaji return string of Name as romaji.

func (*Name) String

func (n *Name) String() string

String implement Stringer.

type Sex

type Sex int

Sex store Male or Female.

const (
	Male   Sex = iota + 1 // 男
	Female                // 女
)

list of sex

func (Sex) String

func (s Sex) String() string

String implement Stringer.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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