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