line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding; coding:utf-8; -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Lingua::NLD::Word2Num; |
4
|
|
|
|
|
|
|
# ABSTRACT: Word 2 number conversion in NLD. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# {{{ use block |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
18925
|
use 5.10.1; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
11
|
1
|
|
|
1
|
|
13
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
29
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
919
|
use Perl6::Export::Attrs; |
|
1
|
|
|
|
|
10770
|
|
|
1
|
|
|
|
|
7
|
|
14
|
1
|
|
|
1
|
|
2022
|
use Parse::RecDescent; |
|
1
|
|
|
|
|
44238
|
|
|
1
|
|
|
|
|
8
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# }}} |
17
|
|
|
|
|
|
|
# {{{ variable declarations |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 0.0682; |
20
|
|
|
|
|
|
|
my $parser = nld_numerals(); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# }}} |
23
|
|
|
|
|
|
|
# {{{ w2n convert number to text |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub w2n :Export { |
26
|
9
|
|
100
|
9
|
1
|
187743
|
my $input = shift // return; |
27
|
|
|
|
|
|
|
|
28
|
8
|
|
|
|
|
31
|
$input = lc $input; |
29
|
8
|
|
|
|
|
33
|
$input =~ s/,//g; |
30
|
8
|
|
|
|
|
27
|
$input =~ s/ //g; |
31
|
|
|
|
|
|
|
|
32
|
8
|
|
|
|
|
80
|
return $parser->numeral($input); |
33
|
1
|
|
|
1
|
|
125
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# }}} |
36
|
|
|
|
|
|
|
# {{{ nld_numerals create parser for numerals |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub nld_numerals { |
39
|
1
|
|
|
1
|
1
|
5
|
return Parse::RecDescent->new(q{ |
40
|
|
|
|
|
|
|
numeral: |
41
|
|
|
|
|
|
|
numeral: million { return $item[1]; } # root parse. go from maximum to minimum value |
42
|
|
|
|
|
|
|
| millenium { return $item[1]; } |
43
|
|
|
|
|
|
|
| century { return $item[1]; } |
44
|
|
|
|
|
|
|
| decade { return $item[1]; } |
45
|
|
|
|
|
|
|
| { return undef; } |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
number: 'negentien' { $return = 19; } # try to find a word from 0 to 19 |
48
|
|
|
|
|
|
|
| 'achtien' { $return = 18; } |
49
|
|
|
|
|
|
|
| 'zeventien' { $return = 17; } |
50
|
|
|
|
|
|
|
| 'zestien' { $return = 16; } |
51
|
|
|
|
|
|
|
| 'vijftien' { $return = 15; } |
52
|
|
|
|
|
|
|
| 'veertien' { $return = 14; } |
53
|
|
|
|
|
|
|
| 'dertien' { $return = 13; } |
54
|
|
|
|
|
|
|
| 'twaalf' { $return = 12; } |
55
|
|
|
|
|
|
|
| 'elf' { $return = 11; } |
56
|
|
|
|
|
|
|
| 'tien' { $return = 10; } |
57
|
|
|
|
|
|
|
| 'negen' { $return = 9; } |
58
|
|
|
|
|
|
|
| 'acht' { $return = 8; } |
59
|
|
|
|
|
|
|
| 'zeven' { $return = 7; } |
60
|
|
|
|
|
|
|
| 'zes' { $return = 6; } |
61
|
|
|
|
|
|
|
| 'vijf' { $return = 5; } |
62
|
|
|
|
|
|
|
| 'vier' { $return = 4; } |
63
|
|
|
|
|
|
|
| 'drie' { $return = 3; } |
64
|
|
|
|
|
|
|
| 'twee' { $return = 2; } |
65
|
|
|
|
|
|
|
| 'een' { $return = 1; } |
66
|
|
|
|
|
|
|
| 'nul' { $return = 0; } |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
tens: 'twintig' { $return = 20; } # try to find a word that representates |
69
|
|
|
|
|
|
|
| 'dertig' { $return = 30; } # values 20,30,..,90 |
70
|
|
|
|
|
|
|
| 'veertig' { $return = 40; } |
71
|
|
|
|
|
|
|
| 'vijftig' { $return = 50; } |
72
|
|
|
|
|
|
|
| 'zestig' { $return = 60; } |
73
|
|
|
|
|
|
|
| 'zeventig' { $return = 70; } |
74
|
|
|
|
|
|
|
| 'tachtig' { $return = 80; } |
75
|
|
|
|
|
|
|
| 'negentig' { $return = 90; } |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
decade: number(?) 'en' tens(?) number(?) # try to find words that represents values |
78
|
|
|
|
|
|
|
{ $return = 0; # from 0 to 99 |
79
|
|
|
|
|
|
|
for (@item) { |
80
|
|
|
|
|
|
|
$return += $$_[0] if (ref $_ && defined $$_[0]); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
| tens(?) number(?) |
84
|
|
|
|
|
|
|
{ $return = -1; |
85
|
|
|
|
|
|
|
for (@item) { |
86
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
87
|
|
|
|
|
|
|
$return += $$_[0] if ($return != -1); |
88
|
|
|
|
|
|
|
$return = $$_[0] if ($return == -1); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
$return = undef if ($return == -1); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
century: number(?) 'honderd' decade(?) # try to find words that represents values |
95
|
|
|
|
|
|
|
{ $return = 0; # from 100 to 999 |
96
|
|
|
|
|
|
|
for (@item) { |
97
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
98
|
|
|
|
|
|
|
$return += $$_[0]; |
99
|
|
|
|
|
|
|
} elsif ($_ eq "honderd") { |
100
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 100 : 100; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
$return ||= undef; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
millenium: century(?) decade(?) 'duizend' century(?) decade(?) # try to find words that represents values |
107
|
|
|
|
|
|
|
{ $return = 0; # from 1.000 to 999.999 |
108
|
|
|
|
|
|
|
for (@item) { |
109
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
110
|
|
|
|
|
|
|
$return += $$_[0]; |
111
|
|
|
|
|
|
|
} elsif ($_ eq "duizend") { |
112
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 1000 : 1000; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
$return ||= undef; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
million: millenium(?) century(?) decade(?) # try to find words that represents values |
119
|
|
|
|
|
|
|
'miljard' # from 1.000.000 to 999.999.999.999 |
120
|
|
|
|
|
|
|
millenium(?) century(?) decade(?) |
121
|
|
|
|
|
|
|
{ $return = 0; |
122
|
|
|
|
|
|
|
for (@item) { |
123
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
124
|
|
|
|
|
|
|
$return += $$_[0]; |
125
|
|
|
|
|
|
|
} elsif ($_ eq "miljard") { |
126
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 1000000 : 1000000; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
$return ||= undef; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
}); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# }}} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |