| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Lingua::LTZ::Num2Word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Number to word conversion in Luxembourgish | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # {{{ variable declarations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my Readonly::Scalar $COPY = 'Copyright (c) PetaMem, s.r.o. 2002-present'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | our $VERSION = '0.2603270'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # {{{ num2ltz_cardinal convert number to text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub num2ltz_cardinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 49 | ▶ | my $positive = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2ltz_cardinal: called CC=31 SCAR=34.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 49 | ▶ | croak 'You should specify a number from interval [0, 999_999_999]' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0
defined $positive && $positive =~ /\A\d+\z/msux
MC/DC50%2/4
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
defined $positive
$positive =~ /\A\d+\z/msux
$positive < 0
$positive > 999999999
Truth table60%3/5
not(A && B) or C or D
A= defined $positiveB= $positive =~ /\A\d+\z/msuxC= $positive < 0D= $positive > 999999999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | if !defined $positive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | || $positive !~ m{\A\d+\z}xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | || $positive < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | || $positive > 999_999_999; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # 0..12 are irregular standalone forms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 47 | my @tokens1 = qw(null een zwee dräi véier fënnef sechs siwen aacht néng zéng eelef zwielef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # tens 20..90 (index 0=20, 1=30, ...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 47 | my @tokens2 = qw(zwanzeg drësseg véierzeg fofzeg sechzeg siwwenzeg achtzeg nonzeg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # standalone 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 47 | ▶ | return 'null' if $positive == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # standalone 1 has trailing 't' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 46 | ▶ | return 'eent' if $positive == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 45 | ▶ | return $tokens1[$positive] if ($positive >= 2 && $positive < 13); # 2 .. 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 2 and $positive < 13
MC/DC50%1/2
$positive >= 2 and $positive < 13
$positive >= 2
$positive < 13
Truth table66%2/3
A and B
A= $positive >= 2B= $positive < 13
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 35 | ▶ | return 'fofzéng' if ($positive == 15); # 15 exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 34 | ▶ | return 'siechzéng' if ($positive == 16); # 16 exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 33 | ▶ | return 'siwwenzéng' if ($positive == 17); # 17 exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 32 | ▶ | return 'uechtzéng' if ($positive == 18); # 18 exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 31 | ▶ | return 'nonzéng' if ($positive == 19); # 19 exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 29 | ▶ | return $tokens1[$positive-10] . 'zéng' if ($positive > 12 && $positive < 20); # 13, 14 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive > 12 and $positive < 20
MC/DC50%1/2
$positive > 12 and $positive < 20
$positive > 12
$positive < 20
Truth table66%2/3
A and B
A= $positive > 12B= $positive < 20
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 28 | my $out; # string for return value construction | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | my $one_idx; # index for array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 28 | my $remain; # remainder | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 28 | ▶ | if ($positive > 19 && $positive < 100) { # 20 .. 99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$positive > 19 and $positive < 100
MC/DC50%1/2
$positive > 19 and $positive < 100
$positive > 19
$positive < 100
Truth table66%2/3
A and B
A= $positive > 19B= $positive < 100
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 15 | $one_idx = int ($positive / 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 15 | $remain = $positive % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 15 | ▶ | if ($remain) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 14 | my $unit = $tokens1[$remain]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 14 | my $tens = $tokens2[$one_idx - 2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 14 | my $connector = _connector($tens); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 14 | $out = $unit . $connector . $tens; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | $out = $tokens2[$one_idx - 2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ▶ | elsif ($positive >= 100 && $positive < 1000) { # 100 .. 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$positive >= 100 and $positive < 1000
MC/DC50%1/2
$positive >= 100 and $positive < 1000
$positive >= 100
$positive < 1000
Truth table66%2/3
A and B
A= $positive >= 100B= $positive < 1000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | $one_idx = int ($positive / 100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 7 | $remain = $positive % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 7 | ▶ | $out = ($one_idx == 1 ? '' : $tokens1[$one_idx]) . 'honnert'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 7 | ▶ | $out .= $remain ? num2ltz_cardinal($remain) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ▶ | elsif ($positive > 999 && $positive < 1_000_000) { # 1000 .. 999_999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$positive > 999 and $positive < 1000000
MC/DC50%1/2
$positive > 999 and $positive < 1000000
$positive > 999
$positive < 1000000
Truth table66%2/3
A and B
A= $positive > 999B= $positive < 1000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | $one_idx = int ($positive / 1000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | $remain = $positive % 1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | ▶ | $out = ($one_idx == 1 ? '' : num2ltz_cardinal($one_idx)) . 'dausend'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | ▶ | $out .= $remain ? num2ltz_cardinal($remain) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ▶ | elsif ( $positive > 999_999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$positive > 999999 and $positive < 1000000000
MC/DC0%0/2
$positive > 999999 and $positive < 1000000000
$positive > 999999
$positive < 1000000000
Truth table33%1/3
A and B
A= $positive > 999999B= $positive < 1000000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | && $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | $one_idx = int ($positive / 1000000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | $remain = $positive % 1000000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # "eng Millioun" for 1M, "zwee Milliounen" for 2M+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | ▶ | if ($one_idx == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | $out = 'eng Millioun'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $out = num2ltz_cardinal($one_idx) . ' Milliounen'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | $out .= $remain ? ' ' . num2ltz_cardinal($remain) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 28 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # {{{ _connector apply n-rule (Eifel rule) for 'an' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | sub _connector { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 14 | ▶ | my $tens = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connector: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # The Eifel rule (n-Regel): final 'n' is dropped before a consonant, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # EXCEPT before n, d, t, z, h. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # Applied to the connector 'an' before the tens word. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 14 | my $first_char = substr($tens, 0, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Before a vowel: keep 'n' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 14 | ▶ | return 'an' if $first_char =~ m/[aeiouäëéAEIOU]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Before consonants n, d, t, z, h: keep 'n' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 13 | ▶ | return 'an' if $first_char =~ m/[ndtzh]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # Before all other consonants: drop 'n' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 5 | return 'a'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # {{{ capabilities declare supported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | sub capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | cardinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capabilities: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ordinal => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||