line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::ID::GuessGender::FromFirstName; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-03-11'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.06'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
41013
|
use 5.010001; |
|
3
|
|
|
|
|
8
|
|
7
|
3
|
|
|
3
|
|
12
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
65
|
|
8
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
86
|
|
9
|
3
|
|
|
3
|
|
1198
|
use experimental 'smartmatch'; |
|
3
|
|
|
|
|
7211
|
|
|
3
|
|
|
|
|
14
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my @known_algos = qw/common v1_rules google/; |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
1711
|
use Locale::ID::GuessGender::FromFirstName::common; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
141
|
|
14
|
3
|
|
|
3
|
|
1338
|
use Locale::ID::GuessGender::FromFirstName::v1_rules; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
72
|
|
15
|
3
|
|
|
3
|
|
1057
|
use Locale::ID::GuessGender::FromFirstName::google; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
553
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
18
|
|
|
|
|
|
|
our @EXPORT_OK = qw(guess_gender); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub guess_gender { |
21
|
5
|
|
|
5
|
1
|
312513
|
my $opts; |
22
|
5
|
50
|
33
|
|
|
31
|
if (@_ && ref($_[0]) eq 'HASH') { |
23
|
5
|
|
|
|
|
8
|
$opts = shift; |
24
|
|
|
|
|
|
|
} else { |
25
|
0
|
|
|
|
|
0
|
$opts = {}; |
26
|
|
|
|
|
|
|
} |
27
|
5
|
50
|
|
|
|
13
|
die "Please specify at least 1 name" unless @_; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# preprocess names |
30
|
5
|
|
|
|
|
6
|
my @names; |
31
|
5
|
|
|
|
|
9
|
for (@_) { |
32
|
5
|
|
|
|
|
11
|
my $name = lc $_; |
33
|
5
|
|
|
|
|
11
|
$name =~ s/[^a-z]//g; |
34
|
5
|
50
|
|
|
|
11
|
die "Invalid first name `$_`" unless $name; |
35
|
5
|
|
|
|
|
11
|
push @names, $name; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
5
|
|
50
|
|
|
21
|
$opts->{try_all} //= 0; |
39
|
5
|
|
50
|
|
|
11
|
$opts->{algos} //= [qw/common v1_rules/]; |
40
|
5
|
|
50
|
|
|
17
|
$opts->{min_guess_confidence} //= 0.51; |
41
|
5
|
|
50
|
|
|
16
|
$opts->{algo_opts} //= {}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my @res = map { |
44
|
5
|
|
|
|
|
11
|
{ |
45
|
5
|
|
|
|
|
24
|
name => $names[$_], |
46
|
|
|
|
|
|
|
result => undef, |
47
|
|
|
|
|
|
|
algo => undef, |
48
|
|
|
|
|
|
|
algo_res => [], |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} 0..$#names; |
51
|
5
|
|
|
|
|
7
|
my $i = 0; |
52
|
3
|
|
|
3
|
|
25
|
no strict 'refs'; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
731
|
|
53
|
5
|
|
|
|
|
5
|
for my $algo (@{ $opts->{algos} }) { |
|
5
|
|
|
|
|
11
|
|
54
|
5
|
50
|
|
|
|
22
|
die "Unknown algoritm `$algo`, use one of: ". |
55
|
|
|
|
|
|
|
join(", ", @known_algos) unless $algo ~~ @known_algos; |
56
|
5
|
|
|
|
|
6
|
$i++; |
57
|
5
|
|
|
|
|
12
|
my $func = "Locale::ID::GuessGender::FromFirstName::". |
58
|
|
|
|
|
|
|
$algo . "::guess_gender"; |
59
|
5
|
|
50
|
|
|
47
|
my $algo_opts = $opts->{algo_opts}{$algo} // {}; |
60
|
|
|
|
|
|
|
my @algo_res = $func->($algo_opts, |
61
|
5
|
50
|
33
|
|
|
11
|
map { ($opts->{try_all} || !$res[$_]{result}) ? |
|
5
|
|
|
|
|
55
|
|
62
|
|
|
|
|
|
|
$names[$_] : undef } 0..$#_); |
63
|
5
|
|
|
|
|
14
|
for (0..$#algo_res) { |
64
|
5
|
50
|
|
|
|
8
|
next unless $algo_res[$_]; |
65
|
5
|
|
|
|
|
7
|
$algo_res[$_]{algo} = $algo; |
66
|
5
|
|
|
|
|
8
|
$algo_res[$_]{order} = $i; |
67
|
5
|
|
|
|
|
4
|
push @{ $res[$_]{algo_res} }, $algo_res[$_]; |
|
5
|
|
|
|
|
9
|
|
68
|
5
|
50
|
33
|
|
|
33
|
if ($algo_res[$_]{success} && |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
69
|
|
|
|
|
|
|
$algo_res[$_]{guess_confidence} >= $opts->{min_guess_confidence} && |
70
|
|
|
|
|
|
|
(!$res[$_]{result} || $res[$_]{guess_confidence} < $algo_res[$_]{guess_confidence})) { |
71
|
5
|
|
|
|
|
7
|
$res[$_]{result} = $algo_res[$_]{result}; |
72
|
5
|
|
|
|
|
5
|
$res[$_]{gender_ratio} = $algo_res[$_]{gender_ratio}; |
73
|
5
|
|
|
|
|
8
|
$res[$_]{guess_confidence} = $algo_res[$_]{guess_confidence}; |
74
|
5
|
|
|
|
|
15
|
$res[$_]{algo} = $algo; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
5
|
|
|
|
|
25
|
@res; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
# ABSTRACT: Guess gender of an Indonesian first name |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |