blib/lib/Lingua/NOR/Word2Num.pm

filter: Statementstmt 100% 28 / 28 Branchbran 50.0% 1 / 2 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 97.8% 45 / 46 CC 4 SCAR 7.4
CC
4
Cov
97%
w2n
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*-
2  
3 package Lingua::NOR::Word2Num;
4 # ABSTRACT: Word to number conversion in Norwegian
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 Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Parse::RecDescent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # }}}
16 # {{{ variable declarations
17 1 our $VERSION = '0.2603270';
18 1 my $parser = no_numerals();
19  
20 # }}}
21  
22 # {{{ w2n convert text to number
23  
24 sub w2n :Export {
25 4 ▶ my $input = shift // return;
Subroutine w2n: called CC=4 SCAR=13.9
Pod documented
Condition100%2/2
shift() // (return)
l!l
31
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
26  
27 3 $input =~ s/ og / /g; # Spoke only relevant keywords
28 3 $input =~ s/ million / millioner /g; # equal
29  
30 3 $input =~ s/,//g;
31 3 $input =~ s/ //g;
32  
33 3 ▶ return 0 if $input eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $input eq "null" 0 3 3
34  
35 3 ▶ return $parser->numeral($input) || undef;
Condition100%2/2
$parser->numeral($input) || undef
l!l
21
MC/DC100%1/1
$parser->numeral($input) || undef
$parser->numeral($input)
Truth table100%2/2
A
A= $parser->numeral($input)
Aresult
11
00
36 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 # }}}
39 # {{{ no_numerals create parser for numerals
40  
41 sub no_numerals {
42 1 ▶ return Parse::RecDescent->new (q{
Subroutine no_numerals: called CC=1 SCAR=0.0
Pod documented
43 numeral: <rulevar: local $number = 0>
44 numeral: million { return $item[1]; } # root parse. go from maximum to minimum value
45 | millenium { return $item[1]; }
46 | century { return $item[1]; }
47 | decade { return $item[1]; }
48 | { return undef; }
49  
50 number: 'null' { $return = 0; } # try to find a word from 0 to 19
51 | 'nitten' { $return = 19; }
52 | 'atten' { $return = 18; }
53 | 'sytten' { $return = 17; }
54 | 'seksten' { $return = 16; }
55 | 'femten' { $return = 15; }
56 | 'fjorten' { $return = 14; }
57 | 'tretten' { $return = 13; }
58 | 'tolv' { $return = 12; }
59 | 'ellve' { $return = 11; }
60 | 'ti' { $return = 10; }
61 | 'ni' { $return = 9; }
62 | 'åtte' { $return = 8; }
63 | 'sju' { $return = 7; }
64 | 'seks' { $return = 6; }
65 | 'fem' { $return = 5; }
66 | 'fire' { $return = 4; }
67 | 'tre' { $return = 3; }
68 | 'to' { $return = 2; }
69 | 'en' { $return = 1; }
70 | 'ett' { $return = 1; }
71  
72 tens: 'tjue' { $return = 20; } # try to find a word that represents
73 | 'tretti' { $return = 30; } # values 20,30,..,90
74 | 'førti' { $return = 40; }
75 | 'femti' { $return = 50; }
76 | 'seksti' { $return = 60; }
77 | 'sytti' { $return = 70; }
78 | 'åtti' { $return = 80; }
79 | 'nitti' { $return = 90; }
80  
81 decade: tens(?) number(?) # try to find words that represents values
82 { $return = 0; # from 0 to 99
83 for (@item) {
84 $return += $$_[0] if (ref $_ && defined $$_[0]);
85 }
86 }
87  
88 century: number(?) 'hundre' decade(?) # try to find words that represents values
89 { $return = 0; # from 100 to 999
90 for (@item) {
91 if (ref $_ && defined $$_[0]) {
92 $return += $$_[0];
93 } elsif ($_ eq "hundre") {
94 $return = ($return>0) ? $return * 100 : 100;
95 }
96 }
97 }
98  
99 millenium: century(?) decade(?) 'tusen' century(?) decade(?) # try to find words that represents values
100 { $return = 0; # from 1.000 to 999.999
101 for (@item) {
102 if (ref $_ && defined $$_[0]) {
103 $return += $$_[0];
104 } elsif ($_ eq "tusen") {
105 $return = ($return>0) ? $return * 1000 : 1000;
106 }
107 }
108 }
109  
110 million: millenium(?) century(?) decade(?) # try to find words that represents values
111 'millioner' # from 1.000.000 to 999.999.999
112 millenium(?) century(?) decade(?)
113 { $return = 0;
114 for (@item) {
115 if (ref $_ && defined $$_[0]) {
116 $return += $$_[0];
117 } elsif ($_ eq "millioner") {
118 $return = ($return>0) ? $return * 1000000 : 1000000;
119 }
120 }
121 }
122 });
123 }
124  
125 # }}}
126  
127 1 1;
128  
129 __END__
↑ Summary