line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding; coding:utf-8; -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Lingua::SPA::Word2Num; |
4
|
|
|
|
|
|
|
# ABSTRACT: Word 2 number conversion in SPA. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# {{{ use block |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
29627
|
use 5.10.1; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
49
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
11
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
33
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
1847
|
use Parse::RecDescent; |
|
1
|
|
|
|
|
56866
|
|
|
1
|
|
|
|
|
8
|
|
14
|
1
|
|
|
1
|
|
1027
|
use Perl6::Export::Attrs; |
|
1
|
|
|
|
|
12617
|
|
|
1
|
|
|
|
|
8
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# }}} |
17
|
|
|
|
|
|
|
# {{{ variable declarations |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 0.0682; |
20
|
|
|
|
|
|
|
my $parser = spa_numerals(); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# }}} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# {{{ w2n convert number to text |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub w2n :Export { |
27
|
4
|
|
100
|
4
|
1
|
73792
|
my $input = shift // return; |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
12
|
$input =~ s/,//g; |
30
|
3
|
|
|
|
|
12
|
$input =~ s/ //g; |
31
|
3
|
|
|
|
|
10
|
$input =~ s/millones/lones/g; # grant unique word identifier |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
37
|
return $parser->numeral($input); |
34
|
1
|
|
|
1
|
|
173
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
35
|
|
|
|
|
|
|
# }}} |
36
|
|
|
|
|
|
|
# {{{ spa_numerals create parser for numerals |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub spa_numerals { |
39
|
1
|
|
|
1
|
1
|
8
|
return Parse::RecDescent->new(q{ |
40
|
|
|
|
|
|
|
numeral: million { return $item[1]; } # root parse. go from maximum to minimum value |
41
|
|
|
|
|
|
|
| millenium { return $item[1]; } |
42
|
|
|
|
|
|
|
| century { return $item[1]; } |
43
|
|
|
|
|
|
|
| decade { return $item[1]; } |
44
|
|
|
|
|
|
|
| { return undef; } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
number: 'cero' { $return = 0; } # try to find a word from 0 to 29 |
47
|
|
|
|
|
|
|
| 'un' { $return = 1; } |
48
|
|
|
|
|
|
|
| 'dos' { $return = 2; } |
49
|
|
|
|
|
|
|
| 'tres' { $return = 3; } |
50
|
|
|
|
|
|
|
| 'cuatro' { $return = 4; } |
51
|
|
|
|
|
|
|
| 'cinco' { $return = 5; } |
52
|
|
|
|
|
|
|
| 'seis' { $return = 6; } |
53
|
|
|
|
|
|
|
| 'siete' { $return = 7; } |
54
|
|
|
|
|
|
|
| 'ocho' { $return = 8; } |
55
|
|
|
|
|
|
|
| 'nueve' { $return = 9; } |
56
|
|
|
|
|
|
|
| 'diez' { $return = 10; } |
57
|
|
|
|
|
|
|
| 'once' { $return = 11; } |
58
|
|
|
|
|
|
|
| 'doce' { $return = 12; } |
59
|
|
|
|
|
|
|
| 'trece' { $return = 13; } |
60
|
|
|
|
|
|
|
| 'catorce' { $return = 14; } |
61
|
|
|
|
|
|
|
| 'quince' { $return = 15; } |
62
|
|
|
|
|
|
|
| 'dieciséis' { $return = 16; } |
63
|
|
|
|
|
|
|
| 'diecisiete' { $return = 17; } |
64
|
|
|
|
|
|
|
| 'dieciocho' { $return = 18; } |
65
|
|
|
|
|
|
|
| 'diecinueve' { $return = 19; } |
66
|
|
|
|
|
|
|
| 'veinte' { $return = 20; } |
67
|
|
|
|
|
|
|
| 'veintiun' { $return = 21; } |
68
|
|
|
|
|
|
|
| 'veintidós' { $return = 22; } |
69
|
|
|
|
|
|
|
| 'veintitrés' { $return = 23; } |
70
|
|
|
|
|
|
|
| 'veinticuatro' { $return = 24; } |
71
|
|
|
|
|
|
|
| 'veinticinco' { $return = 25; } |
72
|
|
|
|
|
|
|
| 'veintiséis' { $return = 26; } |
73
|
|
|
|
|
|
|
| 'veintisiete' { $return = 27; } |
74
|
|
|
|
|
|
|
| 'veintiocho' { $return = 28; } |
75
|
|
|
|
|
|
|
| 'veintinueve' { $return = 29; } |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
tens: 'treinta' { $return = 30; } # try to find a word that representates |
78
|
|
|
|
|
|
|
| 'cuarenta' { $return = 40; } # values 20,30,..,90 |
79
|
|
|
|
|
|
|
| 'cincuenta' { $return = 50; } |
80
|
|
|
|
|
|
|
| 'sesenta' { $return = 60; } |
81
|
|
|
|
|
|
|
| 'setenta' { $return = 70; } |
82
|
|
|
|
|
|
|
| 'ochenta' { $return = 80; } |
83
|
|
|
|
|
|
|
| 'noventa' { $return = 90; } |
84
|
|
|
|
|
|
|
| 'cien' { $return = 100; } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
hundreds: 'ciento' { $return = 100; } |
87
|
|
|
|
|
|
|
| 'doscientos' { $return = 200; } |
88
|
|
|
|
|
|
|
| 'trescientos' { $return = 300; } |
89
|
|
|
|
|
|
|
| 'cuatrocientos' { $return = 400; } |
90
|
|
|
|
|
|
|
| 'quinientos' { $return = 500; } |
91
|
|
|
|
|
|
|
| 'seiscientos' { $return = 600; } |
92
|
|
|
|
|
|
|
| 'setecientos' { $return = 700; } |
93
|
|
|
|
|
|
|
| 'ochocientos' { $return = 800; } |
94
|
|
|
|
|
|
|
| 'novecientos' { $return = 900; } |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
decade: tens(?) 'y' number(?) # try to find words that represents values |
97
|
|
|
|
|
|
|
{ $return = 0; # from 0 to 100 |
98
|
|
|
|
|
|
|
for (@item) { |
99
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
100
|
|
|
|
|
|
|
$return += $$_[0] if ($return != -1); # -1 if the non-zero identifier, since |
101
|
|
|
|
|
|
|
$return = $$_[0] if ($return == -1); # zero is a valid result |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
$return = undef if ($return == -1); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
| tens(?) number(?) |
107
|
|
|
|
|
|
|
{ $return = -1; |
108
|
|
|
|
|
|
|
for (@item) { |
109
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
110
|
|
|
|
|
|
|
$return += $$_[0] if ($return != -1); # -1 if the non-zero identifier, since |
111
|
|
|
|
|
|
|
$return = $$_[0] if ($return == -1); # zero is a valid result |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
$return = undef if ($return == -1); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
century: hundreds(?) decade(?) # try to find words that represents values |
118
|
|
|
|
|
|
|
{ $return = 0; # from 100 to 999 |
119
|
|
|
|
|
|
|
for (@item) { |
120
|
|
|
|
|
|
|
next if (!ref $_ || !defined $$_[0]); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$return += $$_[0]; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
$return = undef if (!$return); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
millenium: century(?) 'mil' century(?) # try to find words that represents values |
128
|
|
|
|
|
|
|
{ $return = 0; # from 1.000 to 999.999 |
129
|
|
|
|
|
|
|
for (@item) { |
130
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
131
|
|
|
|
|
|
|
$return += $$_[0]; |
132
|
|
|
|
|
|
|
} elsif ($_ eq "mil") { |
133
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 1000 : 1000; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
$return = undef if (!$return); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
million: millenium(?) century(?) # try to find words that represents values |
140
|
|
|
|
|
|
|
'lones' # from 1.000.000 to 999.999.999.999 |
141
|
|
|
|
|
|
|
millenium(?) century(?) |
142
|
|
|
|
|
|
|
{ $return = 0; |
143
|
|
|
|
|
|
|
for (@item) { |
144
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
145
|
|
|
|
|
|
|
$return += $$_[0]; |
146
|
|
|
|
|
|
|
} elsif ($_ eq "lones") { |
147
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 1000000 : 1000000; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
$return = undef if (!$return); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
}); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# }}} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__END__ |