MSTperl/Reader.pm

filter: Statementstmt 87.5% 28 / 32 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 81.2% 39 / 48 CC 7 SCAR 18.5
CC
7
Cov
80%
read_tsv
7.9
BEGIN
1.0
BEGIN
1.0
CRAP 6.4
« MSTperl/TrainerUnlabelled.pm ↑ Summary MSTperl/Node.pm »
1 package Treex::Tool::Parser::MSTperl::Reader;
2 {
3 2 $Treex::Tool::Parser::MSTperl::Reader::VERSION = '0.11949';
4 }
5  
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 has config => (
10 isa => 'Treex::Tool::Parser::MSTperl::Config',
11 is => 'ro',
12 required => '1',
13 );
14  
15 2 ▶sub read_tsv {
Subroutine read_tsv: called CC=7 SCAR=20.7
Pod documented
16  
17 # (Str $filename)
18 2 my ( $self, $filename ) = @_;
19  
20 2 my @sentences;
21 my @nodes;
22 2 my $id = 1;
23 2 open my $file, '<:encoding(utf8)', $filename;
24 2 ▶ if ( $self->config->DEBUG >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->config->DEBUG >= 1) 0 2 2
25 0 print "Reading '$filename'...\n";
26 }
27 2 ▶ while (<$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $file)) 149 2 151
28 149 chomp;
29 149 ▶ if (/^$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^$/) { } 10 139 149
30 10 my $sentence = Treex::Tool::Parser::MSTperl::Sentence->new(
31 id => $id++, nodes => [@nodes],
32 config => $self->config
33 );
34 10 push @sentences, $sentence;
35 10 undef @nodes;
36  
37 # only progress and/or debug info
38 10 ▶ if ( $self->config->DEBUG >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->config->DEBUG >= 1) 0 10 10
39 0 ▶ if ( scalar(@sentences) % 50 == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar(@sentences) % 50 == 0) 0 0 0
40 0 print " " . scalar(@sentences) . " sentences read.\n";
41 }
42 }
43  
44 } else {
45 139 my @fields = split /\t/, $_, $self->config->field_names_count;
46 139 my $node = Treex::Tool::Parser::MSTperl::Node->new(
47 fields => [@fields],
48 config => $self->config
49 );
50 139 push @nodes, $node;
51 }
52 }
53 2 close $file;
54 2 ▶ if ( $self->config->DEBUG >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->config->DEBUG >= 1) 0 2 2
55 0 print "Done.\n";
56 }
57  
58 2 return [@sentences];
59 }
60  
61 2 1;
62  
63 __END__
« MSTperl/TrainerUnlabelled.pm ↑ Summary MSTperl/Node.pm »