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             # {{{ use block
7              
8 1     1   107351 use 5.10.1;
  1         5  
9 1     1   7 use strict;
  1         3  
  1         39  
10 1     1   7 use warnings;
  1         14  
  1         73  
11              
12 1     1   863 use Export::Attrs;
  1         12735  
  1         6  
13              
14 1     1   1867 use Parse::RecDescent;
  1         47504  
  1         10  
15             # }}}
16             # {{{ variable declarations
17             our $VERSION = '0.2603230';
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 204105 my $input = shift // return;
27              
28 3         22 $input =~ s/eta / /g; # Remove word that represents tone in speaking, but nothing for the language
29 3         12 $input =~ s/ta / /g; # *the same
30 3         13 $input =~ s/milioi bat/milioi/g; # *the same
31 3         11 $input =~ s/,//g; # Remove trick chars
32              
33 3 50       10 return 0 if $input eq 'zero';
34              
35 3   100     33 return $parser->numeral($input) || undef;
36 1     1   193 }
  1         7  
  1         8  
37             # }}}
38             # {{{ eu_numerals create parser for numerals
39             #
40             sub eu_numerals {
41 1     1 1 6 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              
72             base20: 'hogei' { $return = 20; } # Base20: 20,40,60 and 80. All
73             | 'berrogei' { $return = 40; } # other numbers are an composition
74             | 'hirurogei' { $return = 60; } # of number and base 20.
75             | 'laurogei' { $return = 80; }
76              
77             centuries: 'ehun' { $return = 100; } # try to find a word that representates
78             | 'berrehun' { $return = 200; } # values 100,200,300,...900
79             | 'hirurehun' { $return = 300; }
80             | 'laurehun' { $return = 400; }
81             | 'bostehun' { $return = 500; }
82             | 'seiehun' { $return = 600; }
83             | 'zazpiehun' { $return = 700; }
84             | 'zortziehun' { $return = 800; }
85             | 'bederatziehun' { $return = 900; }
86              
87             decade: base20(?) number(?) # try to find words that represents values
88             { $return = 0; # from 0 to 99
89             for (@item) {
90             $return += $$_[0] if (ref $_ && defined $$_[0]);
91             }
92             }
93              
94             century: centuries(1) decade(?) # try to find words that represents values
95             { $return = 0; # from 100 to 999
96             for (@item) {
97             $return += $$_[0] if (ref $_ && defined $$_[0]);
98             }
99             }
100              
101             millenium: century(?) decade(?) 'mila' century(?) decade(?) # try to find words that represents values
102             { $return = 0; # from 1.000 to 999.999
103             for (@item) {
104             if (ref $_ && defined $$_[0]) {
105             $return += $$_[0];
106             } elsif ($_ eq "mila") {
107             $return = ($return>0) ? $return * 1000 : 1000;
108             }
109             }
110             }
111              
112             million: century(?) decade(?) # try to find words that represents values
113             'milioi' # from 1.000.000 to 999.999.999
114             millenium(?) century(?) decade(?)
115             { $return = 0;
116             for (@item) {
117             if (ref $_ && defined $$_[0]) {
118             $return += $$_[0];
119             } elsif ($_ eq "milioi") {
120             $return = ($return>0) ? $return * 1000000 : 1000000;
121             }
122             }
123             }
124              
125             millions: century(?) decade(?) # try to find words that represents values
126             'mila milioi' # from 1.000.000.000 to 999.999.999.999
127             million(?) millenium(?) century(?) decade(?)
128             { $return = 0;
129             for (@item) {
130             if (ref $_ && defined $$_[0]) {
131             $return += $$_[0];
132             } elsif ($_ eq "mila milioi") {
133             $return = ($return>0) ? $return * 1000000000 : 1000000000;
134             }
135             }
136             }
137              
138              
139             });
140             }
141             # }}}
142              
143             1;
144              
145             __END__