tuqqu/gender-detector 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tuqqu/gender-detector

最新稳定版本:v0.5.2

Composer 安装命令:

composer require tuqqu/gender-detector

包简介

Get gender from first name

README 文档

README

Get the most likely gender associated with a first name using PHP.

This library utilizes data sourced from the gender.c project created by Jörg Michael (details).

Installation

Install it with Composer:

composer require tuqqu/gender-detector

Usage

The usage is straightforward:

$detector = new GenderDetector\GenderDetector();

$detector->getGender('Thomas');
// Gender::Male

$detector->getGender('Avery');
// Gender::Unisex

I18N is fully supported:

$detector->getGender('Geirþrúður');
// Gender::Female

You can also specify a country:

$detector->getGender('Robin');
// Gender::MostlyMale

$detector->getGender('Robin', 'US');
// Gender::MostlyFemale

$detector->getGender('Robin', 'FR');
// Gender::Male

$detector->getGender('Robin', 'IE');
// Gender::Unisex

Country codes are case-insensitive ISO 3166-1 alpha-2 codes. Alternatively, you can utilize enum values; the complete list of values and codes can be found here.

Full list of all the possible gender values are:

enum Gender
{
    case Male;
    case MostlyMale;
    case Female;
    case MostlyFemale;
    case Unisex;
}

For an unknown name it will return null.

If you have an alternative data file, you can pass it as the first argument to the GenderDetector constructor. Additionally, you can add new dictionary files using the addDictionaryFile(string $path) method:

$detector = new GenderDetector('custom_file_path/dict.txt');
$detector->addDictionaryFile('custom_file_path/another_dict.txt');

Note that each GenderDetector instantiation triggers file parsing, so you might want to avoid reading the same file twice.

Licenses

The GenderDetector is licensed under the MIT License.

The data file data/nam_dict.txt is licensed under the GNU Free Documentation License.

统计信息

  • 总下载量: 330.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 55
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 55
  • Watchers: 2
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-20