Treex/Core/Node/A.pm

filter: Statementstmt 16.7% 33 / 197 Branchbran 4.5% 3 / 66 Conditioncond 22.2% 2 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 16.9% 9 / 53 Podpod 25.0% 12 / 48 totaltotal 15.8% 60 / 379 CC 42 SCAR 37.6
CC
42
Cov
14%
set_real_afun
156.0
get_real_afun
110.0
get_subtree_dependency_string
90.0
CRAP 42.8
« Treex/Core/Node/InClause.pm ↑ Summary Treex/Core/DocumentReader/ZoneReader.pm »
1 package Treex::Core::Node::A;
2 36 $Treex::Core::Node::A::VERSION = '2.20151210';
3 36 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 36 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 36 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 36 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 36 extends 'Treex::Core::Node';
8 36 with 'Treex::Core::Node::Ordered';
9 36 with 'Treex::Core::Node::InClause';
10 36 with 'Treex::Core::Node::EffectiveRelations';
11 36 with 'Treex::Core::Node::Interset' => { interset_attribute => 'iset' };
12  
13 # Original w-layer and m-layer attributes
14 36 has [qw(form lemma tag no_space_after)] => ( is => 'rw' );
15  
16 # Original a-layer attributes
17 # (Only afun and is_parenthesis_root originate from PDT, the rest was added in Treex).
18 36 has [
19 qw(deprel afun is_parenthesis_root edge_to_collapse is_auxiliary translit gloss)
20 ] => ( is => 'rw' );
21  
22 sub get_pml_type_name {
23 79 ▶ my ($self) = @_;
Subroutine get_pml_type_name: called CC=2 SCAR=6.9
Pod documented
24 79 ▶ return $self->is_root() ? 'a-root.type' : 'a-node.type';
Branch: 1 branch
BranchTrueFalseTotal
$self->is_root ? : 25 54 79
25 }
26  
27 # the node is a root of a coordination/apposition construction
28 sub is_coap_root {
29 51 ▶ my ($self) = @_;
Subroutine is_coap_root: called CC=3 SCAR=11.4
Pod documented
30 51 ▶ log_fatal('Incorrect number of arguments') if @_ != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 1 0 51 51
31 51 ▶ return defined $self->afun && $self->afun =~ /^(Coord|Apos)$/;
Condition66%2/3
defined $self->afun && $self->afun =~ /^(Coord|Apos)$/
!ll&&!rl&&r
03714
MC/DC50%1/2
defined $self->afun && $self->afun =~ /^(Coord|Apos)$/
defined $self->afun $self->afun =~ /^(Coord|Apos)$/
Truth table66%2/3
A && B
A= defined $self->afunB= $self->afun =~ /^(Coord|Apos)$/
ABresult
0X0
100
111
32 }
33  
34 sub n_node {
35 7 ▶ my ($self) = @_;
Subroutine n_node: called CC=1 SCAR=0.0
Pod documented
36 7 my ($first_n_node) = $self->get_referencing_nodes('a.rf');
37 7 return $first_n_node;
38 }
39  
40 #------------------------------------------------------------------------------
41 # Figures out the real function of the subtree. If its own afun is AuxP or
42 # AuxC, finds the first descendant with a real afun and returns it. If this is
43 # a coordination or apposition root, finds the first member and returns its
44 # afun (but note that members of the same coordination can differ in afuns if
45 # some of them have 'ExD').
46 #------------------------------------------------------------------------------
47 sub get_real_afun
48 {
49 0 ▶ my $self = shift;
Subroutine get_real_afun: not called CC=10 SCAR=47.0
Pod documented
50 0 my $warnings = shift;
51 0 my $afun = $self->afun();
52 0 ▶ if ( not defined($afun) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $afun) 0 0 0
53 0 $afun = '';
54 }
55 0 ▶ if ( $afun =~ m/^Aux[PC]$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($afun =~ /^Aux[PC]$/) { } 0 0 0
elsif ($self->is_coap_root) { } 0 0 0
56 {
57 0 my @children = $self->children();
58 # Exclude punctuation children (afun-wise, not POS-tag-wise: we do not want to exclude coordination heads).
59 0 @children = grep {$_->afun() !~ m/^Aux[XGK]$/} (@children);
60 0 my $n = scalar(@children);
61 0 ▶ if ( $n < 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 1) { } 0 0 0
62 {
63 0 ▶ if ($warnings)
Branch: 1 branch
BranchTrueFalseTotal
if ($warnings) 0 0 0
64 {
65 0 my $i_sentence = $self->get_bundle()->get_position() + 1; # tred numbers from 1
66 0 my $form = $self->form();
67 0 log_warn("$afun node does not have children (sentence $i_sentence, '$form')");
68 }
69 }
70 else
71 {
72 0 ▶ if ( $n > 1 && $warnings )
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 1 and $warnings) 0 0 0
Condition0%0/3
$n > 1 and $warnings
!ll&&!rl&&r
000
MC/DC0%0/2
$n > 1 and $warnings
$n > 1 $warnings
Truth table0%0/3
A and B
A= $n > 1B= $warnings
ABresult
0X0
100
111
73 {
74 0 my $i_sentence = $self->get_bundle()->get_position() + 1; # tred numbers from 1
75 0 my $form = $self->form();
76 0 log_warn("$afun node has $n children so it is not clear which one bears the real afun (sentence $i_sentence, '$form')");
77 }
78 0 return $children[0]->get_real_afun();
79 }
80 }
81 elsif ( $self->is_coap_root() )
82 {
83 0 my @members = $self->get_coap_members();
84 0 my $n = scalar(@members);
85 0 ▶ if ( $n < 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 1) { } 0 0 0
86 {
87 0 ▶ if ($warnings)
Branch: 1 branch
BranchTrueFalseTotal
if ($warnings) 0 0 0
88 {
89 0 my $i_sentence = $self->get_bundle()->get_position() + 1; # tred numbers from 1
90 0 my $form = $self->form();
91 0 log_warn("$afun does not have members (sentence $i_sentence, '$form')");
92 }
93 }
94 else
95 {
96 0 return $members[0]->get_real_afun();
97 }
98 }
99 0 return $afun;
100 }
101  
102 #------------------------------------------------------------------------------
103 # Sets the real function of the subtree. If its current afun is AuxP or AuxC,
104 # finds the first descendant with a real afun replaces it. If this is
105 # a coordination or apposition root, finds all the members and replaces their
106 # afuns (but note that members of the same coordination can differ in afuns if
107 # some of them have 'ExD'; this method can only set the same afun for all).
108 #------------------------------------------------------------------------------
109 sub set_real_afun
110 {
111 0 ▶ my $self = shift;
Subroutine set_real_afun: not called CC=12 SCAR=50.5
Pod documented
112 0 my $new_afun = shift;
113 0 my $warnings = shift;
114 0 my $afun = $self->afun();
115 0 ▶ if ( not defined($afun) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $afun) 0 0 0
116 0 $afun = '';
117 }
118 0 ▶ if ( $afun =~ m/^Aux[PC]$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($afun =~ /^Aux[PC]$/) { } 0 0 0
elsif ($self->is_coap_root) { } 0 0 0
119 {
120 0 my @children = $self->children();
121 # Exclude punctuation children (afun-wise, not POS-tag-wise: we do not want to exclude coordination heads).
122 0 @children = grep {$_->afun() !~ m/^Aux[XGK]$/} (@children);
123 0 my $n = scalar(@children);
124 0 ▶ if ( $n < 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 1) { } 0 0 0
125 {
126 0 ▶ if ($warnings)
Branch: 1 branch
BranchTrueFalseTotal
if ($warnings) 0 0 0
127 {
128 0 my $i_sentence = $self->get_bundle()->get_position() + 1; # tred numbers from 1
129 0 my $form = $self->form();
130 0 log_warn("$afun node does not have children (sentence $i_sentence, '$form')");
131 }
132 }
133 else
134 {
135 0 ▶ if ( $warnings && $n > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($warnings and $n > 1) 0 0 0
Condition0%0/3
$warnings and $n > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$warnings and $n > 1
$warnings $n > 1
Truth table0%0/3
A and B
A= $warningsB= $n > 1
ABresult
0X0
100
111
136 {
137 0 my $i_sentence = $self->get_bundle()->get_position() + 1; # tred numbers from 1
138 0 my $form = $self->form();
139 0 log_warn("$afun node has $n children so it is not clear which one bears the real afun (sentence $i_sentence, '$form')");
140 }
141 0 foreach my $child (@children)
142 {
143 0 $child->set_real_afun($new_afun);
144 }
145 0 return;
146 }
147 }
148 elsif ( $self->is_coap_root() )
149 {
150 0 my @members = $self->get_coap_members();
151 0 my $n = scalar(@members);
152 0 ▶ if ( $n < 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 1) { } 0 0 0
153 {
154 0 ▶ if ($warnings)
Branch: 1 branch
BranchTrueFalseTotal
if ($warnings) 0 0 0
155 {
156 0 my $i_sentence = $self->get_bundle()->get_position() + 1; # tred numbers from 1
157 0 my $form = $self->form();
158 0 log_warn("$afun does not have members (sentence $i_sentence, '$form')");
159 }
160 }
161 else
162 {
163 0 foreach my $member (@members)
164 {
165 0 $member->set_real_afun($new_afun);
166 }
167 0 return;
168 }
169 }
170 0 $self->set_afun($new_afun);
171 0 return $afun;
172 }
173  
174 #------------------------------------------------------------------------------
175 # Recursively copy attributes and children from myself to another node.
176 # This function is specific to the A layer because it contains the list of
177 # attributes. If we could figure out the list automatically, the function would
178 # become general enough to reside directly in Node.pm.
179 #
180 # NOTE: We could possibly make just copy_attributes() layer-dependent and unify
181 # the main copy_atree code.
182 #------------------------------------------------------------------------------
183 sub copy_atree
184 {
185 0 ▶ my $self = shift;
Subroutine copy_atree: not called CC=2 SCAR=17.9
Pod documented
186 0 my $target = shift;
187  
188 # Copy all attributes of the original node to the new one.
189 # We do this for all the nodes including the ‘root’ (which may actually be
190 # an ordinary node if we are copying a subtree).
191 0 $self->copy_attributes($target);
192  
193 0 my @children0 = $self->get_children( { ordered => 1 } );
194 0 foreach my $child0 (@children0)
195 {
196 # Create a copy of the child node.
197 0 my $child1 = $target->create_child();
198 # Call recursively on the subtrees of the children.
199 0 $child0->copy_atree($child1);
200 }
201  
202 0 return;
203 }
204  
205 #------------------------------------------------------------------------------
206 # Copies values of all attributes from one node to another. The only difference
207 # between the two nodes afterwards should be their ids.
208 #------------------------------------------------------------------------------
209 sub copy_attributes
210 {
211 0 ▶ my ( $self, $other ) = @_;
Subroutine copy_attributes: not called CC=2 SCAR=17.9
Pod undocumented
212 # We should copy all attributes that the node has but it is not easy to figure out which these are.
213 # TODO: As a workaround, we list the attributes here directly.
214 0 foreach my $attribute (
215 'form', 'lemma', 'tag', 'no_space_after', 'translit', 'gloss',
216 'ord', 'deprel', 'afun', 'is_member', 'is_parenthesis_root',
217 'conll/deprel', 'conll/cpos', 'conll/pos', 'conll/feat', 'is_shared_modifier', 'morphcat',
218 )
219 {
220 0 my $value = $self->get_attr($attribute);
221 0 $other->set_attr( $attribute, $value );
222 }
223 # copy values of interset features
224 0 my $f = $self->get_iset_structure();
225 0 $other->set_iset($f);
226 # deep copy of wild attributes
227 0 $other->set_wild( Storable::dclone( $self->wild ) );
228 0 return;
229 }
230  
231 # -- linking to p-layer --
232  
233 sub get_terminal_pnode {
234 0 ▶ my ($self) = @_;
Subroutine get_terminal_pnode: not called CC=2 SCAR=17.9
Pod documented
235 0 ▶ my $p_rf = $self->get_attr('p_terminal.rf') or return;
Branch: 1 branch
BranchTrueFalseTotal
my $p_rf = $self->get_attr("p_terminal.rf") or return 0 0 0
236 0 my $doc = $self->get_document();
237 0 return $doc->get_node_by_id($p_rf);
238 }
239  
240 sub set_terminal_pnode {
241 0 ▶ my ( $self, $pnode ) = @_;
Subroutine set_terminal_pnode: not called CC=2 SCAR=17.9
Pod documented
242 0 ▶ my $new_id = defined $pnode ? $pnode->id : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $pnode ? : 0 0 0
243 0 $self->set_attr( 'p_terminal.rf', $new_id );
244 0 return;
245 }
246  
247 sub get_nonterminal_pnodes {
248 0 ▶ my ($self) = @_;
Subroutine get_nonterminal_pnodes: not called CC=3 SCAR=24.8
Pod documented
249 0 ▶ my $pnode = $self->get_terminal_pnode() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $pnode = $self->get_terminal_pnode or return 0 0 0
250 0 my @nonterminals = ();
251 0 ▶ while ( $pnode->is_head ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pnode->is_head) 0 0 0
252 0 $pnode = $pnode->get_parent();
253 0 push @nonterminals, $pnode;
254 }
255 0 return @nonterminals;
256 }
257  
258 sub get_pnodes {
259 0 ▶ my ($self) = @_;
Subroutine get_pnodes: not called CC=1 SCAR=6.9
Pod documented
260 0 return ( $self->get_terminal_pnode, $self->get_nonterminal_pnodes );
261 }
262  
263 # -- referenced node ids --
264  
265 override '_get_reference_attrs' => sub {
266 97 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
267 97 return ('p_terminal.rf');
268 36 };
269  
270 # -- other --
271  
272 # Used only for Czech, so far.
273 sub reset_morphcat {
274 0 ▶ my ($self) = @_;
Subroutine reset_morphcat: not called CC=3 SCAR=24.8
Pod documented
275 0 foreach my $category (
276 qw(pos subpos gender number case possgender possnumber
277 person tense grade negation voice reserve1 reserve2)
278 )
279 {
280 0 my $old_value = $self->get_attr("morphcat/$category");
281 0 ▶ if ( !defined $old_value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $old_value) 0 0 0
282 0 $self->set_attr( "morphcat/$category", '.' );
283 }
284 }
285 0 return;
286 }
287  
288 # Used only for reading from PCEDT/PDT trees, so far.
289 sub get_subtree_string {
290 0 ▶ my ($self) = @_;
Subroutine get_subtree_string: not called CC=3 SCAR=24.8
Pod documented
291 0 ▶ return join '', map { defined( $_->form ) ? ( $_->form . ( $_->no_space_after ? '' : ' ' ) ) : '' } $self->get_descendants( { ordered => 1 } );
Branch: 2 branches
BranchTrueFalseTotal
defined $_->form ? : 0 0 0
$_->no_space_after ? : 0 0 0
292 }
293  
294 #------------------------------------------------------------------------------
295 # Serializes a tree to a string of dependencies (similar to the Stanford
296 # dependency format). Useful for debugging (quick comparison of two tree
297 # structures and an info string for the error message at the same time).
298 #------------------------------------------------------------------------------
299 sub get_subtree_dependency_string
300 {
301 0 ▶ my $self = shift;
Subroutine get_subtree_dependency_string: not called CC=9 SCAR=45.0
Pod undocumented
302 0 my $for_brat = shift; # Do we want a format that spans multiple lines but can be easily visualized in Brat?
303 0 my @nodes = $self->get_descendants({'ordered' => 1});
304 0 ▶ my $offset = $for_brat ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$for_brat ? : 0 0 0
305 my @dependencies = map
306 {
307 0 my $n = $_;
308 0 my $no = $n->ord()+$offset;
309 0 my $nf = $n->form();
310 0 my $p = $n->parent();
311 0 my $po = $p->ord()+$offset;
312 0 ▶ my $pf = $p->is_root() ? 'ROOT' : $p->form();
Branch: 1 branch
BranchTrueFalseTotal
$p->is_root ? : 0 0 0
313 0 ▶ my $d = defined($n->deprel()) ? $n->deprel() : defined($n->afun()) ? $n->afun() : defined($n->conll_deprel()) ? $n->conll_deprel() : 'NR';
Branch: 3 branches
BranchTrueFalseTotal
defined $n->deprel ? : 0 0 0
defined $n->afun ? : 0 0 0
defined $n->conll_deprel ? : 0 0 0
314 0 ▶ if($n->is_member())
Branch: 1 branch
BranchTrueFalseTotal
if ($n->is_member) 0 0 0
315 {
316 0 ▶ if(defined($n->deprel()))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n->deprel) { } 0 0 0
317 {
318 0 $d .= ':member';
319 }
320 else
321 {
322 0 $d .= '_M';
323 }
324 }
325 "$d($pf-$po, $nf-$no)"
326 0 }
327 (@nodes);
328 0 my $sentence = join(' ', map {$_->form()} (@nodes));
329 0 ▶ if($for_brat)
Branch: 1 branch
BranchTrueFalseTotal
if ($for_brat) { } 0 0 0
330 {
331 0 $sentence = "ROOT $sentence";
332 0 my $tree = join("\n", @dependencies);
333 0 return "~~~ sdparse\n$sentence\n$tree\n~~~\n";
334 }
335 else
336 {
337 0 my $tree = join('; ', @dependencies);
338 0 return "$sentence\t$tree";
339 }
340 }
341  
342 #----------- CoNLL attributes -------------
343  
344 3 ▶sub conll_deprel { return $_[0]->get_attr('conll/deprel'); }
Subroutine conll_deprel: called CC=1 SCAR=0.0
Pod undocumented
345 0 ▶sub conll_cpos { return $_[0]->get_attr('conll/cpos'); }
Subroutine conll_cpos: not called CC=1 SCAR=6.9
Pod undocumented
346 0 ▶sub conll_pos { return $_[0]->get_attr('conll/pos'); }
Subroutine conll_pos: not called CC=1 SCAR=6.9
Pod undocumented
347 0 ▶sub conll_feat { return $_[0]->get_attr('conll/feat'); }
Subroutine conll_feat: not called CC=1 SCAR=6.9
Pod undocumented
348  
349 0 ▶sub set_conll_deprel { return $_[0]->set_attr( 'conll/deprel', $_[1] ); }
Subroutine set_conll_deprel: not called CC=1 SCAR=6.9
Pod undocumented
350 0 ▶sub set_conll_cpos { return $_[0]->set_attr( 'conll/cpos', $_[1] ); }
Subroutine set_conll_cpos: not called CC=1 SCAR=6.9
Pod undocumented
351 0 ▶sub set_conll_pos { return $_[0]->set_attr( 'conll/pos', $_[1] ); }
Subroutine set_conll_pos: not called CC=1 SCAR=6.9
Pod undocumented
352 0 ▶sub set_conll_feat { return $_[0]->set_attr( 'conll/feat', $_[1] ); }
Subroutine set_conll_feat: not called CC=1 SCAR=6.9
Pod undocumented
353  
354 #---------- Morphcat -------------
355  
356 0 ▶sub morphcat_pos { return $_[0]->get_attr('morphcat/pos'); }
Subroutine morphcat_pos: not called CC=1 SCAR=6.9
Pod undocumented
357 0 ▶sub morphcat_subpos { return $_[0]->get_attr('morphcat/subpos'); }
Subroutine morphcat_subpos: not called CC=1 SCAR=6.9
Pod undocumented
358 0 ▶sub morphcat_number { return $_[0]->get_attr('morphcat/number'); }
Subroutine morphcat_number: not called CC=1 SCAR=6.9
Pod undocumented
359 0 ▶sub morphcat_gender { return $_[0]->get_attr('morphcat/gender'); }
Subroutine morphcat_gender: not called CC=1 SCAR=6.9
Pod undocumented
360 0 ▶sub morphcat_case { return $_[0]->get_attr('morphcat/case'); }
Subroutine morphcat_case: not called CC=1 SCAR=6.9
Pod undocumented
361 0 ▶sub morphcat_person { return $_[0]->get_attr('morphcat/person'); }
Subroutine morphcat_person: not called CC=1 SCAR=6.9
Pod undocumented
362 0 ▶sub morphcat_tense { return $_[0]->get_attr('morphcat/tense'); }
Subroutine morphcat_tense: not called CC=1 SCAR=6.9
Pod undocumented
363 0 ▶sub morphcat_negation { return $_[0]->get_attr('morphcat/negation'); }
Subroutine morphcat_negation: not called CC=1 SCAR=6.9
Pod undocumented
364 0 ▶sub morphcat_voice { return $_[0]->get_attr('morphcat/voice'); }
Subroutine morphcat_voice: not called CC=1 SCAR=6.9
Pod undocumented
365 0 ▶sub morphcat_grade { return $_[0]->get_attr('morphcat/grade'); }
Subroutine morphcat_grade: not called CC=1 SCAR=6.9
Pod undocumented
366 0 ▶sub morphcat_mood { return $_[0]->get_attr('morphcat/mood'); }
Subroutine morphcat_mood: not called CC=1 SCAR=6.9
Pod undocumented
367 0 ▶sub morphcat_possnumber { return $_[0]->get_attr('morphcat/possnumber'); }
Subroutine morphcat_possnumber: not called CC=1 SCAR=6.9
Pod undocumented
368 0 ▶sub morphcat_possgender { return $_[0]->get_attr('morphcat/possgender'); }
Subroutine morphcat_possgender: not called CC=1 SCAR=6.9
Pod undocumented
369  
370 0 ▶sub set_morphcat_pos { return $_[0]->set_attr( 'morphcat/pos', $_[1] ); }
Subroutine set_morphcat_pos: not called CC=1 SCAR=6.9
Pod undocumented
371 0 ▶sub set_morphcat_subpos { return $_[0]->set_attr( 'morphcat/subpos', $_[1] ); }
Subroutine set_morphcat_subpos: not called CC=1 SCAR=6.9
Pod undocumented
372 0 ▶sub set_morphcat_number { return $_[0]->set_attr( 'morphcat/number', $_[1] ); }
Subroutine set_morphcat_number: not called CC=1 SCAR=6.9
Pod undocumented
373 0 ▶sub set_morphcat_gender { return $_[0]->set_attr( 'morphcat/gender', $_[1] ); }
Subroutine set_morphcat_gender: not called CC=1 SCAR=6.9
Pod undocumented
374 0 ▶sub set_morphcat_case { return $_[0]->set_attr( 'morphcat/case', $_[1] ); }
Subroutine set_morphcat_case: not called CC=1 SCAR=6.9
Pod undocumented
375 0 ▶sub set_morphcat_person { return $_[0]->set_attr( 'morphcat/person', $_[1] ); }
Subroutine set_morphcat_person: not called CC=1 SCAR=6.9
Pod undocumented
376 0 ▶sub set_morphcat_tense { return $_[0]->set_attr( 'morphcat/tense', $_[1] ); }
Subroutine set_morphcat_tense: not called CC=1 SCAR=6.9
Pod undocumented
377 0 ▶sub set_morphcat_negation { return $_[0]->set_attr( 'morphcat/negation', $_[1] ); }
Subroutine set_morphcat_negation: not called CC=1 SCAR=6.9
Pod undocumented
378 0 ▶sub set_morphcat_voice { return $_[0]->set_attr( 'morphcat/voice', $_[1] ); }
Subroutine set_morphcat_voice: not called CC=1 SCAR=6.9
Pod undocumented
379 0 ▶sub set_morphcat_grade { return $_[0]->set_attr( 'morphcat/grade', $_[1] ); }
Subroutine set_morphcat_grade: not called CC=1 SCAR=6.9
Pod undocumented
380 0 ▶sub set_morphcat_mood { return $_[0]->set_attr( 'morphcat/mood', $_[1] ); }
Subroutine set_morphcat_mood: not called CC=1 SCAR=6.9
Pod undocumented
381 0 ▶sub set_morphcat_possnumber { return $_[0]->set_attr( 'morphcat/possnumber', $_[1] ); }
Subroutine set_morphcat_possnumber: not called CC=1 SCAR=6.9
Pod undocumented
382 0 ▶sub set_morphcat_possgender { return $_[0]->set_attr( 'morphcat/possgender', $_[1] ); }
Subroutine set_morphcat_possgender: not called CC=1 SCAR=6.9
Pod undocumented
383  
384 36 1;
385  
386 __END__
387  
388 ######## QUESTIONABLE / DEPRECATED METHODS ###########
389  
390  
391 # For backward compatibility with PDT-style
392 # TODO: This should be handled in format converters/Readers.
393 sub is_coap_member {
394 my ($self) = @_;
395 log_fatal("Incorrect number of arguments") if @_ != 1;
396 return (
397 $self->is_member
398 || ( ( $self->afun || '' ) =~ /^Aux[CP]$/ && grep { $_->is_coap_member } $self->get_children )
399 )
400 ? 1 : undef;
401 }
402  
403 # deprecated, use get_coap_members
404 sub get_transitive_coap_members { # analogy of PML_T::ExpandCoord
405 my ($self) = @_;
406 log_fatal("Incorrect number of arguments") if @_ != 1;
407 if ( $self->is_coap_root ) {
408 return (
409 map { $_->is_coap_root ? $_->get_transitive_coap_members : ($_) }
410 grep { $_->is_coap_member } $self->get_children
411 );
412 }
413 else {
414  
415 #log_warn("The node ".$self->get_attr('id')." is not root of a coordination/apposition construction\n");
416 return ($self);
417 }
418 }
419  
420 # deprecated, get_coap_members({direct_only})
421 sub get_direct_coap_members {
422 my ($self) = @_;
423 log_fatal("Incorrect number of arguments") if @_ != 1;
424 if ( $self->is_coap_root ) {
425 return ( grep { $_->is_coap_member } $self->get_children );
426 }
427 else {
428  
429 #log_warn("The node ".$self->get_attr('id')." is not root of a coordination/apposition construction\n");
430 return ($self);
431 }
432 }
433  
434 # too easy to implement and too rarely used to be a part of API
435 sub get_transitive_coap_root { # analogy of PML_T::GetNearestNonMember
436 my ($self) = @_;
437 log_fatal("Incorrect number of arguments") if @_ != 1;
438 while ( $self->is_coap_member ) {
439 $self = $self->get_parent;
440 }
441 return $self;
442 }
443  
444  
445 =encoding utf-8
446  
447 =head1 NAME
448  
449 Treex::Core::Node::A
450  
451 =head1 VERSION
452  
453 version 2.20151210
454  
455 =head1 DESCRIPTION
456  
457 a-layer (analytical) node
458  
459 =head1 ATTRIBUTES
460  
461 For each attribute (e.g. C<tag>), there is
462 a getter method (C<< my $tag = $anode->tag(); >>)
463 and a setter method (C<< $anode->set_tag('NN'); >>).
464  
465 =head2 Original w-layer and m-layer attributes
466  
467 =over
468  
469 =item form
470  
471 =item lemma
472  
473 =item tag
474  
475 =item no_space_after
476  
477 =back
478  
479 =head2 Original a-layer attributes
480  
481 =over
482  
483 =item afun
484  
485 =item is_parenthesis_root
486  
487 =item edge_to_collapse
488  
489 =item is_auxiliary
490  
491 =back
492  
493 =head1 METHODS
494  
495 =head2 Links from a-trees to phrase-structure trees
496  
497 =over 4
498  
499 =item $node->get_terminal_pnode
500  
501 Returns a terminal node from the phrase-structure tree
502 that corresponds to the a-node.
503  
504 =item $node->set_terminal_pnode($pnode)
505  
506 Set the given terminal node from the phrase-structure tree
507 as corresponding to the a-node.
508  
509 =item $node->get_nonterminal_pnodes
510  
511 Returns an array of non-terminal nodes from the phrase-structure tree
512 that correspond to the a-node.
513  
514 =item $node->get_pnodes
515  
516 Returns the corresponding terminal node and all non-terminal nodes.
517  
518 =back
519  
520 =head2 Other
521  
522 =over 4
523  
524 =item reset_morphcat
525  
526 =item get_pml_type_name
527  
528 Root and non-root nodes have different PML type in the pml schema
529 (C<a-root.type>, C<a-node.type>)
530  
531 =item is_coap_root
532  
533 Is this node a root (or head) of a coordination/apposition construction?
534 On a-layer this is decided based on C<afun =~ /^(Coord|Apos)$/>.
535  
536 =item get_real_afun()
537  
538 Figures out the real function of the subtree. If its own afun is C<AuxP> or
539 C<AuxC>, finds the first descendant with a real afun and returns it. If this is
540 a coordination or apposition root, finds the first member and returns its
541 afun (but note that members of the same coordination can differ in afuns if
542 some of them have C<ExD>).
543  
544 =item set_real_afun($new_afun)
545  
546 Sets the real function of the subtree. If its current afun is C<AuxP> or C<AuxC>,
547 finds the first descendant with a real afun replaces it. If this is
548 a coordination or apposition root, finds all the members and replaces their
549 afuns (but note that members of the same coordination can differ in afuns if
550 some of them have C<ExD>; this method can only set the same afun for all).
551  
552 =item copy_atree()
553  
554 Recursively copy children from myself to another node.
555 This method is specific to the A layer because it contains the list of
556 attributes. If we could figure out the list automatically, the method would
557 become general enough to reside directly in Node.pm.
558  
559 =item n_node()
560  
561 If this a-node is a part of a named entity,
562 this method returns the corresponding n-node (L<Treex::Core::Node::N>).
563 If this node is a part of more than one named entities,
564 only the most nested one is returned.
565 For example: "Bank of China"
566  
567 $n_node_for_china = $a_node_china->n_node();
568 print $n_node_for_china->get_attr('normalized_name'); # China
569 $n_node_for_bank_of_china = $n_node_for_china->get_parent();
570 print $n_node_for_bank_of_china->get_attr('normalized_name'); # Bank of China
571  
572 =item $node->get_subtree_string
573  
574 Return the string corresponding to a subtree rooted in C<$node>.
575 It's computed based on attributes C<form> and C<no_space_after>.
576  
577 =back
578  
579  
580 =head1 AUTHOR
581  
582 Zdeněk Žabokrtský <zabokrtsky@ufal.mff.cuni.cz>
583  
584 Martin Popel <popel@ufal.mff.cuni.cz>
585  
586 =head1 COPYRIGHT AND LICENSE
587  
588 Copyright © 2011-2012 by Institute of Formal and Applied Linguistics, Charles University in Prague
589  
590 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« Treex/Core/Node/InClause.pm ↑ Summary Treex/Core/DocumentReader/ZoneReader.pm »