line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding; coding:utf-8; -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Lingua::ENG::Word2Num; |
4
|
|
|
|
|
|
|
# ABSTRACT: Word 2 number conversion in ENG. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# {{{ use block |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
31838
|
use 5.10.1; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
54
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
11
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
40
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
960
|
use Encode qw(decode_utf8); |
|
1
|
|
|
|
|
11478
|
|
|
1
|
|
|
|
|
81
|
|
14
|
1
|
|
|
1
|
|
1850
|
use Parse::RecDescent; |
|
1
|
|
|
|
|
77142
|
|
|
1
|
|
|
|
|
43
|
|
15
|
1
|
|
|
1
|
|
1091
|
use Perl6::Export::Attrs; |
|
1
|
|
|
|
|
11816
|
|
|
1
|
|
|
|
|
8
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# }}} |
18
|
|
|
|
|
|
|
# {{{ variables |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = 0.0682; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $parser = eng_numerals(); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# }}} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# {{{ w2n convert number to text |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub w2n :Export { |
29
|
4
|
|
100
|
4
|
1
|
304751
|
my $input = shift // return; |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
45
|
return $parser->numeral($input); |
32
|
1
|
|
|
1
|
|
114
|
} |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# }}} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# {{{ eng_numerals create parser for numerals |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub eng_numerals { |
39
|
1
|
|
|
1
|
1
|
6
|
return Parse::RecDescent->new(decode_utf8(q{ |
40
|
|
|
|
|
|
|
numeral: |
41
|
|
|
|
|
|
|
numeral: million |
42
|
|
|
|
|
|
|
{ return $item[1]; } |
43
|
|
|
|
|
|
|
| thousand |
44
|
|
|
|
|
|
|
{ return $item[1]; } |
45
|
|
|
|
|
|
|
| century |
46
|
|
|
|
|
|
|
{ return $item[1]; } |
47
|
|
|
|
|
|
|
| decade |
48
|
|
|
|
|
|
|
{ return $item[1]; } |
49
|
|
|
|
|
|
|
| { return undef; } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
number: 'twelve' { $return = 12; } |
52
|
|
|
|
|
|
|
| 'thirteen' { $return = 13; } |
53
|
|
|
|
|
|
|
| 'fourteen' { $return = 14; } |
54
|
|
|
|
|
|
|
| 'fifteen' { $return = 15; } |
55
|
|
|
|
|
|
|
| 'sixteen' { $return = 16; } |
56
|
|
|
|
|
|
|
| 'seventeen' { $return = 17; } |
57
|
|
|
|
|
|
|
| 'eighteen' { $return = 18; } |
58
|
|
|
|
|
|
|
| 'nineteen' { $return = 19; } |
59
|
|
|
|
|
|
|
| 'zero' { $return = 0; } |
60
|
|
|
|
|
|
|
| 'one' { $return = 1; } |
61
|
|
|
|
|
|
|
| 'two' { $return = 2; } |
62
|
|
|
|
|
|
|
| 'three' { $return = 3; } |
63
|
|
|
|
|
|
|
| 'four' { $return = 4; } |
64
|
|
|
|
|
|
|
| 'five' { $return = 5; } |
65
|
|
|
|
|
|
|
| 'six' { $return = 6; } |
66
|
|
|
|
|
|
|
| 'seven' { $return = 7; } |
67
|
|
|
|
|
|
|
| 'eight' { $return = 8; } |
68
|
|
|
|
|
|
|
| 'nine' { $return = 9; } |
69
|
|
|
|
|
|
|
| 'ten' { $return = 10; } |
70
|
|
|
|
|
|
|
| 'eleven' { $return = 11; } |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
tens: 'twenty' { $return = 20; } |
73
|
|
|
|
|
|
|
| 'thirty' { $return = 30; } |
74
|
|
|
|
|
|
|
| 'forty' { $return = 40; } |
75
|
|
|
|
|
|
|
| 'fifty' { $return = 50; } |
76
|
|
|
|
|
|
|
| 'sixty' { $return = 60; } |
77
|
|
|
|
|
|
|
| 'seventy' { $return = 70; } |
78
|
|
|
|
|
|
|
| 'eighty' { $return = 80; } |
79
|
|
|
|
|
|
|
| 'ninety' { $return = 90; } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
decade: tens '-' number { $return = $item[1] + $item[2]; } |
82
|
|
|
|
|
|
|
| tens number { $return = $item[1] + $item[2]; } |
83
|
|
|
|
|
|
|
| tens { $return = $item[1]; } |
84
|
|
|
|
|
|
|
| number { $return = $item[1]; } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
century: number 'hundred' decade |
87
|
|
|
|
|
|
|
{ $return = $item[1] * 100 + $item[3]; } |
88
|
|
|
|
|
|
|
| number 'hundred' |
89
|
|
|
|
|
|
|
{ $return = $item[1] * 100 } |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
thousand: century thousands century |
92
|
|
|
|
|
|
|
{ $return = $item[1] * 1000 + $item[3]; } |
93
|
|
|
|
|
|
|
| century thousands decade |
94
|
|
|
|
|
|
|
{ $return = $item[1] * 1000 + $item[3]; } |
95
|
|
|
|
|
|
|
| century thousands |
96
|
|
|
|
|
|
|
{ $return = $item[1] * 1000; } |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
| decade thousands century |
99
|
|
|
|
|
|
|
{ $return = $item[1] * 1000 + $item[3]; } |
100
|
|
|
|
|
|
|
| decade thousands decade |
101
|
|
|
|
|
|
|
{ $return = $item[1] * 1000 + $item[3]; } |
102
|
|
|
|
|
|
|
| decade thousands |
103
|
|
|
|
|
|
|
{ $return = $item[1] * 1000; } |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
| number thousands century |
106
|
|
|
|
|
|
|
{ $return = $item[1] * 1000 + $item[3]; } |
107
|
|
|
|
|
|
|
| number thousands decade |
108
|
|
|
|
|
|
|
{ $return = $item[1] * 1000 + $item[3]; } |
109
|
|
|
|
|
|
|
| number thousands |
110
|
|
|
|
|
|
|
{ $return = $item[1] * 1000; } |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
| 'thousand' century |
113
|
|
|
|
|
|
|
{ $return = 1000 + $item[2]; } |
114
|
|
|
|
|
|
|
| 'thousand' decade |
115
|
|
|
|
|
|
|
{ $return = 1000 + $item[2]; } |
116
|
|
|
|
|
|
|
| 'thousand' |
117
|
|
|
|
|
|
|
{ $return = 1000; } |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
| century 'one' 'thousand' century |
120
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1000 + $item[4]; } |
121
|
|
|
|
|
|
|
| century 'one' 'thousand' decade |
122
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1000 + $item[4]; } |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
| decade 'one' 'tisíc' century |
125
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1000 + $item[4]; } |
126
|
|
|
|
|
|
|
| decade 'one' 'tisíc' decade |
127
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1000 + $item[4]; } |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
| century 'one' 'thousand' |
130
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1000; } |
131
|
|
|
|
|
|
|
| decade 'one' 'thousand' |
132
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1000; } |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
thousands: 'thousand' |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
million: century millions thousand |
137
|
|
|
|
|
|
|
{ $return = $item[1] * 1_000_000 + $item[3]; } |
138
|
|
|
|
|
|
|
| century millions century |
139
|
|
|
|
|
|
|
{ $return = $item[1] * 1_000_000 + $item[3]; } |
140
|
|
|
|
|
|
|
| century millions decade |
141
|
|
|
|
|
|
|
{ $return = $item[1] * 1_000_000 + $item[3]; } |
142
|
|
|
|
|
|
|
| century millions |
143
|
|
|
|
|
|
|
{ $return = $item[1] * 1_000_000; } |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
| decade millions thousand |
146
|
|
|
|
|
|
|
{ $return = $item[1] * 1_000_000 + $item[3]; } |
147
|
|
|
|
|
|
|
| decade millions century |
148
|
|
|
|
|
|
|
{ $return = $item[1] * 1_000_000 + $item[3]; } |
149
|
|
|
|
|
|
|
| decade millions decade |
150
|
|
|
|
|
|
|
{ $return = $item[1] * 1_000_000 + $item[3]; } |
151
|
|
|
|
|
|
|
| decade millions |
152
|
|
|
|
|
|
|
{ $return = $item[1] * 1_000_000; } |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
| 'million' thousand |
155
|
|
|
|
|
|
|
{ $return = 1_000_000 + $item[2]; } |
156
|
|
|
|
|
|
|
| 'million' century |
157
|
|
|
|
|
|
|
{ $return = 1_000_000 + $item[2]; } |
158
|
|
|
|
|
|
|
| 'million' decade |
159
|
|
|
|
|
|
|
{ $return = 1_000_000 + $item[2]; } |
160
|
|
|
|
|
|
|
| 'million' |
161
|
|
|
|
|
|
|
{ $return = 1_000_000; } |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
| century 'one' 'million' thousand |
164
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1_000_000 + $item[4]; } |
165
|
|
|
|
|
|
|
| century 'one' 'million' century |
166
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1_000_000 + $item[4]; } |
167
|
|
|
|
|
|
|
| century 'one' 'million' decade |
168
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1_000_000 + $item[4]; } |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
| decade 'one' 'million' thousand |
171
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1_000_000 + $item[4]; } |
172
|
|
|
|
|
|
|
| decade 'one' 'million' century |
173
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1_000_000 + $item[4]; } |
174
|
|
|
|
|
|
|
| decade 'one' 'million' decade |
175
|
|
|
|
|
|
|
{ $return = ($item[1] + 1) * 1_000_000 + $item[4]; } |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
millions: 'millions' |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
})); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# }}} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
__END__ |