line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::IQ::EN; |
2
|
1
|
|
|
1
|
|
661
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
8
|
use base 'Text::IQ'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
356
|
|
5
|
|
|
|
|
|
|
use Lingua::EN::Syllable; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.006'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my %syllable_cache; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Text::IQ::EN - Text::IQ for English |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# see Text::IQ |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 METHODS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This class extends L. Only new or overridden methods are documented here. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 get_num_syllables |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Returns number of syllables in the text. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get_num_syllables { |
32
|
|
|
|
|
|
|
return $syllable_cache{ $_[1] } if exists $syllable_cache{ $_[1] }; |
33
|
|
|
|
|
|
|
$syllable_cache{ $_[1] } = syllable( $_[1] ); |
34
|
|
|
|
|
|
|
return $syllable_cache{ $_[1] }; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 num_misspellings |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Returns the number of misspelled words, according to L. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub num_misspellings { |
44
|
|
|
|
|
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
return $self->{num_misspelled} if defined $self->{num_misspelled}; |
46
|
|
|
|
|
|
|
my $checker = Search::Tools::SpellCheck->new( lang => 'en_US', ); |
47
|
|
|
|
|
|
|
my $aspell = $checker->aspell; |
48
|
|
|
|
|
|
|
my @errs; |
49
|
|
|
|
|
|
|
my %uniq; |
50
|
|
|
|
|
|
|
my $n = 0; |
51
|
|
|
|
|
|
|
while ( my $t = $self->{_tokens}->next ) { |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if ( $t->is_match ) { |
54
|
|
|
|
|
|
|
if ( !$aspell->check("$t") ) { |
55
|
|
|
|
|
|
|
push @errs, "$t"; |
56
|
|
|
|
|
|
|
$uniq{"$t"}++; |
57
|
|
|
|
|
|
|
$n++; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
$self->{misspelled} = \@errs; |
62
|
|
|
|
|
|
|
$self->{num_uniq_misspelled} = scalar keys %uniq; |
63
|
|
|
|
|
|
|
$self->{num_misspelled} = $n; |
64
|
|
|
|
|
|
|
$self->{_tokens}->reset; |
65
|
|
|
|
|
|
|
return $self->{num_misspelled}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 num_uniq_misspellings |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Returns the number of unique misspelled words. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub num_uniq_misspellings { |
75
|
|
|
|
|
|
|
my $self = shift; |
76
|
|
|
|
|
|
|
$self->num_misspellings; |
77
|
|
|
|
|
|
|
return $self->{num_uniq_misspelled}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 misspelled |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Returns the list of misspelled words. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub misspelled { |
87
|
|
|
|
|
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
return $self->{misspelled} if defined $self->{misspelled}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |