blib/lib/Lingua/DEU/Word2Num.pm

filter: Statementstmt 100% 26 / 26 Branchbran n/a Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 100% 40 / 40 CC 2 SCAR 1.8
CC
2
Cov
100%
w2n
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 # For Emacs: -*- mode:cperl; mode:folding; coding:utf-8 -*-
2  
3 package Lingua::DEU::Word2Num;
4 # ABSTRACT: Word 2 Number conversion in DEU.
5  
6 # {{{ use block
7  
8 1 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Encode qw(decode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Parse::RecDescent;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Perl6::Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # }}}
18 # {{{ variables
19  
20 1 our $VERSION = 0.1106;
21 1 my $parser = deu_numerals();
22  
23 # }}}
24 # {{{ w2n convert number to text
25  
26 sub w2n :Export {
27 4 ▶ my $input = shift // return;
Subroutine w2n: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
shift() // (return)
l!l
31
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
28  
29 3 return $parser->numeral($input);
30 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 # }}}
33 # {{{ deu_numerals create parser for german numerals
34  
35 sub deu_numerals {
36 1 ▶ return Parse::RecDescent->new(decode_utf8(q{
Subroutine deu_numerals: called CC=1 SCAR=0.0
Pod documented
37 numeral: <rulevar: local $number = 0>
38 numeral: scrap
39 { return undef; }
40 | millenium
41 { return $item[1]; }
42 | century
43 { return $item[1]; }
44 | decade
45 { return $item[1]; }
46  
47 number: 'dreizehn' { $return = 13; }
48 | 'vierzehn' { $return = 14; }
49 | 'fünfzehn' { $return = 15; }
50 | 'sechzehn' { $return = 16; }
51 | 'siebzehn' { $return = 17; }
52 | 'achtzehn' { $return = 18; }
53 | 'neunzehn' { $return = 19; }
54 | 'null' { $return = 0; }
55 | 'ein' { $return = 1; }
56 | 'zwei' { $return = 2; }
57 | 'drei' { $return = 3; }
58 | 'vier' { $return = 4; }
59 | 'fünf' { $return = 5; }
60 | 'sechs' { $return = 6; }
61 | 'sieben' { $return = 7; }
62 | 'acht' { $return = 8; }
63 | 'neun' { $return = 9; }
64 | 'zehn' { $return = 10; }
65 | 'elf' { $return = 11; }
66 | 'zwölf' { $return = 12; }
67  
68 tens: 'zwanzig' { $return = 20; }
69 | 'dreissig' { $return = 30; }
70 | 'vierzig' { $return = 40; }
71 | 'fünfzig' { $return = 50; }
72 | 'sechzig' { $return = 60; }
73 | 'siebzig' { $return = 70; }
74 | 'achtzig' { $return = 80; }
75 | 'neunzig' { $return = 90; }
76  
77 decade: 'und' decade
78 { $return = $item[2]; }
79 | number 'und' tens
80 { $return = $item[1] + $item[3]; }
81 | tens
82 { $return = $item[1]; }
83 | number
84 { $return = $item[1]; }
85  
86 century: number 'hundert' decade
87 { $return = $item[1] * 100 + $item[3]; }
88 | number 'hundert'
89 { $return = $item[1] * 100; }
90 | 'hundert'
91 { $return = 100; }
92  
93 millenium: century 'tausend' century
94 { $return = $item[1] * 1000 + $item[3]; }
95 | century 'tausend' decade
96 { $return = $item[1] * 1000 + $item[3]; }
97 | decade 'tausend' century
98 { $return = $item[1] * 1000 + $item[3]; }
99 | decade 'tausend' decade
100 { $return = $item[1] * 1000 + $item[3]; }
101 | decade 'tausend'
102 { $return = $item[1] * 1000; }
103 | century 'tausend'
104 { $return = $item[1] * 1000; }
105  
106 scrap: millenium(?) century(?) decade(?)
107 /(.+)/
108 millenium(?) century(?) decade(?)
109 {
110 carp("unknown numeral '$1' !\n");
111 }
112 }));
113 }
114  
115 # }}}
116  
117 1 1;
118  
119 __END__
↑ Summary