line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Lingua::AFR::Word2Num; |
4
|
|
|
|
|
|
|
# ABSTRACT: Word 2 number conversion in AFR. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# {{{ use block |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
21076
|
use 5.10.1; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
35
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
12
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
22
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
92
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
765
|
use Perl6::Export::Attrs; |
|
1
|
|
|
|
|
9345
|
|
|
1
|
|
|
|
|
6
|
|
17
|
1
|
|
|
1
|
|
1688
|
use Parse::RecDescent; |
|
1
|
|
|
|
|
45915
|
|
|
1
|
|
|
|
|
7
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# }}} |
20
|
|
|
|
|
|
|
# {{{ variable declarations |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = 0.1106; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $INFO = { |
25
|
|
|
|
|
|
|
rev => '$Rev: 1106 $', |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $parser = af_numerals(); |
29
|
|
|
|
|
|
|
# }}} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# {{{ w2n convert number to text |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
sub w2n :Export { |
34
|
3
|
|
50
|
3
|
1
|
100760
|
my $input = shift // return; |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
14
|
$input =~ s/,//g; |
37
|
3
|
|
|
|
|
14
|
$input =~ s/ //g; |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
36
|
return $parser->numeral($input); |
40
|
1
|
|
|
1
|
|
129
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
41
|
|
|
|
|
|
|
# }}} |
42
|
|
|
|
|
|
|
# {{{ af_numerals create parser for numerals |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub af_numerals { |
45
|
1
|
|
|
1
|
1
|
5
|
return Parse::RecDescent->new(q{ |
46
|
|
|
|
|
|
|
numeral: scrap { return undef; } # root parse. go from maximum to minimum value |
47
|
|
|
|
|
|
|
| million { return $item[1]; } # scrap is a container rule for cases out of bounds |
48
|
|
|
|
|
|
|
| millenium { return $item[1]; } |
49
|
|
|
|
|
|
|
| century { return $item[1]; } |
50
|
|
|
|
|
|
|
| decade { return $item[1]; } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
number: 'nul' { $return = 0; } # try to find a word from 0 to 19 |
53
|
|
|
|
|
|
|
| 'een' { $return = 1; } |
54
|
|
|
|
|
|
|
| 'twee' { $return = 2; } |
55
|
|
|
|
|
|
|
| 'drie' { $return = 3; } |
56
|
|
|
|
|
|
|
| 'vier' { $return = 4; } |
57
|
|
|
|
|
|
|
| 'vyf' { $return = 5; } |
58
|
|
|
|
|
|
|
| 'ses' { $return = 6; } |
59
|
|
|
|
|
|
|
| 'sewe' { $return = 7; } |
60
|
|
|
|
|
|
|
| 'agt' { $return = 8; } |
61
|
|
|
|
|
|
|
| 'nege' { $return = 9; } |
62
|
|
|
|
|
|
|
| 'tien' { $return = 10; } |
63
|
|
|
|
|
|
|
| 'elf' { $return = 11; } |
64
|
|
|
|
|
|
|
| 'twaalf' { $return = 12; } |
65
|
|
|
|
|
|
|
| 'dertien' { $return = 13; } |
66
|
|
|
|
|
|
|
| 'viertien' { $return = 14; } |
67
|
|
|
|
|
|
|
| 'vyftien' { $return = 15; } |
68
|
|
|
|
|
|
|
| 'sestien' { $return = 16; } |
69
|
|
|
|
|
|
|
| 'sewentien' { $return = 17; } |
70
|
|
|
|
|
|
|
| 'agtien' { $return = 18; } |
71
|
|
|
|
|
|
|
| 'negentien' { $return = 19; } |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
tens: 'twintig' { $return = 20; } # try to find a word that representates |
74
|
|
|
|
|
|
|
| 'dertig' { $return = 30; } # values 20,30,..,90 |
75
|
|
|
|
|
|
|
| 'viertig' { $return = 40; } |
76
|
|
|
|
|
|
|
| 'vyftig' { $return = 50; } |
77
|
|
|
|
|
|
|
| 'sestig' { $return = 60; } |
78
|
|
|
|
|
|
|
| 'sewentig' { $return = 70; } |
79
|
|
|
|
|
|
|
| 'tagtig' { $return = 80; } |
80
|
|
|
|
|
|
|
| 'negentig' { $return = 90; } |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
decade: number(?) 'en' tens(?) # try to find words that represents values |
83
|
|
|
|
|
|
|
{ $return = -1; # from 0 to 99 |
84
|
|
|
|
|
|
|
for (@item) { |
85
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
86
|
|
|
|
|
|
|
$return += $$_[0] if ($return != -1); # -1 if the non-zero identifier, since |
87
|
|
|
|
|
|
|
$return = $$_[0] if ($return == -1); # zero is a valid result |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
$return = undef if ($return == -1); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
| number(?) tens(?) |
93
|
|
|
|
|
|
|
{ $return = -1; |
94
|
|
|
|
|
|
|
for (@item) { |
95
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
96
|
|
|
|
|
|
|
$return += $$_[0] if ($return != -1); # -1 if the non-zero identifier, since |
97
|
|
|
|
|
|
|
$return = $$_[0] if ($return == -1); # zero is a valid result |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
$return = undef if ($return == -1); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
| 'en' number(?) |
103
|
|
|
|
|
|
|
{ $return = -1; |
104
|
|
|
|
|
|
|
for (@item) { |
105
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
106
|
|
|
|
|
|
|
$return += $$_[0] if ($return != -1); # -1 if the non-zero identifier, since |
107
|
|
|
|
|
|
|
$return = $$_[0] if ($return == -1); # zero is a valid result |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
$return = undef if ($return == -1); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
century: number(?) 'honderd' decade(?) # try to find words that represents values |
115
|
|
|
|
|
|
|
{ $return = 0; # from 100 to 999 |
116
|
|
|
|
|
|
|
for (@item) { |
117
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
118
|
|
|
|
|
|
|
$return += $$_[0]; |
119
|
|
|
|
|
|
|
} elsif ($_ eq "honderd") { |
120
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 100 : 100; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
$return = undef if (!$return); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
millenium: century(?) decade(?) 'duisend' century(?) decade(?) # try to find words that represents values |
127
|
|
|
|
|
|
|
{ $return = 0; # from 1.000 to 999.999 |
128
|
|
|
|
|
|
|
for (@item) { |
129
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
130
|
|
|
|
|
|
|
$return += $$_[0]; |
131
|
|
|
|
|
|
|
} elsif ($_ eq "duisend") { |
132
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 1000 : 1000; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
$return = undef if (!$return); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
million: millenium(?) century(?) decade(?) # try to find words that represents values |
139
|
|
|
|
|
|
|
'miljoen' # from 1.000.000 to 999.999.999.999 |
140
|
|
|
|
|
|
|
millenium(?) century(?) decade(?) |
141
|
|
|
|
|
|
|
{ $return = 0; |
142
|
|
|
|
|
|
|
for (@item) { |
143
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
144
|
|
|
|
|
|
|
$return += $$_[0]; |
145
|
|
|
|
|
|
|
} elsif ($_ eq "miljoen") { |
146
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 1000000 : 1000000; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
$return = undef if (!$return); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
scrap: million(?) millenium(?) century(?) decade(?) # if there is something else then the numerals defined above |
153
|
|
|
|
|
|
|
/(.+)/ |
154
|
|
|
|
|
|
|
million(?) millenium(?) century(?) decade(?) # return undef and give a word of warning |
155
|
|
|
|
|
|
|
{ |
156
|
|
|
|
|
|
|
carp("unknown numeral '$1' !\n"); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
}); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# }}} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__ |