barttyrant / php_genderize
Genderize.io 的 PHP 处理器
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-24 21:44:44 UTC
README
PHP5 版本的性别识别库
基本上,它是通过给定的名字和使用 genderize.io 来猜测性别的。
作者:Bart Tyrant bartlomiej@tyranowski.pl 贡献者:Luke Shaheen @tlshaheen http://github.com/tlshaheen 许可证:MIT 许可证 https://open-source.org.cn/licenses/mit-license.php
==用法:==
最简单的情况
$recognizer = new \Genderize\Base\Recognizer('Peter'); $peter = $recognizer->recognize(); print_r($peter);
将给出
Genderize\Base\Name 对象 ( [_name:protected] => Peter [_count:protected] => 4284 [_gender:protected] => male [_probability:protected] => 1.00 )
您可以通过传递多个名字 - 到目前为止,genderizer.io 一次最多接受 10 个
$recognizer = new \Genderize\Base\Recognizer(array('Peter', 'John')); $namesinfo = $recognizer->recognize(); print_r($namesinfo);
将给出
array([0] => Genderize\Base\Name 对象 ( [_name:protected] => Peter [_count:protected] => 4284 [_gender:protected] => male [_probability:protected] => 1.00 ), [1] => Genderize\Base\Name 对象 ( [_name:protected] => Peter [_count:protected] => 4284 [_gender:protected] => male [_probability:protected] => 1.00 ) )
--
此外,还支持国家和语言过滤器
$Recognizer = Genderize::factory(); $asia = $Recognizer->set_name('Asia')->recognize(); print_r($asia); $asiaPL = $Recognizer->set_country_id('pl')->set_name('Asia')->recognize(); print_r($asiaPL);
... 将打印出
Genderize\Base\Name 对象 ( [_name:protected] => Asia [_count:protected] => 97 [_gender:protected] => female [_probability:protected] => 0.99 ) Genderize\Base\Name 对象 ( [_name:protected] => Asia [_count:protected] => 26 [_gender:protected] => female [_probability:protected] => 1.00 [_country_id] => PL )
拥有 http://store.genderize.io 的 API 密钥?使用 $Recognizer->set_api_key($api_key)
在请求中传递它。