| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Parse::Number::EN; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-06-14'; # DATE |
|
4
|
|
|
|
|
|
|
our $VERSION = '0.07'; # VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# TODO: make it OO and customize thousand sep & decimal point |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
415
|
use 5.010001; |
|
|
1
|
|
|
|
|
2
|
|
|
9
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
14
|
|
|
10
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
3
|
use Exporter qw(import); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
223
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw($Pat parse_number_en); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %SPEC; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#our $Pat = qr/(?: |
|
18
|
|
|
|
|
|
|
# [+-]? |
|
19
|
|
|
|
|
|
|
# (?: |
|
20
|
|
|
|
|
|
|
# (?:\d{1,3}(?:[,]\d{3})+ | \d+) (?:[.]\d*)? | # english |
|
21
|
|
|
|
|
|
|
# [.]\d+ |
|
22
|
|
|
|
|
|
|
# ) |
|
23
|
|
|
|
|
|
|
# (?:[Ee][+-]?\d+)? |
|
24
|
|
|
|
|
|
|
# )/x; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# non /x version |
|
27
|
|
|
|
|
|
|
our $Pat = '(?:[+-]?(?:(?:\d{1,3}(?:[,]\d{3})+|\d+)(?:[.]\d*)?|[.]\d+)(?:[Ee][+-]?\d+)?)'; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$SPEC{parse_number_en} = { |
|
30
|
|
|
|
|
|
|
v => 1.1, |
|
31
|
|
|
|
|
|
|
summary => 'Parse number from English text', |
|
32
|
|
|
|
|
|
|
description => <<'_', |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This function can parse number with thousand separators (e.g. 10,000). |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
In the future percentage (e.g. 10.2%) and fractions (e.g. 1/3, 2 1/2) might also |
|
37
|
|
|
|
|
|
|
be supported. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
_ |
|
40
|
|
|
|
|
|
|
args => { |
|
41
|
|
|
|
|
|
|
text => { |
|
42
|
|
|
|
|
|
|
summary => 'The input text that contains number', |
|
43
|
|
|
|
|
|
|
schema => 'str*', |
|
44
|
|
|
|
|
|
|
req => 1, |
|
45
|
|
|
|
|
|
|
pos => 0, |
|
46
|
|
|
|
|
|
|
}, |
|
47
|
|
|
|
|
|
|
}, |
|
48
|
|
|
|
|
|
|
result_naked => 1, |
|
49
|
|
|
|
|
|
|
}; |
|
50
|
|
|
|
|
|
|
sub parse_number_en { |
|
51
|
30
|
|
|
30
|
1
|
39962
|
my %args = @_; |
|
52
|
30
|
|
|
|
|
52
|
my $text = $args{text}; |
|
53
|
|
|
|
|
|
|
|
|
54
|
30
|
100
|
|
|
|
285
|
return undef unless $text =~ s/^\s*($Pat)//s; |
|
55
|
24
|
|
|
|
|
42
|
my $n = $1; |
|
56
|
24
|
|
|
|
|
31
|
$n =~ s/,//g; |
|
57
|
24
|
|
|
|
|
84
|
$n+0; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
|
61
|
|
|
|
|
|
|
# ABSTRACT: Parse number from English text |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |