File Coverage

blib/lib/Lingua/EUS/Word2Num.pm
Criterion Covered Total %
statement 25 25 100.0
branch n/a
condition 2 2 100.0
subroutine 8 8 100.0
pod 2 2 100.0
total 37 37 100.0


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