blib/lib/Lingua/SWE/Word2Num.pm

filter: Statementstmt 100% 23 / 23 Branchbran n/a Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 36 / 36 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::SWE::Word2Num;
4 # ABSTRACT: Word to number conversion in Swedish
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 = sv_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=2 SCAR=6.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 return $parser->numeral($input);
28 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # }}}
31 # {{{ sv_numerals create parser for numerals
32  
33 sub sv_numerals {
34 1 ▶ return Parse::RecDescent->new(q{
Subroutine sv_numerals: called CC=1 SCAR=0.0
Pod documented
35  
36 numeral: million { return $item[1]; } # root parse. go from maximum to minimum value
37 | millenium { return $item[1]; }
38 | century { return $item[1]; }
39 | decade { return $item[1]; }
40 | number { return $item[1]; }
41 | { return undef; }
42  
43 number: 'nitton' { $return = 19; } # try to find a word from 0 to 19
44 | 'arton' { $return = 18; }
45 | 'sjutton' { $return = 17; }
46 | 'sexton' { $return = 16; }
47 | 'femton' { $return = 15; }
48 | 'fjorton' { $return = 14; }
49 | 'tretton' { $return = 13; }
50 | 'tolv' { $return = 12; }
51 | 'elva' { $return = 11; }
52 | 'tio' { $return = 10; }
53 | 'nio' { $return = 9; }
54 | 'åtta' { $return = 8; }
55 | 'sju' { $return = 7; }
56 | 'sex' { $return = 6; }
57 | 'fem' { $return = 5; }
58 | 'fyra' { $return = 4; }
59 | 'tre' { $return = 3; }
60 | 'två' { $return = 2; }
61 | 'ett' { $return = 1; }
62 | 'noll' { $return = 0; }
63  
64 tens: 'tjugo' { $return = 20; } # try to find a word that represents
65 | 'trettio' { $return = 30; } # values 20,30,..,90
66 | 'fyrtio' { $return = 40; }
67 | 'femtio' { $return = 50; }
68 | 'sextio' { $return = 60; }
69 | 'sjutio' { $return = 70; }
70 | 'åttio' { $return = 80; }
71 | 'nittio' { $return = 90; }
72  
73 decade: tens(?) number(?) # try to find words that represents values
74 { $return = 0; # from 0 to 99
75 for (@item) {
76 $return += $$_[0] if (ref $_ && defined $$_[0]);
77 }
78 $return = undef if(!$return);
79 }
80 century: number(?) 'hundra' decade(?) # try to find words that represents values
81 { $return = 0; # from 100 to 999
82 for (@item) {
83 if (ref $_ && defined $$_[0]) {
84 $return += $$_[0];
85 } elsif ($_ eq 'hundra') {
86 $return = ($return>0) ? $return * 100 : 100;
87 }
88 }
89 $return = undef if(!$return);
90 }
91 millenium: century(?) decade(?) 'tusen' century(?) decade(?) # try to find words that represents values
92 { $return = 0; # from 1.000 to 999.999
93 for (@item) {
94 if (ref $_ && defined $$_[0]) {
95 $return += $$_[0];
96 } elsif ($_ eq "tusen") {
97 $return = ($return>0) ? $return * 1000 : 1000;
98 }
99 }
100 $return = undef if(!$return);
101 }
102  
103 million: millenium(?) century(?) decade(?) # try to find words that represents values
104 'miljoner' # from 1.000.000 to 999.999.999.999
105 millenium(?) century(?) decade(?)
106 { $return = 0;
107 for (@item) {
108 if (ref $_ && defined $$_[0]) {
109 $return += $$_[0];
110 } elsif ($_ eq 'miljoner') {
111 $return = $return ? $return * 1000000 : 1000000;
112 }
113 }
114 $return = undef if(!$return);
115 }
116 });
117 }
118  
119 # }}}
120  
121 1 1;
122  
123 __END__
↑ Summary