| 1 | # For Emacs: -*- mode:cperl; mode:folding; coding:utf-8; -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Lingua::LIT::Num2Word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Number to word conversion in Lithuanian | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 nulis 1 vienas 2 du | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 trys 4 keturi 5 penki | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 šeši 7 septyni 8 aštuoni | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 devyni 10 dešimt 11 vienuolika | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 12 dvylika 13 trylika 14 keturiolika | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 15 penkiolika 16 šešiolika 17 septyniolika | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 18 aštuoniolika 19 devyniolika | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my %token2 = qw( 20 dvidešimt 30 trisdešimt | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 40 keturiasdešimt 50 penkiasdešimt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 60 šešiasdešimt 70 septyniasdešimt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 80 aštuoniasdešimt 90 devyniasdešimt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # {{{ _decline choose singular/plural/genitive form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | sub _decline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my ($count, $singular, $plural, $genitive) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decline: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $last_two = $count % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $last_one = $count % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # teens (11-19) always take genitive plural | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($last_two >= 10 && $last_two <= 19) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$last_two >= 10 and $last_two <= 19
MC/DC0%0/2
$last_two >= 10 and $last_two <= 19
$last_two >= 10
$last_two <= 19
Truth table0%0/3
A and B
A= $last_two >= 10B= $last_two <= 19
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return $genitive; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # last digit 1 => singular | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($last_one == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return $singular; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # last digit 0 => genitive plural | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($last_one == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | return $genitive; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # last digit 2-9 => plural nominative | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | return $plural; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # {{{ _hundreds convert hundreds part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | sub _hundreds { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my ($number) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hundreds: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $h = int($number / 100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($h == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return 'vienas šimtas'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return $token1{$h} . ' ' . _decline($h, 'šimtas', 'šimtai', 'šimtų'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # {{{ num2lit_cardinal number to string conversion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | sub num2lit_cardinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | my $result = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2lit_cardinal: called CC=18 SCAR=54.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | my $number = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | if !defined $number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | || $number !~ m{\A\d+\z}xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | || $number < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | || $number > 999_999_999; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # 0-19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | if ($number < 20) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | return $token1{$number}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # 20-99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($number < 100) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $remainder = $number % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $result = $token2{$number - $remainder}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($remainder != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $result .= ' ' . $token1{$remainder}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # 100-999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($number < 1_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $remainder = $number % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $result = _hundreds($number); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($remainder != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $result .= ' ' . num2lit_cardinal($remainder); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # 1_000-999_999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($number < 1_000_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $remainder = $number % 1_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $thousands = int($number / 1_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $suffix = _decline($thousands, 'tūkstantis', 'tūkstančiai', 'tūkstančių'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ($thousands == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $result = 'vienas tūkstantis'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | elsif ($thousands < 20) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $result = $token1{$thousands} . ' ' . $suffix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $result = num2lit_cardinal($thousands) . ' ' . $suffix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($remainder != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $result .= ' ' . num2lit_cardinal($remainder); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # 1_000_000-999_999_999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ($number < 1_000_000_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $remainder = $number % 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $millions = int($number / 1_000_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $suffix = _decline($millions, 'milijonas', 'milijonai', 'milijonų'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ($millions == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $result = 'vienas milijonas'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | elsif ($millions < 20) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $result = $token1{$millions} . ' ' . $suffix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $result = num2lit_cardinal($millions) . ' ' . $suffix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ($remainder != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $result .= ' ' . num2lit_cardinal($remainder); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # {{{ capabilities declare supported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | sub capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | cardinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capabilities: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | ordinal => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||