This file is indexed.

/usr/share/perl5/Lingua/EN/Number/IsOrdinal.pm is in liblingua-en-number-isordinal-perl 0.05-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package Lingua::EN::Number::IsOrdinal;
our $AUTHORITY = 'cpan:RKITOVER';
$Lingua::EN::Number::IsOrdinal::VERSION = '0.05';
use strict;
use warnings;
use Exporter 'import';
use Lingua::EN::FindNumber 'extract_numbers';

=encoding UTF-8

=head1 NAME

Lingua::EN::Number::IsOrdinal - detect if English number is ordinal or cardinal

=head1 SYNOPSIS

    use Lingua::EN::Number::IsOrdinal 'is_ordinal';

    ok is_ordinal('first');

    ok !is_ordinal('one');

    ok is_ordinal('2nd');

    ok !is_ordinal('2');

=head1 DESCRIPTION

This module will tell you if a number, either in words or as digits, is a
cardinal or L<ordinal
number|http://www.ego4u.com/en/cram-up/vocabulary/numbers/ordinal>.

This is useful if you e.g. want to distinguish these types of numbers found with
L<Lingua::EN::FindNumber> and take different actions.

=cut

our @EXPORT_OK = qw/is_ordinal/;

my $ORDINAL_WORDS_NUMBER_RE = qr/(?:first|second|third|th)\s*$/;

my $NUMBER_RE  = qr/^\s*(?:[+-]?)(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee](?:[+-]?\d+))?/;

my $CARDINAL_NUMBER_RE = qr/$NUMBER_RE\s*$/;

my $ORDINAL_NUMBER_RE  = qr/$NUMBER_RE(?:st|nd|rd|th)\s*$/;

=head1 FUNCTIONS

=head2 is_ordinal

Takes a number as English words or digits (with or without ordinal suffix) and
returns C<1> for ordinal numbers and C<undef> for cardinal numbers.

Checks that the whole parameter is a number using L<Lingua::EN::FindNumber> or
a regex in the case of digits, and if it isn't will throw a C<not a number>
exception.

This function can be optionally imported.

=cut

sub is_ordinal { __PACKAGE__->_is_ordinal(@_) }

=head1 METHODS

=head2 _is_ordinal

Method version of L</is_ordinal>, this is where the function is actually
implemented. Can be overloaded in a subclass.

=cut

sub _is_ordinal {
    my ($self, $num) = @_;

    die "not a number" unless $self->_is_number($num);

    if ($num =~ $ORDINAL_NUMBER_RE) {
        return 1;
    }
    elsif ($num =~ $CARDINAL_NUMBER_RE) {
        return undef;
    }
    elsif ($num =~ $ORDINAL_WORDS_NUMBER_RE) {
        return 1;
    }

    return undef; # cardinal words-number
}

=head2 _is_number

Returns C<1> if the passed in string is a word-number as detected by
L<Lingua::EN::FindNumber> or is a cardinal or ordinal number made of digits and
(for ordinal numbers) a suffix. Otherwise returns C<undef>. Can be overloaded in
a subclass.

=cut

sub _is_number {
    my ($self, $text) = @_;
    s/^\s+//, s/\s+$// for $text;
    
    my @nums = extract_numbers $text;

    if ((@nums == 1 && $nums[0] eq $text)
        || $text =~ $ORDINAL_NUMBER_RE || $text =~ $CARDINAL_NUMBER_RE) {

        return 1;
    }

    return undef;
}

=head1 SEE ALSO

=over 4

=item * L<Lingua::EN::FindNumber>

=item * L<Lingua::EN::Words2Nums>

=item * L<Lingua::EN::Inflect::Phrase>

=back

=head1 AUTHOR

Rafael Kitover <rkitover@cpan.org>

=head1 LICENSE

Copyright 2013-2015 by Rafael Kitover

This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.

=cut

1;