line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Treex::Tool::Parser::MSTperl::Node; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Treex::Tool::Parser::MSTperl::Node::VERSION = '0.11949'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4208
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has config => ( |
9
|
|
|
|
|
|
|
isa => 'Treex::Tool::Parser::MSTperl::Config', |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
required => '1', |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has fields => ( |
15
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
required => '1', |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has ord => ( |
21
|
|
|
|
|
|
|
isa => 'Int', |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has parent => ( |
26
|
|
|
|
|
|
|
isa => 'Maybe[Treex::Tool::Parser::MSTperl::Node]', |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has parentOrd => ( |
31
|
|
|
|
|
|
|
isa => 'Int', |
32
|
|
|
|
|
|
|
is => 'rw', |
33
|
|
|
|
|
|
|
default => 0, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has children => ( |
37
|
|
|
|
|
|
|
isa => 'ArrayRef[Treex::Tool::Parser::MSTperl::Edge]', |
38
|
|
|
|
|
|
|
is => 'rw', |
39
|
|
|
|
|
|
|
default => sub { [] }, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has label => ( |
43
|
|
|
|
|
|
|
isa => 'Str', |
44
|
|
|
|
|
|
|
is => 'rw', |
45
|
|
|
|
|
|
|
default => '_', |
46
|
|
|
|
|
|
|
trigger => \&_label_set, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# label updated => need to update features of children |
50
|
|
|
|
|
|
|
# which contain LABEL |
51
|
|
|
|
|
|
|
# (i.e. FeaturesControl->feature_parent on config->label_field_index) |
52
|
|
|
|
|
|
|
# probably obsolete, now handled by dynamic features notion |
53
|
|
|
|
|
|
|
sub _label_set { |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my ($self) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# my ( $self, $parent_label ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $ALGORITHM = $self->config->labeller_algorithm; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
if ( $ALGORITHM < 20 ) { |
62
|
|
|
|
|
|
|
if ( $self->_fully_built ) { |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# TODO: not necessary to update ALL of the features! |
65
|
|
|
|
|
|
|
foreach my $child_edge ( @{ $self->children } ) { |
66
|
|
|
|
|
|
|
my $edge_features = $self->config-> |
67
|
|
|
|
|
|
|
labelledFeaturesControl->get_all_features($child_edge); |
68
|
|
|
|
|
|
|
$child_edge->features($edge_features); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# else only just building -> no updating yet! |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has _fully_built => ( |
79
|
|
|
|
|
|
|
isa => 'Bool', |
80
|
|
|
|
|
|
|
is => 'rw', |
81
|
|
|
|
|
|
|
default => '0', |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub BUILD { |
85
|
|
|
|
|
|
|
my ($self) = @_; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# handle parentOrd |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $parentOrdIndex = $self->config->parent_ord_field_index; |
90
|
|
|
|
|
|
|
my $parentOrd = $self->fields->[$parentOrdIndex]; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# if parent is set (i.e. not filled with dummy value) |
93
|
|
|
|
|
|
|
if ( defined $parentOrd && $parentOrd != -2 ) { |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# set the parentOrd field |
96
|
|
|
|
|
|
|
$self->parentOrd($parentOrd); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# fill with dummy value as this must not be used |
101
|
|
|
|
|
|
|
# (use node->parentOrd instead) |
102
|
|
|
|
|
|
|
$self->fields->[$parentOrdIndex] = -2; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# handle label |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $labelIndex = $self->config->label_field_index; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# if label is used |
109
|
|
|
|
|
|
|
if ( defined $labelIndex ) { |
110
|
|
|
|
|
|
|
my $label = $self->fields->[$labelIndex]; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# if label is set (i.e. not filled with dummy value) |
113
|
|
|
|
|
|
|
if ( defined $label && $label ne '_' ) { |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# set the label field |
116
|
|
|
|
|
|
|
$self->label($label); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# fill with dummy value as this must not be used |
121
|
|
|
|
|
|
|
# (use node->label instead) |
122
|
|
|
|
|
|
|
$self->fields->[$labelIndex] = '_'; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# my $debug = join ',', @{$self->fields}; |
126
|
|
|
|
|
|
|
# warn "$debug\n"; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
$self->_fully_built(1); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
return; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub copy_nonparsed { |
134
|
|
|
|
|
|
|
my ($self) = @_; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $copy = Treex::Tool::Parser::MSTperl::Node->new( |
137
|
|
|
|
|
|
|
fields => $self->fields, |
138
|
|
|
|
|
|
|
config => $self->config, |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
return $copy; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub copy_nonlabelled { |
145
|
|
|
|
|
|
|
my ($self) = @_; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $copy = Treex::Tool::Parser::MSTperl::Node->new( |
148
|
|
|
|
|
|
|
fields => $self->fields, |
149
|
|
|
|
|
|
|
config => $self->config, |
150
|
|
|
|
|
|
|
parentOrd => $self->parentOrd, |
151
|
|
|
|
|
|
|
); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
return $copy; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
__END__ |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=pod |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=for Pod::Coverage BUILD |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=encoding utf-8 |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 NAME |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Treex::Tool::Parser::MSTperl::Node |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 VERSION |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
version 0.11949 |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 DESCRIPTION |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Represents a word in a sentence. |
177
|
|
|
|
|
|
|
Contains its node features, such as form, lemma or pos tag. |
178
|
|
|
|
|
|
|
It may also point to its parent node. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 FIELDS |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 Required or automatically filled fields |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=over 4 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item fields |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Fields read from input and directly stored here, |
189
|
|
|
|
|
|
|
such as word form, morphological lemma, morphological tag etc. |
190
|
|
|
|
|
|
|
See L<Treex::Tool::Parser::MSTperl::Config> for details. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item ord |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1-based position of the word in the sentence. |
195
|
|
|
|
|
|
|
The ord is set automatically when a sentence containing the node is created |
196
|
|
|
|
|
|
|
(see L<Treex::Tool::Parser::MSTperl::Sentence>). |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=back |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 Parse tree related fields |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
These fields are filled in only if the sentence containing the node has been |
203
|
|
|
|
|
|
|
parsed. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=over 4 |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item parent |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Reference to the node's parent in the dependency tree. Default value is C<0>, |
210
|
|
|
|
|
|
|
which means that the node is a child of the root node. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item parentOrd |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Semantically this is an alias of C<parent->ord>, although technically the value |
215
|
|
|
|
|
|
|
is copied here, as it is used more often than the C<parent> field itself. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=back |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 METHODS |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=over 4 |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item my $node = my $node = Treex::Tool::Parser::MSTperl::Node->new( |
224
|
|
|
|
|
|
|
fields => [@fields], |
225
|
|
|
|
|
|
|
config => $config, |
226
|
|
|
|
|
|
|
); |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Creates a new node with the given field values (C<fields>) |
229
|
|
|
|
|
|
|
and using the given L<Treex::Tool::Parser::MSTperl::Config> instance |
230
|
|
|
|
|
|
|
(C<config>). |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item my $node_copy = $node->copy_nonparsed() |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Copies the node without the parse information |
235
|
|
|
|
|
|
|
(i.e. without the info about its parent). |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=back |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 AUTHORS |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Rudolf Rosa <rosa@ufal.mff.cuni.cz> |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles |
246
|
|
|
|
|
|
|
University in Prague |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
249
|
|
|
|
|
|
|
the same terms as Perl itself. |