line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::ID::GuessGender::FromFirstName::v1_rules; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
33
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
82
|
|
4
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
1326
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.06'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# XXX extract from common list instead of wild guessing |
9
|
|
|
|
|
|
|
my @rules = ( |
10
|
|
|
|
|
|
|
[qr/.o$/, M => 0.98], |
11
|
|
|
|
|
|
|
[qr/.i$/, F => 0.60], |
12
|
|
|
|
|
|
|
[qr/.ini$/, F => 0.90], |
13
|
|
|
|
|
|
|
[qr/.d$/, M => 0.85], |
14
|
|
|
|
|
|
|
[qr/.wan$/, M => 0.99], |
15
|
|
|
|
|
|
|
[qr/.wati$/, F => 0.99], |
16
|
|
|
|
|
|
|
[qr/.us$/, M => 0.7], |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub guess_gender { |
20
|
2
|
|
|
2
|
1
|
2
|
my $opts; |
21
|
2
|
50
|
33
|
|
|
11
|
if (@_ && ref($_[0]) eq 'HASH') { |
22
|
2
|
|
|
|
|
3
|
$opts = shift; |
23
|
|
|
|
|
|
|
} else { |
24
|
0
|
|
|
|
|
0
|
$opts = {}; |
25
|
|
|
|
|
|
|
} |
26
|
2
|
50
|
|
|
|
3
|
die "Please specify at least 1 name" unless @_; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
2
|
my @res; |
29
|
2
|
|
|
|
|
17
|
for my $name (@_) { |
30
|
2
|
50
|
|
|
|
4
|
do { push @res, undef; next } unless defined($name); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
31
|
2
|
|
|
|
|
5
|
my $res = { success => 0 }; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
3
|
my $num_match = 0; |
34
|
2
|
|
|
|
|
1
|
my $m = 1; |
35
|
2
|
|
|
|
|
2
|
my $f = 1; |
36
|
2
|
|
|
|
|
3
|
my $min_ratio = 0.75; |
37
|
2
|
|
|
|
|
4
|
for my $rule (@rules) { |
38
|
14
|
100
|
|
|
|
52
|
$name =~ $rule->[0] or next; |
39
|
3
|
|
|
|
|
3
|
$num_match++; |
40
|
3
|
100
|
|
|
|
7
|
if ($rule->[1] eq 'M') { |
41
|
1
|
|
|
|
|
2
|
$m *= $rule->[2]; |
42
|
1
|
|
|
|
|
2
|
$f *= (1-$rule->[2]); |
43
|
|
|
|
|
|
|
} else { |
44
|
2
|
|
|
|
|
3
|
$f *= $rule->[2]; |
45
|
2
|
|
|
|
|
4
|
$m *= (1-$rule->[2]); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
2
|
50
|
|
|
|
5
|
if ($num_match) { |
49
|
2
|
|
|
|
|
2
|
$res->{success} = 1; |
50
|
2
|
|
|
|
|
3
|
$res->{num_rules} = $num_match; |
51
|
2
|
|
|
|
|
3
|
$res->{min_gender_ratio} = $min_ratio; |
52
|
2
|
100
|
|
|
|
5
|
my $r = $m > $f ? $m/($m+$f) : $f/($m+$f); |
53
|
2
|
100
|
|
|
|
8
|
$res->{result} = $r < $min_ratio ? "both" : ($m > $f ? "M" : "F"); |
|
|
50
|
|
|
|
|
|
54
|
2
|
|
|
|
|
4
|
$res->{gender_ratio} = $r; |
55
|
2
|
|
|
|
|
2
|
$res->{guess_confidence} = $r; |
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
|
|
|
|
0
|
$res->{error} = "No heuristic rules matched"; |
58
|
|
|
|
|
|
|
} |
59
|
2
|
|
|
|
|
4
|
push @res, $res; |
60
|
|
|
|
|
|
|
} |
61
|
2
|
|
|
|
|
6
|
@res; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
# ABSTRACT: v1_rules |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |