| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Lingua::DEU::Num2Word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Number to word conversion in German | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | # {{{ num2deu_cardinal convert number to text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub num2deu_cardinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | my $positive = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2deu_cardinal: called CC=25 SCAR=40.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 7 | ▶ | 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 | 5 | my @tokens1 = qw(null ein zwei drei vier fünf sechs sieben acht neun zehn elf zwölf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | my @tokens2 = qw(zwanzig dreissig vierzig fünfzig sechzig siebzig achtzig neunzig hundert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | return $tokens1[$positive] if ($positive >= 0 && $positive < 13); # 0 .. 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 0 and $positive < 13
MC/DC50%1/2
$positive >= 0 and $positive < 13
$positive >= 0
$positive < 13
Truth table66%2/3
A and B
A= $positive >= 0B= $positive < 13
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | ▶ | return 'sechzehn' if ($positive == 16); # 16 exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | return 'siebzehn' if ($positive == 17); # 17 exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | return $tokens1[$positive-10] . 'zehn' if ($positive > 12 && $positive < 20); # 13 .. 19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$positive > 12 and $positive < 20
MC/DC0%0/2
$positive > 12 and $positive < 20
$positive > 12
$positive < 20
Truth table33%1/3
A and B
A= $positive > 12B= $positive < 20
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | my $out; # string for return value construction | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | my $one_idx; # index for tokens1 array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | my $remain; # remainder | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | if ($positive > 19 && $positive < 101) { # 20 .. 100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$positive > 19 and $positive < 101
MC/DC50%1/2
$positive > 19 and $positive < 101
$positive > 19
$positive < 101
Truth table66%2/3
A and B
A= $positive > 19B= $positive < 101
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | $one_idx = int ($positive / 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | $remain = $positive % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | $out = "$tokens1[$remain]und" if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | $out .= $tokens2[$one_idx - 2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ▶ | elsif ($positive > 100 && $positive < 1000) { # 101 .. 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | $one_idx = int ($positive / 100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | $remain = $positive % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | $out = "$tokens1[$one_idx]hundert"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | $out .= $remain ? num2deu_cardinal($remain) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ▶ | elsif ($positive > 999 && $positive < 1_000_000) { # 1000 .. 999_999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$positive > 999 and $positive < 1000000
MC/DC0%0/2
$positive > 999 and $positive < 1000000
$positive > 999
$positive < 1000000
Truth table33%1/3
A and B
A= $positive > 999B= $positive < 1000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | $one_idx = int ($positive / 1000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | $remain = $positive % 1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | $out = num2deu_cardinal($one_idx).'tausend'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | $out .= $remain ? num2deu_cardinal($remain) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ▶ | elsif ( $positive > 999_999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$positive > 999999 and $positive < 1000000000
MC/DC0%0/2
$positive > 999999 and $positive < 1000000000
$positive > 999999
$positive < 1000000000
Truth table0%0/3
A and B
A= $positive > 999999B= $positive < 1000000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | && $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $one_idx = int ($positive / 1000000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $remain = $positive % 1000000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $one = $one_idx == 1 ? 'e' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $out = num2deu_cardinal($one_idx) . "$one million"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $out .= 'en' if ($one_idx > 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $out .= $remain ? ' ' . num2deu_cardinal($remain) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # {{{ num2deu_ordinal convert number to ordinal text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | sub num2deu_ordinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $number = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2deu_ordinal: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | croak 'You should specify a number from interval [1, 999_999_999]' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
not defined $number && $number =~ /\A\d+\z/msux or $number < 1 or $number > 999999999
not defined $number && $number =~ /\A\d+\z/msux or $number < 1
defined $number && $number =~ /\A\d+\z/msux
MC/DC0%0/4
not defined $number && $number =~ /\A\d+\z/msux or $number < 1 or $number > 999999999
defined $number
$number =~ /\A\d+\z/msux
$number < 1
$number > 999999999
Truth table0%0/5
not(A && B) or C or D
A= defined $numberB= $number =~ /\A\d+\z/msuxC= $number < 1D= $number > 999999999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | if !defined $number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | || $number !~ m{\A\d+\z}xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | || $number < 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | || $number > 999_999_999; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # Fully irregular forms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | return 'erste' if $number == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return 'zweite' if $number == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | return 'dritte' if $number == 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # Stem irregulars: siebte (not siebente), achte (not achtte) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return 'siebte' if $number == 7; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return 'achte' if $number == 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $cardinal = num2deu_cardinal($number); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # Numbers 4-19 get suffix "te", 20+ get "ste" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my $suffix = $number < 20 ? 'te' : 'ste'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return $cardinal . $suffix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # {{{ capabilities declare supported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | sub capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | cardinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capabilities: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ordinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||