| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Lingua::EN::Inflect::Number; |
|
2
|
|
|
|
|
|
|
$Lingua::EN::Inflect::Number::VERSION = '1.11'; |
|
3
|
1
|
|
|
1
|
|
35074
|
use 5.006; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
42
|
|
|
4
|
1
|
|
|
1
|
|
9
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
37
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
178
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(to_PL to_S number); |
|
10
|
1
|
|
|
1
|
|
3185
|
use Lingua::EN::Inflect qw(PL PL_N_eq); |
|
|
1
|
|
|
|
|
37872
|
|
|
|
1
|
|
|
|
|
679
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
|
13
|
1
|
|
|
1
|
|
19
|
my ($self, @syms) = @_; |
|
14
|
|
|
|
|
|
|
# Grep out the ones we provide: |
|
15
|
1
|
|
|
|
|
7
|
my $provide = join "|", map quotemeta, @EXPORT_OK; |
|
16
|
1
|
|
|
|
|
3
|
my @new_syms; |
|
17
|
1
|
|
|
|
|
3
|
for my $sym (@syms) { |
|
18
|
4
|
100
|
|
|
|
167
|
if ($sym =~ /^\&?($provide)$/) { |
|
19
|
3
|
|
|
|
|
668
|
$self->export_to_level(1, $self, $sym); |
|
20
|
|
|
|
|
|
|
} else { |
|
21
|
1
|
|
|
|
|
5
|
push @new_syms, $sym; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
} |
|
24
|
1
|
50
|
|
|
|
6
|
return unless @new_syms; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Pretend we don't exist |
|
27
|
1
|
|
|
|
|
4
|
@_ = ("Lingua::EN::Inflect", @new_syms); |
|
28
|
1
|
|
|
|
|
2992
|
goto &Exporter::import; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub to_PL { |
|
32
|
8
|
|
|
8
|
1
|
2698
|
my $word = shift; |
|
33
|
8
|
|
|
|
|
20
|
my $num = number($word); |
|
34
|
8
|
100
|
100
|
|
|
77
|
return $word if $num eq "ambig" or $num eq "p"; |
|
35
|
3
|
|
|
|
|
11
|
return PL($word); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub to_S { |
|
39
|
8
|
|
|
8
|
1
|
3482
|
my $word = shift; |
|
40
|
8
|
|
|
|
|
20
|
my $num = number($word); |
|
41
|
8
|
100
|
100
|
|
|
64
|
return $word if $num eq "ambig" or $num eq "s"; |
|
42
|
3
|
|
|
|
|
10
|
return PL($word); # I don't know why this works, but it seems to. |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub number { |
|
46
|
19
|
|
|
19
|
1
|
944
|
my $word = shift; |
|
47
|
19
|
|
|
|
|
58
|
my $test = PL_N_eq($word, PL($word)); |
|
48
|
19
|
|
|
|
|
20387
|
$test =~ s/:.*//; |
|
49
|
19
|
100
|
|
|
|
66
|
$test = "ambig" if $test eq "eq"; |
|
50
|
19
|
|
|
|
|
99
|
return $test; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
|
54
|
|
|
|
|
|
|
__END__ |
|
55
|
|
|
|
|
|
|
# Below is stub documentation for your module. You better edit it! |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Lingua::EN::Inflect::Number - Force number of words to singular or plural |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
use Lingua::EN::Inflect::Number qw( |
|
64
|
|
|
|
|
|
|
number to_S to_PL # Or anything you want from Lingua::EN::Inflect |
|
65
|
|
|
|
|
|
|
); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
print number("goat"); # "s" - there's only one goat |
|
68
|
|
|
|
|
|
|
print number("goats"); # "p" - there's several goats |
|
69
|
|
|
|
|
|
|
print number("sheep"); # "ambig" - there could be one or many sheep |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
print to_S("goats"); # "goat" |
|
72
|
|
|
|
|
|
|
print to_PL("goats"); # "goats" - it already is |
|
73
|
|
|
|
|
|
|
print to_S("goat"); # "goat" - it already is |
|
74
|
|
|
|
|
|
|
print to_S("sheep"); # "sheep" |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This module extends the functionality of Lingua::EN::Inflect with three |
|
79
|
|
|
|
|
|
|
new functions available for export: |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 number |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This takes a word, and determines its number. It returns C<s> for singular, |
|
84
|
|
|
|
|
|
|
C<p> for plural, and C<ambig> for words that can be either singular or plural. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Based on that: |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 to_S / to_PL |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
These take a word and convert it forcefully either to singular or to |
|
91
|
|
|
|
|
|
|
plural. C<Lingua::EN::Inflect> does funny things if you try to pluralise |
|
92
|
|
|
|
|
|
|
an already-plural word, but this module does the right thing. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 DISCLAIMER |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The whole concept is based on several undocumented features and |
|
97
|
|
|
|
|
|
|
idiosyncracies in the way Lingua::EN::Inflect works. Because of this, |
|
98
|
|
|
|
|
|
|
the module only works reliably on nouns. It's also possible that these |
|
99
|
|
|
|
|
|
|
idiosyncracies will be fixed at some point in the future and this module |
|
100
|
|
|
|
|
|
|
will need to be rethought. But it works at the moment. Additionally, |
|
101
|
|
|
|
|
|
|
any disclaimers on Lingua::EN::Inflect apply double here. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L<Lingua::EN::Inflect> |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 REPOSITORY |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L<https://github.com/neilbowers/Lingua-EN-Inflect-Number> |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 AUTHOR |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Simon Cozens, C<simon@cpan.org> |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This software is copyright (c) 2004 by Simon Cozens C<simon@cpan.org> |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
120
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |