File Coverage

blib/lib/Benchmark/Featureset/StopwordLists.pm
Criterion Covered Total %
statement 36 125 28.8
branch 0 14 0.0
condition 0 6 0.0
subroutine 12 21 57.1
pod 1 3 33.3
total 49 169 28.9


line stmt bran cond sub pod time code
1             package Benchmark::Featureset::StopwordLists;
2              
3 1     1   24997 use strict;
  1         3  
  1         24  
4 1     1   4 use warnings;
  1         1  
  1         28  
5              
6 1     1   514 use Benchmark::Featureset::StopwordLists::Config;
  1         44  
  1         39  
7              
8 1     1   25 use Config;
  1         2  
  1         48  
9 1     1   5 use Config::Tiny;
  1         2  
  1         21  
10              
11 1     1   13678 use Date::Simple;
  1         65802  
  1         69  
12              
13 1     1   1518 use Lingua::EN::StopWordList;
  1         1103  
  1         52  
14 1     1   1225 use Lingua::EN::StopWords;
  1         1126  
  1         86  
15 1     1   1205 use Lingua::StopWords;
  1         490  
  1         89  
16              
17 1     1   9 use Moo;
  1         3  
  1         14  
18              
19 1     1   3267 use Text::Xslate 'mark_raw';
  1         115703  
  1         369  
20              
21 1     1   17 use Types::Standard qw/Any Str/;
  1         2  
  1         14  
