| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*- | ||||||||||||
| 2 | |||||||||||||
| 3 | package Lingua::EUS::Word2Num; | ||||||||||||
| 4 | # ABSTRACT: Word to number conversion in Basque | ||||||||||||
| 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 | |||||||||||||
| 14 | 1 | ▶ | use Parse::RecDescent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | # }}} | ||||||||||||
| 16 | # {{{ variable declarations | ||||||||||||
| 17 | 1 | our $VERSION = '0.2603270'; | |||||||||||
| 18 | |||||||||||||
| 19 | 1 | my $parser = eu_numerals(); | |||||||||||
| 20 | |||||||||||||
| 21 | # }}} | ||||||||||||
| 22 | |||||||||||||
| 23 | # {{{ w2n convert text to number | ||||||||||||
| 24 | # | ||||||||||||
| 25 | sub w2n :Export { | ||||||||||||
| 26 | 4 | ▶ | my $input = shift // return; | ||||||||||
|
Subroutine
w2n: called CC=4 SCAR=13.9
Pod
documented
Condition100%2/2
shift() // (return)
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 27 | |||||||||||||
| 28 | 3 | $input =~ s/eta / /g; # Remove word that represents tone in speaking, but nothing for the language | |||||||||||
| 29 | 3 | $input =~ s/ta / /g; # *the same | |||||||||||
| 30 | 3 | $input =~ s/milioi bat/milioi/g; # *the same | |||||||||||
| 31 | 3 | $input =~ s/,//g; # Remove trick chars | |||||||||||
| 32 | |||||||||||||
| 33 | 3 | ▶ | return 0 if $input eq 'zero'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | |||||||||||||
| 35 | 3 | ▶ | return $parser->numeral($input) || undef; | ||||||||||
|
Condition100%2/2
$parser->numeral($input) || undef
MC/DC100%1/1
$parser->numeral($input) || undef
$parser->numeral($input)
Truth table100%2/2
A
A= $parser->numeral($input)
| |||||||||||||
| 36 | 1 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 37 | # }}} | ||||||||||||
| 38 | # {{{ eu_numerals create parser for numerals | ||||||||||||
| 39 | # | ||||||||||||
| 40 | sub eu_numerals { | ||||||||||||
| 41 | 1 | ▶ | return Parse::RecDescent->new(q{ | ||||||||||
|
Subroutine
eu_numerals: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 42 | numeral: <rulevar: local $number = 0> | ||||||||||||
| 43 | numeral: millions { return $item[1]; } # root parse. go from maximum to minimum value | ||||||||||||
| 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 represents | ||||||||||||
| 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 | 1; | |||||||||||
| 142 | |||||||||||||
| 143 | __END__ | ||||||||||||