blib/lib/Lingua/KOR/Word2Num.pm

filter: Statementstmt 100% 25 / 25 Branchbran 50.0% 1 / 2 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 85.4% 41 / 48 CC 5 SCAR 10.9
CC
5
Cov
88%
w2n
5.7
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*-
2  
3 package Lingua::KOR::Word2Num;
4 # ABSTRACT: Word to number conversion in Korean
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 Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Parse::RecDescent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # }}}
16 # {{{ variable declarations
17 1 our $VERSION = '0.2603270';
18 1 my $parser = kor_numerals();
19  
20 # }}}
21  
22 # {{{ w2n convert text to number
23  
24 sub w2n :Export {
25 2 ▶ my $input = shift // return;
Subroutine w2n: called CC=5 SCAR=17.5
Pod documented
Condition100%2/2
shift() // (return)
l!l
11
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
26  
27 # zero
28 1 ▶ return 0 if ($input =~ m{\b(yeong)\b}xmsi || $input =~ m{\A영\z}xms);
Branch: 1 branch
BranchTrueFalseTotal
if $input =~ /\b(yeong)\b/imsux or $input =~ /\A\x{c601}\z/msux 0 1 1
Condition33%1/3
$input =~ /\b(yeong)\b/imsux or $input =~ /\A\x{c601}\z/msux
l!l&&r!l&&!r
001
MC/DC0%0/2
$input =~ /\b(yeong)\b/imsux or $input =~ /\A\x{c601}\z/msux
$input =~ /\b(yeong)\b/imsux $input =~ /\A\x{c601}\z/msux
Truth table33%1/3
A or B
A= $input =~ /\b(yeong)\b/imsuxB= $input =~ /\A\x{c601}\z/msux
ABresult
1X1
011
000
29  
30 1 $input .= " "; # Grant space at the end
31  
32 1 ▶ return $parser->numeral($input) || undef;
Condition50%1/2
$parser->numeral($input) || undef
l!l
10
MC/DC0%0/1
$parser->numeral($input) || undef
$parser->numeral($input)
Truth table50%1/2
A
A= $parser->numeral($input)
Aresult
11
00
33 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # }}}
36 # {{{ kor_numerals create parser for numerals
37  
38 sub kor_numerals {
39 1 ▶ return Parse::RecDescent->new(q{
Subroutine kor_numerals: called CC=1 SCAR=0.0
Pod documented
40 numeral: <rulevar: local $number = 0>
41 numeral: eok { return $item[1]; } # root parse. go from maximum to minimum value
42 | man { return $item[1]; }
43 | millenium2 { return $item[1]; }
44 | millenium1 { return $item[1]; }
45 | century { return $item[1]; }
46 | decade { return $item[1]; }
47 | { return undef; }
48  
49 number: 'yeong ' { $return = 0; } # try to find a word from 0 to 9
50 | 'il ' { $return = 1; }
51 | 'sam ' { $return = 3; }
52 | 'sa ' { $return = 4; }
53 | 'o ' { $return = 5; }
54 | 'yuk ' { $return = 6; }
55 | 'chil ' { $return = 7; }
56 | 'pal ' { $return = 8; }
57 | 'gu ' { $return = 9; }
58 | 'i ' { $return = 2; }
59 | /영/ { $return = 0; }
60 | /일/ { $return = 1; }
61 | /이/ { $return = 2; }
62 | /삼/ { $return = 3; }
63 | /사/ { $return = 4; }
64 | /오/ { $return = 5; }
65 | /육/ { $return = 6; }
66 | /칠/ { $return = 7; }
67 | /팔/ { $return = 8; }
68 | /구/ { $return = 9; }
69  
70 tens: 'ilsip ' { $return = 10; } # try to find a word that represents
71 | 'isip ' { $return = 20; } # values 10,20,..,90
72 | 'samsip ' { $return = 30; }
73 | 'sasip ' { $return = 40; }
74 | 'osip ' { $return = 50; }
75 | 'yuksip ' { $return = 60; }
76 | 'chilsip ' { $return = 70; }
77 | 'palsip ' { $return = 80; }
78 | 'gusip ' { $return = 90; }
79 | 'sip ' { $return = 10; }
80 | /일십/ { $return = 10; }
81 | /이십/ { $return = 20; }
82 | /삼십/ { $return = 30; }
83 | /사십/ { $return = 40; }
84 | /오십/ { $return = 50; }
85 | /육십/ { $return = 60; }
86 | /칠십/ { $return = 70; }
87 | /팔십/ { $return = 80; }
88 | /구십/ { $return = 90; }
89 | /십/ { $return = 10; }
90  
91 hundreds: 'ilbaek ' { $return = 100; } # try to find a word that represents
92 | 'ibaek ' { $return = 200; } # values 100,200,..,900
93 | 'sambaek ' { $return = 300; }
94 | 'sabaek ' { $return = 400; }
95 | 'obaek ' { $return = 500; }
96 | 'yukbaek ' { $return = 600; }
97 | 'chilbaek ' { $return = 700; }
98 | 'palbaek ' { $return = 800; }
99 | 'gubaek ' { $return = 900; }
100 | 'baek ' { $return = 100; }
101 | /일백/ { $return = 100; }
102 | /이백/ { $return = 200; }
103 | /삼백/ { $return = 300; }
104 | /사백/ { $return = 400; }
105 | /오백/ { $return = 500; }
106 | /육백/ { $return = 600; }
107 | /칠백/ { $return = 700; }
108 | /팔백/ { $return = 800; }
109 | /구백/ { $return = 900; }
110 | /백/ { $return = 100; }
111  
112 thousands: 'ilcheon ' { $return = 1000; } # try to find a word that represents
113 | 'icheon ' { $return = 2000; } # values 1000,2000,..,9000
114 | 'samcheon ' { $return = 3000; }
115 | 'sacheon ' { $return = 4000; }
116 | 'ocheon ' { $return = 5000; }
117 | 'yukcheon ' { $return = 6000; }
118 | 'chilcheon ' { $return = 7000; }
119 | 'palcheon ' { $return = 8000; }
120 | 'gucheon ' { $return = 9000; }
121 | 'cheon ' { $return = 1000; }
122 | /일천/ { $return = 1000; }
123 | /이천/ { $return = 2000; }
124 | /삼천/ { $return = 3000; }
125 | /사천/ { $return = 4000; }
126 | /오천/ { $return = 5000; }
127 | /육천/ { $return = 6000; }
128 | /칠천/ { $return = 7000; }
129 | /팔천/ { $return = 8000; }
130 | /구천/ { $return = 9000; }
131 | /천/ { $return = 1000; }
132  
133 tenthousands: 'ilman ' { $return = 10000; } # try to find a word that represents
134 | 'iman ' { $return = 20000; } # values 10000,20000,..,90000
135 | 'samman ' { $return = 30000; }
136 | 'saman ' { $return = 40000; }
137 | 'oman ' { $return = 50000; }
138 | 'yukman ' { $return = 60000; }
139 | 'chilman ' { $return = 70000; }
140 | 'palman ' { $return = 80000; }
141 | 'guman ' { $return = 90000; }
142 | 'man ' { $return = 10000; }
143 | /일만/ { $return = 10000; }
144 | /이만/ { $return = 20000; }
145 | /삼만/ { $return = 30000; }
146 | /사만/ { $return = 40000; }
147 | /오만/ { $return = 50000; }
148 | /육만/ { $return = 60000; }
149 | /칠만/ { $return = 70000; }
150 | /팔만/ { $return = 80000; }
151 | /구만/ { $return = 90000; }
152 | /만/ { $return = 10000; }
153  
154 decade: tens(?) number(?) number(?) # try to find words that represents values
155 { $return = 0; # from 0 to 99
156 for (@item) {
157 $return += $$_[0] if (ref $_ && defined $$_[0]);
158 }
159 }
160  
161 century: hundreds(?) decade(?) # try to find words that represents values
162 { $return = 0; # from 100 to 999
163 for (@item) {
164 $return += $$_[0] if (ref $_ && defined $$_[0]);
165 }
166 }
167  
168 millenium1: thousands(1) century(?) # try to find words that represents values
169 { $return = 0; # from 1.000 to 9.999
170 for (@item) {
171 if (ref $_ && defined $$_[0]) {
172 $return += $$_[0] if (ref $_ && defined $$_[0]);
173 }
174 }
175 }
176  
177 millenium2: tenthousands(1) thousands(?) century(?) decade(?) # try to find words that represents values
178 { $return = 0; # from 10.000 to 99.999
179 for (@item) {
180 if (ref $_ && defined $$_[0]) {
181 $return += $$_[0] if (ref $_ && defined $$_[0]);
182 }
183 }
184 }
185  
186 man: millenium1(?) century(?) decade(?) # N만K = N * 10_000 + K where N is 1..9999
187 manmark # handles values from 10_000 to 99_999_999
188 millenium1(?) century(?) decade(?)
189 { $return = 0;
190 for (@item) {
191 if (ref $_ && defined $$_[0]) {
192 $return += $$_[0];
193 } elsif (defined $_ && $_ eq "Man") {
194 $return = ($return>0) ? $return * 10000 : 10000;
195 }
196 }
197 }
198  
199 manmark: 'man ' { $return = "Man"; }
200 | /만/ { $return = "Man"; }
201  
202 eok: millenium1(?) century(?) decade(?) # try to find words that represents values
203 eokmark # from 100.000.000 to 999.999.999.999
204 man(?) millenium1(?) century(?) decade(?)
205 { $return = 0;
206 for (@item) {
207 if (ref $_ && defined $$_[0]) {
208 $return += $$_[0];
209 } elsif (defined $_ && $_ eq "Eok") {
210 $return = ($return>0) ? $return * 100000000 : 100000000;
211 }
212 }
213 }
214  
215 eokmark: 'eok ' { $return = "Eok"; }
216 | /억/ { $return = "Eok"; }
217 });
218 }
219  
220 # }}}
221  
222 1 1;
223  
224 __END__
↑ Summary