| 1 | package Treex::Tool::Parser::MSTperl::Writer; | ||||||||||
| 2 | { | ||||||||||
| 3 | 2 | $Treex::Tool::Parser::MSTperl::Writer::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 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | has config => ( | |||||||||
| 11 | isa => 'Treex::Tool::Parser::MSTperl::Config', | ||||||||||
| 12 | is => 'ro', | ||||||||||
| 13 | required => '1', | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | sub write_tsv { | ||||||||
|
Subroutine
write_tsv: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||
| 17 | |||||||||||
| 18 | # (Str $filename, | ||||||||||
| 19 | # ArrayRef[Treex::Tool::Parser::MSTperl::Sentence] $sentences) | ||||||||||
| 20 | 2 | my ( $self, $filename, $sentences ) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 2 | open my $file, '>:encoding(utf8)', $filename; | |||||||||
| 23 | 2 | foreach my $sentence ( @{$sentences} ) { | |||||||||
| 24 | 6 | foreach my $node ( @{ $sentence->nodes } ) { | |||||||||
| 25 | 94 | my @line = @{ $node->fields }; | |||||||||
| 26 | |||||||||||
| 27 | # the parent_ord field contains -2 -> fill it with actual value | ||||||||||
| 28 | # which is stored in $node->parentOrd | ||||||||||
| 29 | 94 | $line[ $self->config->parent_ord_field_index ] = | |||||||||
| 30 | $node->parentOrd; | ||||||||||
| 31 | |||||||||||
| 32 | # the label field contains '_' -> fill it with actual value | ||||||||||
| 33 | # which is stored in $node->label | ||||||||||
| 34 | 94 | my $label_field_index = $self->config->label_field_index; | |||||||||
| 35 | 94 | ▶ | if ( defined $label_field_index ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 94 | $line[$label_field_index] = $node->label; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 94 | print $file join "\t", @line; | |||||||||
| 40 | 94 | print $file "\n"; | |||||||||
| 41 | } | ||||||||||
| 42 | 6 | print $file "\n"; | |||||||||
| 43 | } | ||||||||||
| 44 | 2 | close $file; | |||||||||
| 45 | |||||||||||
| 46 | 2 | ▶ | if ( -e $filename ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 2 | return 1; | |||||||||
| 48 | } else { | ||||||||||
| 49 | 0 | croak "MSTperl parser error:" | |||||||||
| 50 | . "unable to create the output file '$filename'!"; | ||||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 2 | 1; | |||||||||
| 55 | |||||||||||
| 56 | __END__ | ||||||||||