| 1 | # For Emacs: -*- mode:cperl; mode:folding; coding:utf-8; -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Lingua::LAV::Num2Word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Number to word conversion in Latvian | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Export::Attrs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # {{{ var block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | our $VERSION = '0.2603270'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | my %token1 = qw( 0 nulle 1 viens 2 divi | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 trīs 4 četri 5 pieci | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 seši 7 septiņi 8 astoņi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 deviņi 10 desmit 11 vienpadsmit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 12 divpadsmit 13 trīspadsmit 14 četrpadsmit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 15 piecpadsmit 16 sešpadsmit 17 septiņpadsmit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 18 astoņpadsmit 19 deviņpadsmit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my %token2 = qw( 20 divdesmit 30 trīsdesmit | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 40 četrdesmit 50 piecdesmit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 60 sešdesmit 70 septiņdesmit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 80 astoņdesmit 90 deviņdesmit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # {{{ _decline choose singular/plural form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | sub _decline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my ($count, $singular, $plural) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decline: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $last_two = $count % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $last_one = $count % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # teens (11-19) always take plural | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($last_two >= 11 && $last_two <= 19) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$last_two >= 11 and $last_two <= 19
MC/DC0%0/2
$last_two >= 11 and $last_two <= 19
$last_two >= 11
$last_two <= 19
Truth table0%0/3
A and B
A= $last_two >= 11B= $last_two <= 19
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return $plural; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # last digit 1 => singular | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($last_one == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return $singular; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # everything else => plural | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return $plural; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # {{{ _hundreds convert hundreds part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | sub _hundreds { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my ($number) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hundreds: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $h = int($number / 100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($h == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return 'simts'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $token1{$h} . ' ' . _decline($h, 'simts', 'simti'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # {{{ num2lav_cardinal number to string conversion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | sub num2lav_cardinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | my $result = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2lav_cardinal: called CC=18 SCAR=54.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | my $number = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | croak 'You should specify a number from interval [0, 999_999_999]' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not defined $number && $number =~ /\A\d+\z/msux or $number < 0 or $number > 999999999
not defined $number && $number =~ /\A\d+\z/msux or $number < 0
defined $number && $number =~ /\A\d+\z/msux
MC/DC0%0/4
not defined $number && $number =~ /\A\d+\z/msux or $number < 0 or $number > 999999999
defined $number
$number =~ /\A\d+\z/msux
$number < 0
$number > 999999999
Truth table20%1/5
not(A && B) or C or D
A= defined $numberB= $number =~ /\A\d+\z/msuxC= $number < 0D= $number > 999999999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | if !defined $number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | || $number !~ m{\A\d+\z}xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | || $number < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | || $number > 999_999_999; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # 0-19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | if ($number < 20) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | return $token1{$number}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # 20-99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ($number < 100) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $remainder = $number % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $result = $token2{$number - $remainder}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($remainder != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $result .= ' ' . $token1{$remainder}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # 100-999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($number < 1_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $remainder = $number % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $result = _hundreds($number); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($remainder != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $result .= ' ' . num2lav_cardinal($remainder); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # 1_000-999_999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ($number < 1_000_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $remainder = $number % 1_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $thousands = int($number / 1_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $suffix = _decline($thousands, 'tūkstotis', 'tūkstoši'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($thousands == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $result = 'viens tūkstotis'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | elsif ($thousands < 20) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $result = $token1{$thousands} . ' ' . $suffix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $result = num2lav_cardinal($thousands) . ' ' . $suffix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ($remainder != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $result .= ' ' . num2lav_cardinal($remainder); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # 1_000_000-999_999_999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($number < 1_000_000_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $remainder = $number % 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $millions = int($number / 1_000_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $suffix = _decline($millions, 'miljons', 'miljoni'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ($millions == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $result = 'viens miljons'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | elsif ($millions < 20) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $result = $token1{$millions} . ' ' . $suffix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $result = num2lav_cardinal($millions) . ' ' . $suffix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ($remainder != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $result .= ' ' . num2lav_cardinal($remainder); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # {{{ capabilities declare supported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | sub capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | cardinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capabilities: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | ordinal => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||