| 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
| |||||||||||
| 25 | 0 | print "Reading '$filename'...\n"; | |||||||||
| 26 | } | ||||||||||
| 27 | 2 | ▶ | while (<$file>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 149 | chomp; | |||||||||
| 29 | 149 | ▶ | if (/^$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 39 | 0 | ▶ | if ( scalar(@sentences) % 50 == 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 55 | 0 | print "Done.\n"; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 2 | return [@sentences]; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 2 | 1; | |||||||||
| 62 | |||||||||||
| 63 | __END__ | ||||||||||