ngrams.pl

filter: Statementstmt 86.3% 38 / 44 Branchbran 65.0% 13 / 20 Conditioncond 41.6% 5 / 12 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 66.6% 4 / 6 Podpod n/a totaltotal 67.7% 61 / 90 CC 1 SCAR 2.9
CC
1
Cov
74%
help
2.0
version
2.0
BEGIN
1.0
CRAP 1.3
« blib/script/ngrams.pl ↑ Summary
1 #!/usr/bin/perl -w
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #<? read_starfish_conf(); echo "\$VERSION = $ModuleVersion;"; !>#+
6 6 $VERSION = 2.007;#-
7 #+
8 6 $VERSION = 2.007;
9 #-
10 # $Revision: 1.26 $
11  
12 6 ▶use Text::Ngrams;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 my ($help, $version, $orderby, $onlyfirst, $limit, $spartan);
16 6 my $n = 3;
17 6 my $type = 'character';
18  
19 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
20 0 print <<EOF;
21 Usage: $0 [options] [files]
22 Compute the ngram frequencies and produce tables to the stdout.
23 Options:
24 --n=N The default is 3-grams.
25 --normalize Produce normalized frequencies (divided by the total
26 number of n-grams of the same size)
27 --type=T The default is character. Other types include: byte,
28 words, utf8, or there can be user-defined types.
29 --limit=N Limit the number of distinct n-grams.
30 BEWARE: Final tables may be inaccurate if limit is used.
31 --help Show this help.
32 --version Show version.
33 --orderby=ARG ARG can be: frequency or ngram.
34 --onlyfirst=N Only first N ngrams are printed for each n.
35 --spartan If specified, only the n-grams of maximal length are
36 printed.
37  
38 The options can be shortened to their unique prefixes and
39 the two dashes to one dash. No files means using STDIN.
40  
41 NOTE: The documentation of the module Text::Ngrams.pl provides more
42 information.
43 EOF
44 0 exit(1);
45 }
46  
47 6 my ($opt_normalize);
48  
49 6 ▶help()
Branch: 1 branch
BranchTrueFalseTotal
unless &GetOptions("n=i", \$n, "normalize", \$opt_normalize, "type=s", \$type, "limit=i", \$limit, "help", \$help, "version", \$version, "orderby=s", \$orderby, "onlyfirst=i", \$onlyfirst, "spartan", \$spartan) 0 6 6
50 unless
51 GetOptions('n=i' => \$n,
52 'normalize' => \$opt_normalize,
53 'type=s' => \$type,
54 'limit=i' => \$limit,
55 'help' => \$help,
56 'version' => \$version,
57 'orderby=s' => \$orderby,
58 'onlyfirst=i' => \$onlyfirst,
59 'spartan' => \$spartan);
60  
61 6 ▶help() if $n < 1 || int($n) != $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n < 1 or int $n != $n 0 6 6
Condition33%1/3
$n < 1 or int $n != $n
l!l&&r!l&&!r
006
MC/DC0%0/2
$n < 1 or int $n != $n
$n < 1 int $n != $n
Truth table33%1/3
A or B
A= $n < 1B= int $n != $n
ABresult
1X1
011
000
62  
63 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=6.9
64 0 print $VERSION, "\n";
65 0 exit(1);
66 }
67  
68 6 ▶help() if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 6 6
69 6 ▶version() if $version;
Branch: 1 branch
BranchTrueFalseTotal
if $version 0 6 6
70  
71 6 my %params = ( windowsize=>$n, type=>$type);
72  
73 0 ▶if (defined($limit) and ($limit > 0)) { $params{'limit'} = $limit }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $limit and $limit > 0) 0 6 6
Condition33%1/3
defined $limit and $limit > 0
!ll&&!rl&&r
600
MC/DC0%0/2
defined $limit and $limit > 0
defined $limit $limit > 0
Truth table33%1/3
A and B
A= defined $limitB= $limit > 0
ABresult
0X0
100
111
74  
75 6 my $ng = Text::Ngrams->new( %params );
76  
77 6 ▶if ($#ARGV > -1) { $ng->process_files(@ARGV) }
Branch: 1 branch
BranchTrueFalseTotal
if ($#ARGV > -1) { } 6 0 6
78 0 else { $ng->process_files(\*STDIN) }
79  
80 6 %params = ( 'out' => \*STDOUT );
81 6 ▶if (defined($orderby) and $orderby) { $params{'orderby'} = $orderby }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $orderby and $orderby) 6 0 6
Condition33%1/3
defined $orderby and $orderby
!ll&&!rl&&r
006
MC/DC0%0/2
defined $orderby and $orderby
defined $orderby $orderby
Truth table33%1/3
A and B
A= defined $orderbyB= $orderby
ABresult
0X0
100
111
82 6 ▶if (defined($onlyfirst) and $onlyfirst>0) { $params{'onlyfirst'} = $onlyfirst }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $onlyfirst and $onlyfirst > 0) 3 3 6
Condition66%2/3
defined $onlyfirst and $onlyfirst > 0
!ll&&!rl&&r
303
MC/DC50%1/2
defined $onlyfirst and $onlyfirst > 0
defined $onlyfirst $onlyfirst > 0
Truth table66%2/3
A and B
A= defined $onlyfirstB= $onlyfirst > 0
ABresult
0X0
100
111
83 6 ▶if ($opt_normalize) { $params{'normalize'} = $opt_normalize }
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_normalize) 4 2 6
84 6 ▶if ($spartan) { $params{'spartan'} = $spartan }
Branch: 1 branch
BranchTrueFalseTotal
if ($spartan) 1 5 6
85  
86 6 print $ng->to_string( %params );
87  
88 6 exit(0);
89  
90 __END__
« blib/script/ngrams.pl ↑ Summary