line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::NL::Numbers; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '1.3'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6611
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1358
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my $numbers = { |
8
|
|
|
|
|
|
|
0 => 'nul', |
9
|
|
|
|
|
|
|
1 => 'een', |
10
|
|
|
|
|
|
|
2 => 'twee', |
11
|
|
|
|
|
|
|
3 => 'drie', |
12
|
|
|
|
|
|
|
4 => 'vier', |
13
|
|
|
|
|
|
|
5 => 'vijf', |
14
|
|
|
|
|
|
|
6 => 'zes', |
15
|
|
|
|
|
|
|
7 => 'zeven', |
16
|
|
|
|
|
|
|
8 => 'acht', |
17
|
|
|
|
|
|
|
9 => 'negen', |
18
|
|
|
|
|
|
|
10 => 'tien', |
19
|
|
|
|
|
|
|
11 => 'elf', |
20
|
|
|
|
|
|
|
12 => 'twaalf', |
21
|
|
|
|
|
|
|
13 => 'dertien', |
22
|
|
|
|
|
|
|
14 => 'veertien', |
23
|
|
|
|
|
|
|
15 => 'vijftien', |
24
|
|
|
|
|
|
|
16 => 'zestien', |
25
|
|
|
|
|
|
|
17 => 'zeventien', |
26
|
|
|
|
|
|
|
18 => 'achtien', |
27
|
|
|
|
|
|
|
19 => 'negentien', |
28
|
|
|
|
|
|
|
20 => 'twintig', |
29
|
|
|
|
|
|
|
30 => 'dertig', |
30
|
|
|
|
|
|
|
40 => 'veertig', |
31
|
|
|
|
|
|
|
50 => 'vijftig', |
32
|
|
|
|
|
|
|
60 => 'zestig', |
33
|
|
|
|
|
|
|
70 => 'zeventig', |
34
|
|
|
|
|
|
|
80 => 'tachtig', |
35
|
|
|
|
|
|
|
90 => 'negentig', |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
41
|
0
|
|
0
|
|
|
|
my $number = shift || ''; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $self = {}; |
44
|
0
|
|
|
|
|
|
bless $self, $class; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if( $number =~ /\d+/ ) { |
47
|
0
|
|
|
|
|
|
return( $self->parse($number) ); |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return( $self ); |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub parse |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
my $number = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $digits; |
60
|
0
|
|
|
|
|
|
my $ret = ''; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if( defined($numbers->{$number}) ) { |
63
|
0
|
|
|
|
|
|
$ret = $numbers->{$number}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
0
|
|
|
|
|
|
my $ret_array = []; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
@{$digits} = reverse( split('', $number) ); |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# tens of billions |
71
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[10]) && ($digits->[10] != 0) ) { |
|
|
0
|
0
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $temp = $self->_formatTens( $digits->[9], $digits->[10] ); |
73
|
0
|
|
|
|
|
|
unshift @{$ret_array}, "$temp biljoen"; |
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif( defined($digits->[9]) && ($digits->[9] != 0) ) { |
76
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[9], ' biljoen' ); |
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# hundreds of millions |
80
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[8]) && ($digits->[8] != 0) ) { |
81
|
0
|
0
|
0
|
|
|
|
if( ($digits->[7] == 0) && ($digits->[6] == 0) ) { |
82
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[8], ' honderd miljard' ); |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[8], ' honderd' ); |
|
0
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# tens of millions |
90
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[7]) && ($digits->[7] != 0) ) { |
|
|
0
|
0
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $temp = $self->_formatTens( $digits->[6], $digits->[7] ); |
92
|
0
|
|
|
|
|
|
unshift @{$ret_array}, "$temp miljard"; |
|
0
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif( defined($digits->[6]) && ($digits->[6] != 0) ) { |
95
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[6], ' miljard' ); |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# hundreds of thousands |
99
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[5]) && ($digits->[5] != 0) ) { |
100
|
0
|
0
|
0
|
|
|
|
if( ($digits->[4] == 0) && ($digits->[3] == 0) ) { |
101
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[5], ' honderd duizend' ); |
|
0
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[5], ' honderd' ); |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
}; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# tens of thousands |
109
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[4]) && ($digits->[4] != 0) ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $temp = $self->_formatTens( $digits->[3], $digits->[4] ); |
111
|
0
|
|
|
|
|
|
unshift @{$ret_array}, "$temp duizend"; |
|
0
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
elsif( defined($digits->[3]) && ($digits->[3] == 1) ) { |
114
|
0
|
|
|
|
|
|
unshift @{$ret_array}, ' duizend'; |
|
0
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
elsif( defined($digits->[3]) && ($digits->[3] != 0) ) { |
117
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[3], ' duizend' ); |
|
0
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
}; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# hundreds |
121
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[2]) && ($digits->[2] == 1) ) { |
|
|
0
|
0
|
|
|
|
|
122
|
0
|
|
|
|
|
|
unshift @{$ret_array}, 'honderd'; |
|
0
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
elsif( defined($digits->[2]) && ($digits->[2] != 0) ) { |
125
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[2], 'honderd' ); |
|
0
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
}; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# tens |
129
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatTens( $digits->[0], $digits->[1], 'en' ); |
|
0
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
$ret = $self->_sortReturn( $ret_array, $digits ); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
return( $ret ); |
136
|
|
|
|
|
|
|
}; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _sortReturn |
140
|
|
|
|
|
|
|
{ |
141
|
0
|
|
|
0
|
|
|
my $self = shift; |
142
|
0
|
|
|
|
|
|
my $ret_array = shift; |
143
|
0
|
|
|
|
|
|
my $digits = shift; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
my $large_nums = 0; |
146
|
0
|
|
|
|
|
|
my $ret = ''; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
my $size = @{$ret_array}; |
|
0
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
|
if( $size == 1 ) { |
|
|
0
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
return( $ret_array->[0] ); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
elsif( $size > 1 ) { |
154
|
0
|
|
|
|
|
|
$large_nums = 1; |
155
|
|
|
|
|
|
|
}; |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
for( my $i = $size; $i > 0; $i-- ) { |
158
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
|
if( defined($ret_array->[$i]) ) { |
160
|
0
|
0
|
|
|
|
|
if( $ret_array->[$i] =~ /(miljard|duizend)/ ) { |
161
|
0
|
|
|
|
|
|
$ret .= $ret_array->[$i] .', '; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
0
|
|
|
|
|
|
$ret .= $ret_array->[$i] .' '; |
165
|
|
|
|
|
|
|
}; |
166
|
|
|
|
|
|
|
}; |
167
|
|
|
|
|
|
|
}; |
168
|
|
|
|
|
|
|
|
169
|
0
|
0
|
0
|
|
|
|
if( ($digits->[0] == 0) && ($digits->[1] == 0) ) { |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
170
|
|
|
|
|
|
|
# do nothing |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
elsif( ($digits->[0] == 0) || ($digits->[1] == 0) || ($digits->[1] == 1) ) { |
173
|
0
|
0
|
|
|
|
|
if( $large_nums ) { |
174
|
0
|
|
|
|
|
|
$ret .= ' en '; |
175
|
|
|
|
|
|
|
}; |
176
|
0
|
|
|
|
|
|
$ret .= $ret_array->[0]; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
else { |
179
|
0
|
|
|
|
|
|
$ret .= ' '. $ret_array->[0]; |
180
|
|
|
|
|
|
|
}; |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
$ret =~ s/(^ |\s{2,}| $)/ /g; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
return( $ret ); |
185
|
|
|
|
|
|
|
}; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub _formatTens |
189
|
|
|
|
|
|
|
{ |
190
|
0
|
|
|
0
|
|
|
my $self = shift; |
191
|
0
|
|
|
|
|
|
my $units = shift; |
192
|
0
|
|
|
|
|
|
my $tens = shift; |
193
|
0
|
|
0
|
|
|
|
my $en = shift || ' en '; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# Both digits are zero |
196
|
0
|
0
|
0
|
|
|
|
unless( $units || $tens ) { |
197
|
0
|
|
|
|
|
|
return; |
198
|
|
|
|
|
|
|
}; |
199
|
|
|
|
|
|
|
|
200
|
0
|
0
|
0
|
|
|
|
if( $tens == 0 ) { |
|
|
0
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
return( $numbers->{$units} ); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
elsif( ($tens == 1) || ($units == 0) ) { |
204
|
0
|
|
|
|
|
|
my $temp = $tens . $units; |
205
|
0
|
|
|
|
|
|
return( $numbers->{$temp} ); |
206
|
|
|
|
|
|
|
}; |
207
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
my $temp = $tens . 0; |
209
|
0
|
|
|
|
|
|
return( $numbers->{$units} . $en . $numbers->{$temp} ); |
210
|
|
|
|
|
|
|
}; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub _formatLarge |
214
|
|
|
|
|
|
|
{ |
215
|
0
|
|
|
0
|
|
|
my $self = shift; |
216
|
0
|
|
|
|
|
|
my $digit = shift; |
217
|
0
|
|
|
|
|
|
my $word = shift; |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
my $ret = "$numbers->{$digit}$word"; |
220
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
return( $ret ); |
222
|
|
|
|
|
|
|
}; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=pod |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 NAME |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Lingua::NL::Numbers - Perl module for converting numeric values into their Dutch equivalents |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 DESCRIPTION |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Initial release, documentation and updates will follow. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 SYNOPSIS |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
use Lingua::NL::Numbers; |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
my $numbers = Lingua::NL::Numbers->new; |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
my $text = $numbers->parse( 123 ); |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
# prints 'een honderd, drie en twintig' |
249
|
|
|
|
|
|
|
print $text; |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 KNOWN BUGS |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
None, but that does not mean there are not any. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 AUTHOR |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Alistair Francis, http://search.cpan.org/~friffin/ |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=cut |
261
|
|
|
|
|
|
|
|