File Coverage

blib/lib/Lingua/EUS/Word2Num.pm
Criterion Covered Total %
statement 25 25 100.0
branch 1 2 50.0
condition 4 4 100.0
subroutine 8 8 100.0
pod 2 2 100.0
total 40 41 97.5


line stmt bran cond sub pod time code
1             # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*-
2              
3             package Lingua::EUS::Word2Num;
4             # ABSTRACT: Word 2 number conversion in EUS.
5              
6 1     1   88963 use 5.16.0;
  1         3  
7 1     1   6 use utf8;
  1         2  
  1         12  
8 1     1   20 use warnings;
  1         1  
  1         56  
9              
10             # {{{ use block
11              
12 1     1   530 use Export::Attrs;
  1         9447  
  1         7  
13              
14 1     1   1204 use Parse::RecDescent;
  1         36436  
  1         9  
15             # }}}
16             # {{{ variable declarations
17             our $VERSION = '0.2603250';
18              
19             my $parser = eu_numerals();
20              
21             # }}}
22              
23             # {{{ w2n convert number to text
24             #
25             sub w2n :Export {
26 4   100 4 1 326493 my $input = shift // return;
27              
28 3         21 $input =~ s/eta / /g; # Remove word that represents tone in speaking, but nothing for the language
29 3         14 $input =~ s/ta / /g; # *the same
30 3         16 $input =~ s/milioi bat/milioi/g; # *the same
31 3         8 $input =~ s/,//g; # Remove trick chars
32              
33 3 50       13 return 0 if $input eq 'zero';
34              
35 3   100     38 return $parser->numeral($input) || undef;
36 1     1   205 }
  1         2  
  1         13  
37             # }}}
38             # {{{ eu_numerals create parser for numerals
39             #
40             sub eu_numerals {
41 1     1 1 5 return Parse::RecDescent->new(q{
42             numeral:
43             numeral: millions { return $item[1]; } # root parse. go from maximum to minimum valeu
44             | million { return $item[1]; }
45             | millenium { return $item[1]; }
46             | century { return $item[1]; }
47             | decade { return $item[1]; }
48             | { return undef; }
49              
50             number: 'zero' { $return = 0; } # try to find a word from 0 to 19
51             | 'bat' { $return = 1; }
52             | 'bi' { $return = 2; }
53             | 'hiru' { $return = 3; }
54             | 'lau' { $return = 4; }
55             | 'bost' { $return = 5; }
56             | 'sei' { $return = 6; }
57             | 'zazpi' { $return = 7; }
58             | 'zortzi' { $return = 8; }
59             | 'bederatzi' { $return = 9; }
60             | 'hamar' { $return = 10; }
61             | 'hamaika' { $return = 11; }
62             | 'hamabi' { $return = 12; }
63             | 'hamahiru' { $return = 13; }
64             | 'hamalau' { $return = 14; }
65             | 'hamabost' { $return = 15; }
66             | 'hamasei' { $return = 16; }
67             | 'hamazazpi' { $return = 17; }
68             | 'hemezortzi' { $return = 18; }
69             | 'hemeretzi' { $return = 19; }
70              
71             base20: 'hogei' { $return = 20; } # Base20: 20,40,60 and 80. All
72             | 'berrogei' { $return = 40; } # other numbers are an composition
73             | 'hirurogei' { $return = 60; } # of number and base 20.
74             | 'laurogei' { $return = 80; }
75              
76             centuries: 'ehun' { $return = 100; } # try to find a word that representates
77             | 'berrehun' { $return = 200; } # values 100,200,300,...900
78             | 'hirurehun' { $return = 300; }
79             | 'laurehun' { $return = 400; }
80             | 'bostehun' { $return = 500; }
81             | 'seiehun' { $return = 600; }
82             | 'zazpiehun' { $return = 700; }
83             | 'zortziehun' { $return = 800; }
84             | 'bederatziehun' { $return = 900; }
85              
86             decade: base20(?) number(?) # try to find words that represents values
87             { $return = 0; # from 0 to 99
88             for (@item) {
89             $return += $$_[0] if (ref $_ && defined $$_[0]);
90             }
91             }
92              
93             century: centuries(1) decade(?) # try to find words that represents values
94             { $return = 0; # from 100 to 999
95             for (@item) {
96             $return += $$_[0] if (ref $_ && defined $$_[0]);
97             }
98             }
99              
100             millenium: century(?) decade(?) 'mila' century(?) decade(?) # try to find words that represents values
101             { $return = 0; # from 1.000 to 999.999
102             for (@item) {
103             if (ref $_ && defined $$_[0]) {
104             $return += $$_[0];
105             } elsif ($_ eq "mila") {
106             $return = ($return>0) ? $return * 1000 : 1000;
107             }
108             }
109             }
110              
111             million: century(?) decade(?) # try to find words that represents values
112             'milioi' # from 1.000.000 to 999.999.999
113             millenium(?) century(?) decade(?)
114             { $return = 0;
115             for (@item) {
116             if (ref $_ && defined $$_[0]) {
117             $return += $$_[0];
118             } elsif ($_ eq "milioi") {
119             $return = ($return>0) ? $return * 1000000 : 1000000;
120             }
121             }
122             }
123              
124             millions: century(?) decade(?) # try to find words that represents values
125             'mila milioi' # from 1.000.000.000 to 999.999.999.999
126             million(?) millenium(?) century(?) decade(?)
127             { $return = 0;
128             for (@item) {
129             if (ref $_ && defined $$_[0]) {
130             $return += $$_[0];
131             } elsif ($_ eq "mila milioi") {
132             $return = ($return>0) ? $return * 1000000000 : 1000000000;
133             }
134             }
135             }
136              
137             });
138             }
139             # }}}
140              
141             1;
142              
143             __END__