| 1 | package Text::Info; | ||
| 2 | 6 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 6 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 6 | extends 'Text::Info::BASE'; | |
| 6 | |||
| 7 | 6 | ▶ | use Text::Info::Sentence; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 6 | ▶ | use Text::Info::Readability; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | =encoding utf-8 | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | Text::Info - Retrieve information about, and do analysis on, text. | ||
| 15 | |||
| 16 | =head1 VERSION | ||
| 17 | |||
| 18 | Version 0.01. | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | 6 | our $VERSION = '0.01'; | |
| 23 | |||
| 24 | =head1 SYNOPSIS | ||
| 25 | |||
| 26 | use Text::Info; | ||
| 27 | |||
| 28 | my $text = Text::Info->new( "Some text..." ); | ||
| 29 | |||
| 30 | say "The text is written in language '" . $text->language . "', and"; | ||
| 31 | say "has a readability score (FRES) of " . $text->readability->fres; | ||
| 32 | |||
| 33 | =head1 DESCRIPTION | ||
| 34 | |||
| 35 | L<Text::Info> is an extensible and easy to use solution for retrieving useful | ||
| 36 | information about texts based on the L<Germanic languages|https://en.wikipedia.org/wiki/Germanic_languages>. | ||
| 37 | |||
| 38 | For the time being it has a limited feature set, but the plan is to use this | ||
| 39 | as a basis for NLP-solutions. | ||
| 40 | |||
| 41 | The solution is under heavy development, and the API will definitely change. | ||
| 42 | Please respect these facts if you intend to use it. | ||
| 43 | |||
| 44 | Contributions and suggestions are welcome! | ||
| 45 | |||
| 46 | =head1 WARNING! | ||
| 47 | |||
| 48 | This solution is - and will be - heavily based on language-specific features. | ||
| 49 | This means that if you use this solution on languages that doesn't have the | ||
| 50 | required "support modules", you're on your own. For the time being this only | ||
| 51 | affects the L<Text::Info::Readability> functionality, but will in the future | ||
| 52 | also include stemming- and stop word-functionality (and probably many other | ||
| 53 | things). | ||
| 54 | |||
| 55 | What you can do to help on this, is to create the missing supported modules, | ||
| 56 | for example create a Lingua::__::Syllable module specific for your language. | ||
| 57 | |||
| 58 | =head1 METHODS | ||
| 59 | |||
| 60 | =over | ||
| 61 | |||
| 62 | =item new() | ||
| 63 | |||
| 64 | Returns a new L<Text::Info> object. Can take C<text> as a single argument, | ||
| 65 | optionally C<tld> (top level domain, for better language detection), and/or | ||
| 66 | optionally C<language> if you want to specify the text's language yourself. | ||
| 67 | |||
| 68 | my $text = Text::Info->new( 'Dette er en norsk tekst.' ); | ||
| 69 | |||
| 70 | # ...or... | ||
| 71 | |||
| 72 | my $text = Text::Info->new( | ||
| 73 | text => 'Dette er en norsk tekst.', | ||
| 74 | tld => 'no', | ||
| 75 | ); | ||
| 76 | |||
| 77 | # ...or... | ||
| 78 | |||
| 79 | my $text = Text::Info->new( | ||
| 80 | text => 'Dette er en norsk tekst.' | ||
| 81 | language => 'no', | ||
| 82 | ); | ||
| 83 | |||
| 84 | It really doesn't make sense to set both C<tld> and C<language>, as the | ||
| 85 | former is a helper for detecting the correct language of the text, while | ||
| 86 | the latter overrides whatever that detection algorithm returns. | ||
| 87 | |||
| 88 | =item readability() | ||
| 89 | |||
| 90 | Returns an instance of the text's L<Text::Info::Readability> class, which in turn | ||
| 91 | can be used to retrieve L<readability information|https://en.wikipedia.org/wiki/Readability_test> about the text in question. | ||
| 92 | |||
| 93 | =cut | ||
| 94 | |||
| 95 | 6 | has 'readability' => ( isa => 'Text::Info::Readability', is => 'ro', lazy_build => 1 ); | |
| 96 | |||
| 97 | 2 | ▶ | sub _build_readability { |
|
Subroutine
_build_readability: called CC=1 SCAR=0.0
| |||
| 98 | 2 | my $self = shift; | |
| 99 | |||
| 100 | 2 | return Text::Info::Readability->new( | |
| 101 | text => $self->text, | ||
| 102 | tld => $self->tld, | ||
| 103 | language => $self->language, | ||
| 104 | ); | ||
| 105 | } | ||
| 106 | |||
| 107 | =item sentences() | ||
| 108 | |||
| 109 | Returns an array reference of the text's sentences as C<Text::Info::Sentence> | ||
| 110 | objects. This method is derived from L<Text::Info::BASE>. | ||
| 111 | |||
| 112 | Keep in mind that this method tries to remove any separators, so the sentences | ||
| 113 | returned should NOT contain those. For example "This is a sentence!" will be | ||
| 114 | returned as "This is a sentence". | ||
| 115 | |||
| 116 | =item sentence_count() | ||
| 117 | |||
| 118 | Returns the number of sentences in the text. This method is derived from | ||
| 119 | L<Text::Info::BASE>. | ||
| 120 | |||
| 121 | =item avg_sentence_length() | ||
| 122 | |||
| 123 | Returns the average length of the sentences in the text. This method is derived | ||
| 124 | from L<Text::Info::BASE>. | ||
| 125 | |||
| 126 | =item words() | ||
| 127 | |||
| 128 | Returns an array reference containing the text's words. This method is derived | ||
| 129 | from L<Text::Info::BASE>. | ||
| 130 | |||
| 131 | =item word_count() | ||
| 132 | |||
| 133 | Returns the number of words in the text. This is a helper method and is derived | ||
| 134 | from L<Text::Info::BASE>. | ||
| 135 | |||
| 136 | =item avg_word_length() | ||
| 137 | |||
| 138 | Returns the average length of the words in the text. This is a helper method and | ||
| 139 | is derived from L<Text::Info::BASE>. | ||
| 140 | |||
| 141 | =item ngrams( $size ) | ||
| 142 | |||
| 143 | Returns an array reference containing the text's ngrams of size C<$size>. | ||
| 144 | Default size is 2 (i.e. bigrams). This method overrides L<Text::Info::BASE>'s | ||
| 145 | C<ngrams()> method, as it takes into accounts building ngrams based on the | ||
| 146 | text's sentences, not the text's complete list of words. | ||
| 147 | |||
| 148 | =cut | ||
| 149 | |||
| 150 | 5 | ▶ | override 'ngrams' => sub { |
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||
| 151 | 5 | my $self = shift; | |
| 152 | |||
| 153 | 5 | my @ngrams = (); | |
| 154 | |||
| 155 | 5 | foreach my $sentence ( @{$self->sentences} ) { | |
| 156 | 13 | foreach my $ngram ( @{$sentence->ngrams(@_)} ) { | |
| 157 | 56 | push( @ngrams, $ngram ); | |
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | 5 | return \@ngrams; | |
| 162 | 6 | }; | |
| 163 | |||
| 164 | =item unigrams() | ||
| 165 | |||
| 166 | Returns an array reference containing the text's unigrams, i.e. the same | ||
| 167 | as C<ngrams(1)>. This is a helper method and is derived from L<Text::Info::BASE>. | ||
| 168 | |||
| 169 | =item bigrams() | ||
| 170 | |||
| 171 | Returns an array reference containing the text's bigrams, i.e. the same | ||
| 172 | as C<ngrams(2)>. This is a helper method and is derived from L<Text::Info::BASE>. | ||
| 173 | |||
| 174 | =item trigrams() | ||
| 175 | |||
| 176 | Returns an array reference containing the text's trigrams, i.e. the same | ||
| 177 | as C<ngrams(3)>. This is a helper method and is derived from L<Text::Info::BASE>. | ||
| 178 | |||
| 179 | =item quadgrams() | ||
| 180 | |||
| 181 | Returns an array reference containing the text's quadgrams, i.e. the same | ||
| 182 | as C<ngrams(4)>. This is a helper method and is derived from L<Text::Info::BASE>. | ||
| 183 | |||
| 184 | =item syllable_count() | ||
| 185 | |||
| 186 | Returns the number of syllables in the text. This method requires that | ||
| 187 | Lingua::__::Syllable is available for the language in question. This method | ||
| 188 | is derived from L<Text::Info::BASE>. | ||
| 189 | |||
| 190 | =cut | ||
| 191 | |||
| 192 | 6 | __PACKAGE__->meta->make_immutable; | |
| 193 | |||
| 194 | 6 | 1; | |
| 195 | |||
| 196 | =back | ||
| 197 | |||
| 198 | =head1 SEE ALSO | ||
| 199 | |||
| 200 | =over 4 | ||
| 201 | |||
| 202 | =item * L<Text::Info::Sentence> | ||
| 203 | |||
| 204 | =item * L<Text::Info::Readability> | ||
| 205 | |||
| 206 | =back | ||
| 207 | |||
| 208 | =head1 AUTHOR | ||
| 209 | |||
| 210 | Tore Aursand, C<< <toreau at gmail.com> >> | ||
| 211 | |||
| 212 | =head1 BUGS | ||
| 213 | |||
| 214 | Please report any bugs or feature requests to the web interface at L<https://rt.cpan.org/Dist/Display.html?Name=Text-Info> | ||
| 215 | |||
| 216 | =head1 SUPPORT | ||
| 217 | |||
| 218 | You can find documentation for this module with the perldoc command. | ||
| 219 | |||
| 220 | perldoc Text::Info | ||
| 221 | |||
| 222 | You can also look for information at: | ||
| 223 | |||
| 224 | =over 4 | ||
| 225 | |||
| 226 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 227 | |||
| 228 | L<http://annocpan.org/dist/Text-Info> | ||
| 229 | |||
| 230 | =item * CPAN Ratings | ||
| 231 | |||
| 232 | L<http://cpanratings.perl.org/d/Text-Info> | ||
| 233 | |||
| 234 | =item * Search CPAN | ||
| 235 | |||
| 236 | L<http://search.cpan.org/dist/Text-Info/> | ||
| 237 | |||
| 238 | =item * GitHub | ||
| 239 | |||
| 240 | L<https://github.com/toreau/Text-Info> | ||
| 241 | |||
| 242 | =back | ||
| 243 | |||
| 244 | =head1 LICENSE AND COPYRIGHT | ||
| 245 | |||
| 246 | Copyright 2015 Tore Aursand. | ||
| 247 | |||
| 248 | This program is free software; you can redistribute it and/or modify it | ||
| 249 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 250 | copy of the full license at: | ||
| 251 | |||
| 252 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 253 | |||
| 254 | Any use, modification, and distribution of the Standard or Modified | ||
| 255 | Versions is governed by this Artistic License. By using, modifying or | ||
| 256 | distributing the Package, you accept this license. Do not use, modify, | ||
| 257 | or distribute the Package, if you do not accept this license. | ||
| 258 | |||
| 259 | If your Modified Version has been derived from a Modified Version made | ||
| 260 | by someone other than you, you are nevertheless required to ensure that | ||
| 261 | your Modified Version complies with the requirements of this license. | ||
| 262 | |||
| 263 | This license does not grant you the right to use any trademark, service | ||
| 264 | mark, tradename, or logo of the Copyright Holder. | ||
| 265 | |||
| 266 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 267 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 268 | otherwise transfer the Package with respect to any patent claims | ||
| 269 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 270 | Package. If you institute patent litigation (including a cross-claim or | ||
| 271 | counterclaim) against any party alleging that the Package constitutes | ||
| 272 | direct or contributory patent infringement, then this Artistic License | ||
| 273 | to you shall terminate on the date that such litigation is filed. | ||
| 274 | |||
| 275 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 276 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 277 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 278 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 279 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 280 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 281 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 282 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||