fakename

package module
v0.0.0-...-600978b Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 6 Imported by: 0

README

go-france

Fake french first and last names.

Raw data from the INSEE:

Use

go get github.com/malikbenkirane/go-france

Read th docs at pkg.go.dev/github.com/malikbenkirane/go-france. You will find there an example with NewSet on how to load provided firstnames and lastnames sets concurrently.

Of course this is not perfect and every suggestion is welcome 🙂

Feel free to file issues and pull requests 🚀

Roadmap

Open to suggestions... 😊

nat.ipynb

Known to work: extract files from /public, and open nat.ipynb in a jupyter lab, this would generate the files you can find in /data.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

type Loader interface {
	Read() (Nameset, error)
}

func NewLoader

func NewLoader(r io.Reader) Loader

type Nameset

type Nameset interface {
	RandomName() string
	Label() string
	All() (name []string, count []int, cum int)
}

func DefaultSet

func DefaultSet(opts ...NamesetOption) (fn, ln Nameset)

func NewSet

func NewSet(r io.Reader, opts ...NamesetOption) (Nameset, error)
Example
// Loading both firstnames and lastnames concurrently.

fn, ln, err := func() (Nameset, Nameset, error) {
	dst := make(chan Nameset, 2)

	{
		var eg errgroup.Group
		for _, _s := range []struct {
			src   string
			label string
		}{
			{
				src:   "data/noms_sorted_by_count.csv",
				label: "lastnames",
			},
			{
				src:   "data/prenoms_sorted_by_count.csv",
				label: "firstnames",
			},
		} {
			s := _s
			eg.Go(func() error {
				f, err := os.Open(s.src)
				if err != nil {
					return fmt.Errorf("%s: os: open: %w", s.label, err)
				}
				ns, err := NewSet(f, NamesetWithRand(rand.New(rand.NewSource(42)))) // read also go doc math/rand
				if err != nil {
					return fmt.Errorf("%s: new set: %w", s.label, err)
				}
				dst <- ns
				return nil
			})
		}

		if err := eg.Wait(); err != nil {
			return nil, nil, err
		}

	}

	{

		var fn, ln Nameset

		ns := <-dst
		if ns.Label() == "lastnames" {
			ln = ns
			fn = <-dst
		} else {
			fn = ns
			ln = <-dst
		}

		return fn, ln, nil

	}

}()

if err != nil {
	fmt.Println(err)
	return
}

fmt.Println(fn.RandomName(), ln.RandomName())
Output:

MARCELLE LEMEE

type NamesetOption

type NamesetOption func(nsconf) nsconf

func NamesetWithLabel

func NamesetWithLabel(label string) NamesetOption

func NamesetWithRand

func NamesetWithRand(r *rand.Rand) NamesetOption

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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