line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Treex::Tool::Parser::MSTperl::Reader; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Treex::Tool::Parser::MSTperl::Reader::VERSION = '0.11949'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
2314
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use autodie; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has config => ( |
10
|
|
|
|
|
|
|
isa => 'Treex::Tool::Parser::MSTperl::Config', |
11
|
|
|
|
|
|
|
is => 'ro', |
12
|
|
|
|
|
|
|
required => '1', |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub read_tsv { |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# (Str $filename) |
18
|
|
|
|
|
|
|
my ( $self, $filename ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my @sentences; |
21
|
|
|
|
|
|
|
my @nodes; |
22
|
|
|
|
|
|
|
my $id = 1; |
23
|
|
|
|
|
|
|
open my $file, '<:encoding(utf8)', $filename; |
24
|
|
|
|
|
|
|
if ( $self->config->DEBUG >= 1 ) { |
25
|
|
|
|
|
|
|
print "Reading '$filename'...\n"; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
while (<$file>) { |
28
|
|
|
|
|
|
|
chomp; |
29
|
|
|
|
|
|
|
if (/^$/) { |
30
|
|
|
|
|
|
|
my $sentence = Treex::Tool::Parser::MSTperl::Sentence->new( |
31
|
|
|
|
|
|
|
id => $id++, nodes => [@nodes], |
32
|
|
|
|
|
|
|
config => $self->config |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
push @sentences, $sentence; |
35
|
|
|
|
|
|
|
undef @nodes; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# only progress and/or debug info |
38
|
|
|
|
|
|
|
if ( $self->config->DEBUG >= 1 ) { |
39
|
|
|
|
|
|
|
if ( scalar(@sentences) % 50 == 0 ) { |
40
|
|
|
|
|
|
|
print " " . scalar(@sentences) . " sentences read.\n"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} else { |
45
|
|
|
|
|
|
|
my @fields = split /\t/, $_, $self->config->field_names_count; |
46
|
|
|
|
|
|
|
my $node = Treex::Tool::Parser::MSTperl::Node->new( |
47
|
|
|
|
|
|
|
fields => [@fields], |
48
|
|
|
|
|
|
|
config => $self->config |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
push @nodes, $node; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
close $file; |
54
|
|
|
|
|
|
|
if ( $self->config->DEBUG >= 1 ) { |
55
|
|
|
|
|
|
|
print "Done.\n"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return [@sentences]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=pod |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=for Pod::Coverage BUILD |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=encoding utf-8 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Treex::Tool::Parser::MSTperl::Reader |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 VERSION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
version 0.11949 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Reads CoNLL-like TSV file |
82
|
|
|
|
|
|
|
(one line corresponds to one node, its features separated by tabs, |
83
|
|
|
|
|
|
|
sentence boundary is represented by an empty line) |
84
|
|
|
|
|
|
|
and converts it to L<Treex::Tool::Parser::MSTperl::Node> and |
85
|
|
|
|
|
|
|
L<Treex::Tool::Parser::MSTperl::Sentence> instances. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 METHODS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=over 4 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item $reader->read_tsv($filename) |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Reads a TSV file C<$filename>, returns a reference to an array of sentences |
94
|
|
|
|
|
|
|
(instances of L<Treex::Tool::Parser::MSTperl::Sentence>). |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The structure of the file (the order of the fields) |
97
|
|
|
|
|
|
|
is determined by the C<config> field |
98
|
|
|
|
|
|
|
(instance of L<Treex::Tool::Parser::MSTperl::Config>), |
99
|
|
|
|
|
|
|
specifically by the C<field_names> setting. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=back |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 AUTHORS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Rudolf Rosa <rosa@ufal.mff.cuni.cz> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles |
110
|
|
|
|
|
|
|
University in Prague |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
113
|
|
|
|
|
|
|
the same terms as Perl itself. |