| 1 | package Lingua::EN::Inflect::Numberscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/; |
| 2 | $Lingua::EN::Inflect::Number::VERSIONscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/$VERSION. = '1.12'; |
| 3 | use 5.006scip-perl cpan Lingua-EN-Inflect-Number 1.12 `5.006`/; |
| 4 | use strictscip-perl cpan Lingua-EN-Inflect-Number 1.12 strict/; |
| 5 | use warningsscip-perl cpan Lingua-EN-Inflect-Number 1.12 warnings/; |
| 6 | |
| 7 | requirescip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/require(). Exporter; |
| 8 | our @ISAscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/`@ISA`. = qw(Exporter); |
| 9 | our @EXPORT_OKscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/`@EXPORT_OK`. = qw(to_PL to_S number); |
| 10 | use Lingua::EN::Inflectscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/ qw(PL PL_N_eq); |
| 11 | |
| 12 | sub importscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/import(). { |
| 13 | my ($self, @syms) = @_scip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/`@_`.; |
| 14 | # Grep out the ones we provide: |
| 15 | my $provide = joinscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/join(). "|", mapscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/map(). quotemetascip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/quotemeta()., @EXPORT_OKscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/`@EXPORT_OK`.; |
| 16 | my @new_syms; |
| 17 | for my $sym (@syms) { |
| 18 | if ($sym =~ /^\&?($provide)$/) { |
| 19 | $self->export_to_levelscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/export_to_level().(1, $self, $sym); |
| 20 | } else { |
| 21 | pushscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/push(). @new_syms, $sym; |
| 22 | } |
| 23 | } |
| 24 | return unless @new_syms; |
| 25 | |
| 26 | # Pretend we don't exist |
| 27 | @_scip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/`@_`. = ("Lingua::EN::Inflect", @new_syms); |
| 28 | goto &Exporter::importscip-perl cpan Lingua-EN-Inflect-Number 1.12 Exporter/import().; |
| 29 | } |
| 30 | |
| 31 | sub to_PLscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/to_PL(). { |
| 32 | my $word = shiftscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/shift().; |
| 33 | my $num = numberscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/number().($word); |
| 34 | return $word if $num eq "ambig" or $num eq "p"; |
| 35 | return PLscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/PL().($word); |
| 36 | } |
| 37 | |
| 38 | sub to_Sscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/to_S(). { |
| 39 | my $word = shiftscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/shift().; |
| 40 | my $num = numberscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/number().($word); |
| 41 | return $word if $num eq "ambig" or $num eq "s"; |
| 42 | return PLscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/PL().($word); # I don't know why this works, but it seems to. |
| 43 | } |
| 44 | |
| 45 | sub numberscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/number(). { |
| 46 | my $word = shiftscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/shift().; |
| 47 | my $test = PL_N_eqscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/PL_N_eq().($word, PLscip-perl cpan Lingua-EN-Inflect-Number 1.12 Lingua/EN/Inflect/Number/PL().($word)); |
| 48 | $test =~ s/:.*//; |
| 49 | $test = "ambig" if $test eq "eq"; |
| 50 | 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<[email protected]> |
| 114 | |
| 115 | =head1 COPYRIGHT AND LICENSE |
| 116 | |
| 117 | This software is copyright (c) 2004 by Simon Cozens C<[email protected]> |
| 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 |