line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Number::ID; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
474
|
use 5.010001; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
222
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(parse_number_id $Pat); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.07'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %SPEC; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#our $Pat = qr/(?: |
16
|
|
|
|
|
|
|
# [+-]? |
17
|
|
|
|
|
|
|
# (?: |
18
|
|
|
|
|
|
|
# \d{1,2}(?:[.]\d{3})*(?:[,]\d*)? | # indo |
19
|
|
|
|
|
|
|
# \d{1,2}(?:[,]\d{3})*(?:[.]\d*)? | # english |
20
|
|
|
|
|
|
|
# [,.]\d+ | |
21
|
|
|
|
|
|
|
# \d+ |
22
|
|
|
|
|
|
|
# ) |
23
|
|
|
|
|
|
|
# (?:[Ee][+-]?\d+)? |
24
|
|
|
|
|
|
|
# )/x; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# non /x version |
27
|
|
|
|
|
|
|
our $Pat = '(?:[+-]?(?:\d{1,2}(?:[.]\d{3})*(?:[,]\d*)?|\d{1,2}(?:[,]\d{3})*(?:[.]\d*)?|[,.]\d+|\d+)(?:[Ee][+-]?\d+)?)'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _clean_nd { |
30
|
7
|
|
|
7
|
|
10
|
my $n = shift; |
31
|
7
|
|
|
|
|
18
|
$n =~ s/\D//; |
32
|
7
|
|
|
|
|
54
|
$n; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _parse_mantissa { |
36
|
25
|
|
|
25
|
|
48
|
my $n = shift; |
37
|
25
|
100
|
|
|
|
94
|
if ($n =~ /^([+-]?)([\d,.]*)\.(\d{0,2})$/) { |
38
|
7
|
100
|
100
|
|
|
33
|
return (_clean_nd($2 || 0) + "0.$3")* |
39
|
|
|
|
|
|
|
($1 eq '-' ? -1 : 1); |
40
|
|
|
|
|
|
|
} else { |
41
|
18
|
|
|
|
|
22
|
$n =~ s/\.//g; |
42
|
18
|
|
|
|
|
25
|
$n =~ s/,/./g; |
43
|
1
|
|
|
1
|
|
4
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
238
|
|
44
|
18
|
|
|
|
|
54
|
return $n+0; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$SPEC{parse_number_id} = { |
49
|
|
|
|
|
|
|
v => 1.1, |
50
|
|
|
|
|
|
|
summary => 'Parse number from Indonesian text', |
51
|
|
|
|
|
|
|
args => { |
52
|
|
|
|
|
|
|
text => { |
53
|
|
|
|
|
|
|
summary => 'The input text that contains number', |
54
|
|
|
|
|
|
|
schema => 'str*', |
55
|
|
|
|
|
|
|
pos => 0, |
56
|
|
|
|
|
|
|
req => 1, |
57
|
|
|
|
|
|
|
}, |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
result_naked => 1, |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
sub parse_number_id { |
62
|
30
|
|
|
30
|
1
|
53978
|
my %args = @_; |
63
|
30
|
|
|
|
|
55
|
my $text = $args{text}; |
64
|
|
|
|
|
|
|
|
65
|
30
|
|
|
|
|
89
|
$text =~ s/^\s+//s; |
66
|
30
|
100
|
|
|
|
82
|
return undef unless length($text); |
67
|
|
|
|
|
|
|
|
68
|
29
|
100
|
|
|
|
113
|
$text =~ s/^([+-]?[0-9,.]+)// or return undef; |
69
|
25
|
|
|
|
|
48
|
my $n = _parse_mantissa($1); |
70
|
25
|
50
|
|
|
|
54
|
return undef unless defined $n; |
71
|
25
|
100
|
|
|
|
60
|
if ($text =~ /[Ee]([+-]?\d+)/) { |
72
|
7
|
|
|
|
|
31
|
$n *= 10**$1; |
73
|
|
|
|
|
|
|
} |
74
|
25
|
|
|
|
|
59
|
$n; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
# ABSTRACT: Parse number from Indonesian text |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |