line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding; coding:utf-8; -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Lingua::NOR::Word2Num; |
4
|
|
|
|
|
|
|
# ABSTRACT: Word 2 number conversion in NOR. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# {{{ use block |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
21082
|
use 5.10.1; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
11
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
25
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
754
|
use Perl6::Export::Attrs; |
|
1
|
|
|
|
|
9453
|
|
|
1
|
|
|
|
|
7
|
|
14
|
1
|
|
|
1
|
|
1672
|
use Parse::RecDescent; |
|
1
|
|
|
|
|
45361
|
|
|
1
|
|
|
|
|
7
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# }}} |
17
|
|
|
|
|
|
|
# {{{ variable declarations |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 0.0682; |
20
|
|
|
|
|
|
|
our $INFO = { |
21
|
|
|
|
|
|
|
rev => '$Rev: 682 $', |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $parser = no_numerals(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# }}} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# {{{ w2n convert number to text |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub w2n :Export { |
31
|
4
|
|
100
|
4
|
1
|
56269
|
my $input = shift // return; |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
19
|
$input =~ s/ og / /g; # Spoke only relevant keywords |
34
|
3
|
|
|
|
|
9
|
$input =~ s/ million / millioner /g; # equal |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
8
|
$input =~ s/,//g; |
37
|
3
|
|
|
|
|
14
|
$input =~ s/ //g; |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
33
|
return $parser->numeral($input); |
40
|
1
|
|
|
1
|
|
153
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# }}} |
43
|
|
|
|
|
|
|
# {{{ no_numerals create parser for numerals |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub no_numerals { |
46
|
1
|
|
|
1
|
1
|
5
|
return Parse::RecDescent->new (q{ |
47
|
|
|
|
|
|
|
numeral: |
48
|
|
|
|
|
|
|
numeral: million { return $item[1]; } # root parse. go from maximum to minimum value |
49
|
|
|
|
|
|
|
| millenium { return $item[1]; } |
50
|
|
|
|
|
|
|
| century { return $item[1]; } |
51
|
|
|
|
|
|
|
| decade { return $item[1]; } |
52
|
|
|
|
|
|
|
| { return undef; } |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
number: 'null' { $return = 0; } # try to find a word from 0 to 19 |
55
|
|
|
|
|
|
|
| 'nitten' { $return = 19; } |
56
|
|
|
|
|
|
|
| 'atten' { $return = 18; } |
57
|
|
|
|
|
|
|
| 'sytten' { $return = 17; } |
58
|
|
|
|
|
|
|
| 'seksten' { $return = 16; } |
59
|
|
|
|
|
|
|
| 'femten' { $return = 15; } |
60
|
|
|
|
|
|
|
| 'fjorten' { $return = 14; } |
61
|
|
|
|
|
|
|
| 'tretten' { $return = 13; } |
62
|
|
|
|
|
|
|
| 'tolv' { $return = 12; } |
63
|
|
|
|
|
|
|
| 'ellve' { $return = 11; } |
64
|
|
|
|
|
|
|
| 'ti' { $return = 10; } |
65
|
|
|
|
|
|
|
| 'ni' { $return = 9; } |
66
|
|
|
|
|
|
|
| 'åtte' { $return = 8; } |
67
|
|
|
|
|
|
|
| 'sju' { $return = 7; } |
68
|
|
|
|
|
|
|
| 'seks' { $return = 6; } |
69
|
|
|
|
|
|
|
| 'fem' { $return = 5; } |
70
|
|
|
|
|
|
|
| 'fire' { $return = 4; } |
71
|
|
|
|
|
|
|
| 'tre' { $return = 3; } |
72
|
|
|
|
|
|
|
| 'to' { $return = 2; } |
73
|
|
|
|
|
|
|
| 'en' { $return = 1; } |
74
|
|
|
|
|
|
|
| 'ett' { $return = 1; } |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
tens: 'tjue' { $return = 20; } # try to find a word that representates |
77
|
|
|
|
|
|
|
| 'tretti' { $return = 30; } # values 20,30,..,90 |
78
|
|
|
|
|
|
|
| 'førti' { $return = 40; } |
79
|
|
|
|
|
|
|
| 'femti' { $return = 50; } |
80
|
|
|
|
|
|
|
| 'seksti' { $return = 60; } |
81
|
|
|
|
|
|
|
| 'sytti' { $return = 70; } |
82
|
|
|
|
|
|
|
| 'åtti' { $return = 80; } |
83
|
|
|
|
|
|
|
| 'nitti' { $return = 90; } |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
decade: tens(?) number(?) # try to find words that represents values |
86
|
|
|
|
|
|
|
{ $return = 0; # from 0 to 99 |
87
|
|
|
|
|
|
|
for (@item) { |
88
|
|
|
|
|
|
|
$return += $$_[0] if (ref $_ && defined $$_[0]); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
century: number(?) 'hundre' decade(?) # try to find words that represents values |
93
|
|
|
|
|
|
|
{ $return = 0; # from 100 to 999 |
94
|
|
|
|
|
|
|
for (@item) { |
95
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
96
|
|
|
|
|
|
|
$return += $$_[0]; |
97
|
|
|
|
|
|
|
} elsif ($_ eq "hundre") { |
98
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 100 : 100; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
millenium: century(?) decade(?) 'tusen' century(?) decade(?) # try to find words that represents values |
104
|
|
|
|
|
|
|
{ $return = 0; # from 1.000 to 999.999 |
105
|
|
|
|
|
|
|
for (@item) { |
106
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
107
|
|
|
|
|
|
|
$return += $$_[0]; |
108
|
|
|
|
|
|
|
} elsif ($_ eq "tusen") { |
109
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 1000 : 1000; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
million: millenium(?) century(?) decade(?) # try to find words that represents values |
115
|
|
|
|
|
|
|
'millioner' # from 1.000.000 to 999.999.999 |
116
|
|
|
|
|
|
|
millenium(?) century(?) decade(?) |
117
|
|
|
|
|
|
|
{ $return = 0; |
118
|
|
|
|
|
|
|
for (@item) { |
119
|
|
|
|
|
|
|
if (ref $_ && defined $$_[0]) { |
120
|
|
|
|
|
|
|
$return += $$_[0]; |
121
|
|
|
|
|
|
|
} elsif ($_ eq "millioner") { |
122
|
|
|
|
|
|
|
$return = ($return>0) ? $return * 1000000 : 1000000; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
}); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# }}} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |