blib/lib/Lingua/CAT/Word2Num.pm

filter: Statementstmt 100% 26 / 26 Branchbran n/a Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 39 / 39 CC 2 SCAR 2.0
CC
2
Cov
100%
w2n
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*-
2  
3 package Lingua::CAT::Word2Num;
4 # ABSTRACT: Word to number conversion in Catalan
5  
6 1 ▶use 5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # {{{ use block
11  
12 1 ▶use Parse::RecDescent;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # }}}
16 # {{{ var block
17 1 our $VERSION = '0.2603270';
18 1 my $parser = cat_numerals();
19  
20 # }}}
21  
22 # {{{ w2n convert text to number
23  
24 sub w2n :Export {
25 2 ▶ my $input = shift // return;
Subroutine w2n: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
shift() // (return)
l!l
11
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
26  
27 1 $input = lc $input;
28 1 $input =~ s/\s+/ /g;
29 1 $input =~ s/^\s+|\s+$//g;
30  
31 1 return $parser->numeral($input);
32 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
33 # }}}
34 # {{{ cat_numerals create parser for numerals
35  
36 sub cat_numerals {
37 1 ▶ return Parse::RecDescent->new(q{
Subroutine cat_numerals: called CC=1 SCAR=0.0
Pod documented
38 <autoaction: { $item[1] } >
39 <nocheck>
40  
41 numeral: mega
42 | kOhOd
43 | 'zero' { 0 }
44 | { }
45  
46 number: 'un' { 1 }
47 | 'una' { 1 }
48 | 'dos' { 2 }
49 | 'dues' { 2 }
50 | 'tres' { 3 }
51 | 'quatre' { 4 }
52 | 'cinc' { 5 }
53 | 'sis' { 6 }
54 | 'vuit' { 8 }
55 | 'nou' { 9 }
56 | 'deu' { 10 }
57 | 'onze' { 11 }
58 | 'dotze' { 12 }
59 | 'tretze' { 13 }
60 | 'catorze' { 14 }
61 | 'quinze' { 15 }
62 | 'setze' { 16 }
63 | 'disset' { 17 }
64 | 'divuit' { 18 }
65 | 'dinou' { 19 }
66 | 'set' { 7 }
67 | 'vint-i-un' { 21 }
68 | 'vint-i-una' { 21 }
69 | 'vint-i-dos' { 22 }
70 | 'vint-i-dues' { 22 }
71 | 'vint-i-tres' { 23 }
72 | 'vint-i-quatre' { 24 }
73 | 'vint-i-cinc' { 25 }
74 | 'vint-i-sis' { 26 }
75 | 'vint-i-set' { 27 }
76 | 'vint-i-vuit' { 28 }
77 | 'vint-i-nou' { 29 }
78 | 'vint' { 20 }
79  
80 tens: 'trenta' { 30 }
81 | 'quaranta' { 40 }
82 | 'cinquanta' { 50 }
83 | 'seixanta' { 60 }
84 | 'setanta' { 70 }
85 | 'vuitanta' { 80 }
86 | 'noranta' { 90 }
87  
88 hundreds: number /\-?cents?/ { $item[1] * 100 }
89 | /cents?/ { 100 }
90  
91 deca: tens /-/ number { $item[1] + $item[3] }
92 | tens
93 | number
94  
95 hecto: hundreds deca { $item[1] + $item[2] }
96 | hundreds
97  
98 hOd: hecto
99 | deca
100  
101 kilo: hOd milnotmeg hOd { $item[1] * 1000 + $item[3] }
102 | hOd milnotmeg { $item[1] * 1000 }
103 | milnotmeg hOd { 1000 + $item[2] }
104 | milnotmeg { 1000 }
105  
106 milnotmeg: ...!'mili' 'mil'
107  
108 kOhOd: kilo
109 | hOd
110  
111 mega: hOd /mili(ons|ó)/ kOhOd { $item[1] * 1_000_000 + $item[3] }
112 | hOd /mili(ons|ó)/ { $item[1] * 1_000_000 }
113 });
114 }
115  
116 # }}}
117  
118 1 1;
119  
120 __END__
↑ Summary