bin/yali-builder

filter: Statementstmt 85.9% 49 / 57 Branchbran 58.3% 14 / 24 Conditioncond 66.6% 8 / 12 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 76.1% 83 / 109 SCAR 0.1
CC
1
Cov
76%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Lingua/YALI/LanguageIdentifier.pm ↑ Summary bin/yali-identifier »
1 #!/usr/bin/env perl
2  
3 # ABSTRACT: Script for building language models
4 # PODNAME: yali-builder
5  
6 54 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 54 ▶use Lingua::YALI::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 54 ▶use Lingua::YALI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 54 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 54 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 54 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 54 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 54 our $VERSION = '0.014_01'; # VERSION
18  
19 54 my $output_file = undef;
20 54 my $file_list = undef;
21 54 my $input_file = undef;
22 54 my $count = undef;
23 54 my $ngram = 4;
24 54 my $help = 0;
25  
26 54 ▶my $result = GetOptions("filelist=s" => \$file_list,
Condition66%2/3
&GetOptions('filelist=s', \$file_list, 'input|i=s', \$input_file, 'output|o=s', \$output_file, 'count|c=i', \$count, 'ngram|n=i', \$ngram, 'help|h', \$help) || pod2usage('-exitval', 105)
l!l&&r!l&&!r
4509
MC/DC50%1/2
&GetOptions('filelist=s', \$file_list, 'input|i=s', \$input_file, 'output|o=s', \$output_file, 'count|c=i', \$count, 'ngram|n=i', \$ngram, 'help|h', \$help) || pod2usage('-exitval', 105)
&GetOptions('filelist=s', \$file_list, 'input|i=s', \$input_file, 'output|o=s', \$output_file, 'count|c=i', \$count, 'ngram|n=i', \$ngram, 'help|h', \$help) pod2usage('-exitval', 105)
Truth table66%2/3
A || B
A= &GetOptions('filelist=s', \$file_list, 'input|i=s', \$input_file, 'output|o=s', \$output_file, 'count|c=i', \$count, 'ngram|n=i', \$ngram, 'help|h', \$help)B= pod2usage('-exitval', 105)
ABresult
1X1
011
000
27 "input|i=s" => \$input_file,
28 "output|o=s" => \$output_file,
29 "count|c=i" => \$count,
30 "ngram|n=i" => \$ngram,
31 "help|h" => \$help
32 ) || pod2usage( -exitval => 105);
33  
34 45 ▶if ($help) {
Branch: 1 branch
BranchTrueFalseTotal
if ($help) 4 41 45
35 4 pod2usage(-exitval => 0);
36 }
37  
38 # reading input from STDIN is default
39 41 ▶if ( ! defined($input_file) && ! defined($file_list) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $input_file or defined $file_list) 25 16 41
Condition66%2/3
defined $input_file or defined $file_list
l!l&&r!l&&!r
16025
MC/DC50%1/2
defined $input_file or defined $file_list
defined $input_file defined $file_list
Truth table66%2/3
A or B
A= defined $input_fileB= defined $file_list
ABresult
1X1
011
000
40 25 $input_file = "-";
41 }
42  
43 # it is incorrect when parameter filelist and input are specified
44 41 ▶if ( defined($input_file) && defined($file_list) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $input_file and defined $file_list) 0 41 41
Condition33%1/3
defined $input_file and defined $file_list
!ll&&!rl&&r
0410
MC/DC0%0/2
defined $input_file and defined $file_list
defined $input_file defined $file_list
Truth table33%1/3
A and B
A= defined $input_fileB= defined $file_list
ABresult
0X0
100
111
45 0 pod2usage(-exitval => 101, -msg => "Options --filelist and --input can not be specified in the same time.");
46 }
47  
48 # output file is required
49 41 ▶if ( ! defined($output_file) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output_file) 1 40 41
50 1 pod2usage(-exitval => 101, -msg => "Output file --output has to be specified.");
51 }
52  
53 # check parameter range
54 40 ▶if ( defined($count) && $count < 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $count and $count < 1) 4 36 40
Condition100%3/3
defined $count and $count < 1
!ll&&!rl&&r
20164
MC/DC100%2/2
defined $count and $count < 1
defined $count $count < 1
Truth table100%3/3
A and B
A= defined $countB= $count < 1
ABresult
0X0
100
111
55 4 pod2usage(-exitval => 101, -msg => "The number of n-grams --count has to be positive. $count was used.");
56 }
57  
58 36 ▶if ( $ngram < 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ngram < 1) 4 32 36
59 4 pod2usage(-exitval => 101, -msg => "The n-gram size --ngram has to be positive. $ngram was used.");
60 }
61  
62 # construct builder
63 32 my $builder = Lingua::YALI::Builder->new(ngrams=>[$ngram]);
64  
65 # train models from input
66 32 ▶if ( defined($input_file) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $input_file) { } 32 0 32
elsif (defined $file_list) { } 0 0 0
67 32 ▶ if ( $input_file eq "-" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_file eq '-') { } 24 8 32
68 24 $builder->train_handle(\*STDIN);
69 } else {
70 8 $builder->train_file($input_file);
71 }
72 } elsif ( defined($file_list) ) {
73 0 my $fh_list = undef;
74 0 ▶ if ( $file_list eq "-" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file_list eq '-') { } 0 0 0
75 0 $fh_list = \*STDIN;
76 } else {
77 0 ▶ open($fh_list, "<", $file_list) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
open $fh_list, "<", $file_list or croak($!) 0 0 0
78 }
79 0 ▶ while ( <$fh_list> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh_list)) 0 0 0
80 0 chomp;
81 0 $builder->train_file($_);
82 }
83 }
84  
85 # store results
86 32 $builder->store($output_file, $ngram, $count);
87  
88 __END__
89  
90 =pod
91  
92 =encoding UTF-8
93  
94 =head1 NAME
95  
96 yali-builder - Script for building language models
97  
98 =head1 VERSION
99  
100 version 0.014_01
101  
102 =head1 SYNOPSIS
103  
104 yali-builder [options]
105  
106 Train models for language identification with yali-identifier.
107  
108 Options:
109  
110 -i, --input=F input file. When F is -, read standard input (default -).
111 --filelist=F input files are read from F. When F is -, read them from standard input.
112 -o, --output=F output file
113 -n, --ngram=N n-gram size (default 4)
114 -c, --count the number of n-grams
115 -h, --help prints documentation
116  
117 More examples are available at L<http://search.cpan.org/perldoc?Lingua%3A%3AYALI%3A%3AExamples>
118  
119 Version: 0.014_01 (2014-05-03)
120  
121 =head1 AUTHOR
122  
123 Martin Majlis <martin@majlis.cz>
124  
125 =head1 COPYRIGHT AND LICENSE
126  
127 This software is Copyright (c) 2012 by Martin Majlis.
128  
129 This is free software, licensed under:
130  
131 The (three-clause) BSD License
132  
133 =cut
« blib/lib/Lingua/YALI/LanguageIdentifier.pm ↑ Summary bin/yali-identifier »