line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::EN::FindNumber; |
2
|
|
|
|
|
|
|
$Lingua::EN::FindNumber::VERSION = '1.30'; |
3
|
1
|
|
|
1
|
|
942
|
use 5.006; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
16
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use base 'Exporter'; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
181
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw( extract_numbers $number_re numify ); |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
866
|
use Lingua::EN::Words2Nums; |
|
1
|
|
|
|
|
3647
|
|
|
1
|
|
|
|
|
1356
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# This is from Lingua::EN::Words2Nums, after being thrown through |
13
|
|
|
|
|
|
|
# Regex::PreSuf |
14
|
|
|
|
|
|
|
my $numbers = |
15
|
|
|
|
|
|
|
qr/((?:b(?:akers?dozen|illi(?:ard|on))|centillion|d(?:ecilli(?:ard|on)|ozen|u(?:o(?:decilli(?:ard|on)|vigintillion)|vigintillion))|e(?:ight(?:een|ieth|[yh])?|leven(?:ty(?:first|one))?|s)|f(?:i(?:ft(?:een|ieth|[yh])|rst|ve)|o(?:rt(?:ieth|y)|ur(?:t(?:ieth|[yh]))?))|g(?:oogol(?:plex)?|ross)|hundred|mi(?:l(?:ion|li(?:ard|on))|nus)|n(?:aught|egative|in(?:et(?:ieth|y)|t(?:een|[yh])|e)|o(?:nilli(?:ard|on)|ught|vem(?:dec|vigint)illion))|o(?:ct(?:illi(?:ard|on)|o(?:dec|vigint)illion)|ne)|qu(?:a(?:drilli(?:ard|on)|ttuor(?:decilli(?:ard|on)|vigintillion))|in(?:decilli(?:ard|on)|tilli(?:ard|on)|vigintillion))|s(?:core|e(?:cond|pt(?:en(?:dec|vigint)illion|illi(?:ard|on))|ven(?:t(?:ieth|y))?|x(?:decillion|tilli(?:ard|on)|vigintillion))|ix(?:t(?:ieth|y))?)|t(?:ee?n|h(?:ir(?:t(?:een|ieth|y)|d)|ousand|ree)|r(?:e(?:decilli(?:ard|on)|vigintillion)|i(?:gintillion|lli(?:ard|on)))|w(?:e(?:l(?:fth|ve)|nt(?:ieth|y))|o)|h)|un(?:decilli(?:ard|on)|vigintillion)|vigintillion|zero|s))/i; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $ok_words = qr/\b(and|a|of)\b/; |
18
|
|
|
|
|
|
|
my $ok_things = qr/[^A-Za-z0-9.]/; |
19
|
|
|
|
|
|
|
our $number_re = qr/\b(($numbers($ok_words|$ok_things)*)+)\b/i; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub extract_numbers { |
22
|
1
|
|
|
1
|
1
|
2
|
my $text = shift; |
23
|
1
|
|
|
|
|
3
|
my @numbers; |
24
|
1
|
|
|
|
|
38
|
push @numbers, $1 while $text =~ /$number_re/g; |
25
|
1
|
|
|
|
|
12
|
s/\s+$// for @numbers; |
26
|
1
|
|
|
|
|
610
|
return @numbers; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub numify { |
30
|
1
|
|
|
1
|
1
|
796
|
my $text = shift; |
31
|
1
|
50
|
|
|
|
28
|
$text =~ s/$number_re/words2nums($1). ($1 =~ m{(\s+)$} ? $1 :"")/eg; |
|
2
|
|
|
|
|
939
|
|
32
|
1
|
|
|
|
|
55
|
return $text; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
__END__ |