Giter Site home page Giter Site logo

gander's Introduction

Gender guesser written in Go

Inspired by the python gender guesser, with data from the program "gender" by Jorg Michael

Motivation

  • Performance
  • Only males or females
  • In a go package

Usage

  • Make sure you have your $GOPATH set, otherwise
$ export GOPATH=~/go # Or your gopath location
  • Install
$ go get -u github.com/octohedron/gander
  • Example
package main

import "log"
import "github.com/octohedron/gander"

func main() {
	g, err := gander.CheckGender("Aad")
	if err == nil {
		// prints 'm'
		log.Println(g.Gender)
	} else {
		// It would print 'Aad', if there was an error
		log.Println(g.Name)
    }
}

Performance

The fastest is to use the CheckGenderMap func, but it doesn't return an error, only "unknown" if it doesn't find the gender.

func TestBenchmark(t *testing.T) {
	var males int
	var females int
	const total = 100000000 // 100 million
	t.Log("START")
	for i := 0; i < total; i++ {
		g := CheckGenderMap(
			NGData[rand.Intn(len(NGData))].Name)
		if g == "f" {
			females++
		} else {
			males++
		}
	}
	t.Logf("In %d we found %d females and %d males", total, females, males)
}
2019/01/27 20:51:16.996857 START
2019/01/27 20:51:29.781984 In 100000000 we found 47278122 females and 52721878 males

That's ~ 7.7M/s ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

With error

func TestAllLoadedNames(t *testing.T) {
	var males int
	var females int
	c := make(chan int)
	var complete int
	for _, n := range NGData {
		go func(n NameGender) {
			g, err := CheckGender(n.Name)
			if err == nil {
				if g.Gender == "f" {
					c <- 1
				} else {
					c <- 0
				}
			}
		}(n)
	}
	for p := range c {
		complete++
		if p == 1 {
			females++
		} else {
			males++
		}
		if complete == len(NGData) {
			break
		}
	}
	log.Println("COMPLETED")
	t.Logf("In %d we found %d females and %d males", len(NGData), females, males)
}

Prints

2019/01/27 13:05:01.639677 LOADED
=== RUN   TestAllLoadedNames
2019/01/27 13:05:02.165385 COMPLETED
--- PASS: TestAllLoadedNames (2.32s)
    ...gander/gander_test.go:50: In 41437 we found 20505 females and 20932 males
PASS
ok  	github.com/octohedron/gander	0.604s
Success: Tests passed.

0.525708 for 41.437 names, or ~78.821 names per second in a laptop

LICENSE

  • The data file nam_dict.txt is released under the GNU Free Documentation License.
  • The project is released under the MIT license

gander's People

Contributors

octohedron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.