22              
23             has html_config =>
24             (
25             default => sub{return ''},
26             is => 'rw',
27             isa => Any,
28             required => 0,
29             );
30              
31             has module_config =>
32             (
33             default => sub{return ''},
34             is => 'rw',
35             isa => Any,
36             required => 0,
37             );
38              
39             has os_version =>
40             (
41             default => sub{return '! Debian'},
42             is => 'rw',
43             isa => Str,
44             required => 0,
45             );
46              
47             our $VERSION = '1.03';
48              
49             # --------------------------------------------------
50              
51             sub BUILD
52             {
53 0     0 0   my($self) = @_;
54 0           my($config) = Benchmark::Featureset::StopwordLists::Config -> new;
55              
56 0           $self -> html_config($config -> config);
57 0           $self -> module_config(Config::Tiny -> read('config/module.list.ini') );
58 0           $self -> os_version($config -> os_version);
59              
60             } # End of BUILD.
61              
62             # ------------------------------------------------
63              
64             sub _build_environment
65             {
66 0     0     my($self) = @_;
67              
68 0           my(@environment);
69              
70             # mark_raw() is needed because of the HTML tag .
71              
72             push @environment,
73             {left => 'Author', right => mark_raw(qq|Ron Savage|)},
74             {left => 'Date', right => Date::Simple -> today},
75             {left => 'OS', right => $self -> os_version},
76 0           {left => 'Perl', right => $Config{version} };
77              
78 0           return \@environment;
79             }
80             # End of _build_environment.
81              
82             # ------------------------------------------------
83              
84             sub _build_excluded_list
85             {
86 0     0     my($self, $module_config) = @_;
87 0           my($count) = 0;
88              
89 0           my($href);
90             my(@tr);
91              
92 0           push @tr, [{td => 'Name'}, {td => 'Package'}, {td => 'Notes'}];
93              
94 0           for my $module (sort keys %$module_config)
95             {
96 0 0         next if ($$module_config{$module}{include} eq 'Yes');
97              
98 0           $count++;
99              
100 0           ($href = $$module_config{$module}{package}) =~ s/::/-/g;
101              
102             # mark_raw() is needed because notes contain the HTML tag
.
103              
104             push @tr,
105             [
106             {td => mark_raw("$count: $module")},
107             {td => mark_raw(qq|$$module_config{$module}{package}|)},
108 0   0       {td => mark_raw($$module_config{$module}{notes} || '')},
109             ];
110             }
111              
112 0           push @tr, [{td => 'Name'}, {td => 'Package'}, {td => 'Notes'}];
113              
114 0           return [@tr];
115             }
116             # End of _build_excluded_list.
117              
118             # ------------------------------------------------
119              
120             sub _build_module_list
121             {
122 0     0     my($self, $module_config) = @_;
123 0           my($count) = 0;
124              
125 0           my($href);
126             my(@tr);
127 0           my($version);
128 0           my($word_list, %word_list);
129              
130 0           push @tr, [{td => 'Name'}, {td => 'Package'}, {td => 'Version'}, {td => 'Word count'}];
131              
132 0           for my $module (sort keys %$module_config)
133             {
134 0 0         next if ($$module_config{$module}{include} eq 'No');
135              
136 0           $count++;
137              
138 0           ($href = $$module_config{$module}{package}) =~ s/::/-/g;
139 0           $version = `mversion $module`;
140 0           $word_list = [];
141              
142 0 0         if ($module eq 'Lingua::EN::StopWordList')
    0          
    0          
143             {
144 0           $word_list = Lingua::EN::StopWordList -> new -> words;
145             }
146             elsif ($module eq 'Lingua::EN::StopWords')
147             {
148 0           $word_list = [sort keys %Lingua::EN::StopWords::StopWords];
149             }
150             elsif ($module eq 'Lingua::StopWords')
151             {
152 0           $word_list = [sort keys %{Lingua::StopWords::getStopWords('en')}];
  0            
153             }
154              
155 0           $word_list{$module} = [@$word_list];
156              
157 0           push @tr,
158             [
159             {td => "$count: $module"},
160             {td => mark_raw(qq|$$module_config{$module}{package}|)},
161             {td => $version},
162             {td => scalar @$word_list},
163             ];
164             }
165              
166 0           push @tr, [{td => 'Name'}, {td => 'Package'}, {td => 'Version'}, {td => 'Word count'}];
167              
168 0           return (\@tr, \%word_list);
169             }
170             # End of _build_module_list.
171              
172             # ------------------------------------------------
173              
174             sub _build_report_generator
175             {
176 0     0     my($self) = @_;
177 0           my($module) = __PACKAGE__;
178 0           my($href) = $module;
179 0           $href =~ s/::/-/g;
180              
181 0           my(@report);
182              
183 0           push @report,
184             {left => 'Module', right => 'Version'},
185             {left => mark_raw(qq|$module|), right => $VERSION};
186              
187 0           return \@report;
188              
189             } # End of _build_report_generator;
190              
191             # ------------------------------------------------
192              
193             sub _build_templater
194             {
195 0     0     my($self, $html_config) = @_;
196              
197             return Text::Xslate -> new
198             (
199             input_layer => '',
200             path => $$html_config{template_path},
201 0           );
202              
203             } # End of _build_templater.
204              
205             # --------------------------------------------------
206              
207             sub _build_word_lists
208             {
209 0     0     my($self, $module_list) = @_;
210              
211             # 1: Build a list of all words.
212              
213 0           my(%word, %word_list);
214              
215 0           for my $module (keys %$module_list)
216             {
217 0           $word{$_} = 1 for @{$$module_list{$module} };
  0            
218 0           $word_list{$module} = {};
219 0           @{$word_list{$module} }{@{$$module_list{$module} } } = (1) x @{$$module_list{$module} };
  0            
  0            
  0            
220             }
221              
222             # 2: Determine which module has which words.
223              
224 0           my(@temp);
225              
226 0           push @temp, {td => 'Id'};
227              
228 0           for my $module (sort keys %$module_list)
229             {
230 0           push @temp, {td => $module};
231             }
232              
233 0           my(@tr) = [@temp];
234 0           my($count) = 0;
235              
236 0           for my $word (sort keys %word)
237             {
238 0           @temp = ();
239              
240 0           push @temp, {td => ++$count};
241              
242 0           for my $module (sort keys %$module_list)
243             {
244 0 0         push @temp, {td => $word_list{$module}{$word} ? $word : ''};
245             }
246              
247 0           push @tr, [@temp];
248             }
249              
250 0           @temp = ();
251              
252 0           push @temp, {td => 'Id'};
253              
254 0           for my $module (sort keys %$module_list)
255             {
256 0           push @temp, {td => $module};
257             }
258              
259 0           push @tr, [@temp];
260              
261 0           return \@tr;
262              
263             } # End of _build_word_lists.
264              
265             # --------------------------------------------------
266              
267             sub log
268             {
269 0     0 0   my($self, $level, $s) = @_;
270 0   0       $level ||= 'debug';
271 0   0       $s ||= '';
272              
273 0           print "$level: $s\n";
274              
275             } # End of log.
276              
277             # ------------------------------------------------
278              
279             sub run
280             {
281 0     0 1   my($self) = @_;
282 0           my($html_config) = $self -> html_config;
283 0           my($module_config) = $self -> module_config;
284 0           my(@module_list) = $self -> _build_module_list($module_config);
285 0           my($templater) = $self -> _build_templater($html_config);
286 0           my($excluded_modules) = $self -> _build_excluded_list($module_config);
287              
288 0 0         print $templater -> render
289             (
290             'stopwordlists.report.tx',
291             {
292             default_css => "$$html_config{css_url}/default.css",
293             environment => $self -> _build_environment,
294             fancy_table_css => "$$html_config{css_url}/fancy.table.css",
295             modules_excluded => $#$excluded_modules > 1 ? $excluded_modules : [],
296             modules_included => $module_list[0],
297             report_generator => $self -> _build_report_generator,
298             word_data => $self -> _build_word_lists($module_list[1]),
299             }
300             );
301              
302             } # End of run.
303              
304             # ------------------------------------------------
305              
306             1;
307              
308             =pod
309              
310             =head1 NAME
311              
312             Benchmark::Featureset::StopwordLists - Compare various stopword list modules
313              
314             =head1 Synopsis
315              
316             #!/usr/bin/env perl
317              
318             use Benchmark::Featureset::StopwordLists;
319              
320             Benchmark::Featureset::StopwordLists -> new -> run;
321              
322             See scripts/stopwordlists.report.pl. This outputs HTML to STDOUT.
323              
324             Hint: Redirect the output of that script to your $doc_root/stopwordlists.report.html.
325              
326             A copy of the report ships in html/stopwordlists.report.html.
327              
328             L.
329              
330             =head1 Description
331              
332             L compares various stopword list modules.
333              
334             The list of modules processed is shipped in data/module.list.ini, and can easily be edited before re-running:
335              
336             shell> scripts/copy.config.pl
337             shell> scripts/stopwordlists.report.pl
338              
339             The config stuff is explained below.
340              
341             =head1 Distributions
342              
343             This module is available as a Unix-style distro (*.tgz).
344              
345             See L
346             for help on unpacking and installing distros.
347              
348             =head1 Installation
349              
350             =head2 The Module Itself
351              
352             Install L as you would for any C module:
353              
354             Run:
355              
356             cpanm Benchmark::Featureset::StopwordLists
357              
358             or run:
359              
360             sudo cpan Benchmark::Featureset::StopwordLists
361              
362             or unpack the distro, and then either:
363              
364             perl Build.PL
365             ./Build
366             ./Build test
367             sudo ./Build install
368              
369             or:
370              
371             perl Makefile.PL
372             make (or dmake or nmake)
373             make test
374             make install
375              
376             =head2 The Configuration File
377              
378             All that remains is to tell L your values for some options.
379              
380             For that, see config/.htbenchmark.featureset.stopwordlists.conf.
381              
382             If you are using Build.PL, running Build (without parameters) will run scripts/copy.config.pl,
383             as explained next.
384              
385             If you are using Makefile.PL, running make (without parameters) will also run scripts/copy.config.pl.
386              
387             Either way, before editing the config file, ensure you run scripts/copy.config.pl. It will copy
388             the config file using L, to a directory where the run-time code in
389             L will look for it.
390              
391             shell>cd Benchmark-Featureset-StopwordLists-1.00
392             shell>perl scripts/copy.config.pl
393              
394             Under Debian, this directory will be $HOME/.perl/Benchmark-Featureset-StopwordLists/. When you
395             run copy.config.pl, it will report where it has copied the config file to.
396              
397             Check the docs for L to see what your operating system returns for a
398             call to my_dist_config().
399              
400             The point of this is that after the module is installed, the config file will be
401             easily accessible and editable without needing permission to write to the directory
402             structure in which modules are stored.
403              
404             That's why L and L are pre-requisites for this module.
405              
406             Although this is a good mechanism for modules which ship with their own config files, be advised that some
407             CPAN tester machines run tests as users who don't have home directories, resulting in test failures.
408              
409             =head1 Constructor and Initialization
410              
411             C is called as C<< my($builder) = Benchmark::Featureset::StopwordLists -> new(k1 => v1, k2 => v2, ...) >>.
412              
413             It returns a new object of type C.
414              
415             Key-value pairs in accepted in the parameter list (see corresponding methods for details):
416              
417             =over 4
418              
419             =item o (None as yet)
420              
421             =back
422              
423             =head1 Methods
424              
425             =head2 new()
426              
427             For use by subclasses.
428              
429             =head2 run()
430              
431             Does the real work.
432              
433             See scripts/stopwordlists.report.pl and its output html/stopwordlists.report.html.
434              
435             Hint: Redirect the output of that script to $doc_root/stopwordlists.report.html.
436              
437             =head1 FAQ
438              
439             =head2 Where is the HTML template for the report?
440              
441             Templates ship in htdocs/assets/templates/benchmark/featureset/stopwordlists/.
442              
443             See also htdocs/assets/css/benchmark/featureset/stopwordlists/.
444              
445             =head2 How did you choose the modules to review?
446              
447             By searching MetaCPAN.org for phrases like 'stopword' and 'stop word'.
448              
449             =head1 See Also
450              
451             The other modules in this series are L and
452             L.
453              
454             One set of module comparison reviews, by Neil Bowers, is L.
455              
456             And another set of module comparison reviews, by Ron Savage, is L.
457              
458             =head1 Machine-Readable Change Log
459              
460             The file Changes was converted into Changelog.ini by L.
461              
462             =head1 Version Numbers
463              
464             Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
465              
466             =head1 Support
467              
468             Email the author, or log a bug on RT:
469              
470             L.
471              
472             =head1 Repository
473              
474             L.
475              
476             =head1 Author
477              
478             L was written by Ron Savage Iron@savage.net.auE> in 2012.
479              
480             Home page: L.
481              
482             =head1 Copyright
483              
484             Australian copyright (c) 2012, Ron Savage.
485              
486             All Programs of mine are 'OSI Certified Open Source Software';
487             you can redistribute them and/or modify them under the terms of
488             The Artistic License, a copy of which is available at:
489             http://www.opensource.org/licenses/index.html
490              
491             =cut