Treex/Core/Coordination.pm

filter: Statementstmt 3.0% 22 / 719 Branchbran 0.0% 0 / 278 Conditioncond 0.0% 0 / 114 MC/DCmcdc 0.0% 0 / 61 Subroutinesub 13.5% 5 / 37 Podpod 0.0% 0 / 30 totaltotal 2.1% 27 / 1239 CC 208 SCAR 57.3
CC
208
Cov
2%
detect_szeged
930.0
detect_mosford
650.0
detect_moscow
462.0
CRAP 309.4
« Treex/Core/TredView/Styles.pm ↑ Summary Treex/Core/TredView/Labels.pm »
1 package Treex::Core::Coordination;
2 2 $Treex::Core::Coordination::VERSION = '2.20151210';
3 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Treex::Core::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Treex::Core::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11  
12 # Root nodes of conjuncts and delimiters are participants of coordination.
13 # Shared and private modifiers are not participants, even though we keep track of them.
14 # We maintain one array of records (hashes) about participants.
15 # For every participant, we maintain the following information:
16 # node ... reference to the corresponding Node object
17 # type ... conjunct|delimiter
18 # subtype ... conjunct|orphan||conjunction|symbol
19 # Technically: orphan => 0|1
20 # symbol => 0|1
21 # pmod ... reference to the list of private modifiers of the participant
22 # list of root nodes of dependents of the participant
23 # It is not necessarily identical to the list of current children of the node in the tree!
24 # Depending on the currently used annotation scheme, other participants may be among the children
25 # but they will not be listed here!
26 has _participants => (
27 is => 'rw',
28 isa => 'ArrayRef[HashRef]',
29 writer => '_set_participants',
30 reader => '_get_participants',
31 0 ▶ default => sub { [] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 2 );
33  
34  
35  
36 # We also maintain a list of shared modifiers, i.e. root nodes of subtrees that ought to depend on the root of the coordination.
37 # This is a simple array of references to Node objects, without any wrapping information.
38 has _smod => (
39 is => 'rw',
40 isa => 'ArrayRef[Treex::Core::Node]',
41 writer => '_set_smod',
42 reader => '_get_smod',
43 0 ▶ default => sub { [] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 2 );
45  
46  
47  
48 # Relation of the whole coordination to its parent.
49 2 has parent => (
50 is => 'rw',
51 isa => 'Treex::Core::Node',
52 writer => 'set_parent',
53 reader => 'parent'
54 );
55 2 has afun => (
56 is => 'rw',
57 isa => 'Str',
58 writer => 'set_afun',
59 reader => 'afun'
60 );
61 2 has is_member => (
62 is => 'rw',
63 isa => 'Bool',
64 writer => 'set_is_member',
65 reader => 'is_member'
66 );
67  
68  
69  
70 #------------------------------------------------------------------------------
71 # Checks that a node is not yet known to the coordination. We do not want to
72 # know one node in two different roles (not even twice in the same role!)
73 # This function either returns true or throws FATAL right away. So it cannot
74 # be used to check a node before we attempt to add it.
75 #------------------------------------------------------------------------------
76 sub check_that_node_is_new
77 {
78 0 ▶ my $self = shift;
Subroutine check_that_node_is_new: not called CC=11 SCAR=48.8
Pod undocumented
79 0 my $node = shift;
80 0 my $p = shift; my @participants = @{$p};
81 0 my $s = shift; my @smod = @{$s};
82 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
83 # Is it a participant?
84 0 ▶ if(grep {$_->{node} == $node} @participants)
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_->{"node"} == $node;} @participants) 0 0 0
85 {
86 0 ▶ my $form = $node->form(); $form = '' if(!defined($form));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 0 0 0
87 0 my $address = $node->get_address();
88 0 log_fatal("Node $node ('$form') is already a participant of this coordination!\n$address");
89 }
90 # Is it private modifier of a participant?
91 0 ▶ if(grep {$_ == $node} (map {@{$_->{pmod}}} @participants))
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ == $node;} map({@{$_->{"pmod"};};} @participants)) 0 0 0
92 {
93 0 ▶ my $form = $node->form(); $form = '' if(!defined($form));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 0 0 0
94 0 my $address = $node->get_address();
95 0 log_fatal("Node $node ('$form') is already a private modifier of a participant of this coordination!\n$address");
96 }
97 # Is it a shared modifier?
98 0 ▶ if(grep {$_ == $node} @smod)
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ == $node;} @smod) 0 0 0
99 {
100 0 ▶ my $form = $node->form(); $form = '' if(!defined($form));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 0 0 0
101 0 my $address = $node->get_address();
102 0 log_fatal("Node $node ('$form') is already a shared modifier of this coordination!\n$address");
103 }
104 # Is it registered as parent of the whole coordination?
105 # Note: We want the world consistent as far as our knowledge reaches.
106 # But we want to be independent of the parent-child links between the nodes.
107 # So we cannot guarantee that changing the parent-child links will not introduce cycles!
108 # If e.g. the registered parent is grandchild of a participant, we will not know about it.
109 # Then the Node object will launch alarm when we attempt to shape the coordination.
110 0 ▶ if(defined($self->parent()) && $node == $self->parent())
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->parent and $node == $self->parent) 0 0 0
Condition0%0/3
defined $self->parent and $node == $self->parent
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->parent and $node == $self->parent
defined $self->parent $node == $self->parent
Truth table0%0/3
A and B
A= defined $self->parentB= $node == $self->parent
ABresult
0X0
100
111
111 {
112 0 ▶ my $form = $node->form(); $form = '' if(!defined($form));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 0 0 0
113 0 my $address = $node->get_address();
114 0 log_fatal("Node $node ('$form') is already a parent of this coordination!\n$address");
115 }
116 0 return 1;
117 }
118  
119  
120  
121 #------------------------------------------------------------------------------
122 # Adds participant to coordination.
123 #------------------------------------------------------------------------------
124 sub add_participant
125 {
126 0 ▶ my $self = shift;
Subroutine add_participant: not called CC=3 SCAR=24.8
Pod undocumented
127 0 my $node = shift;
128 0 my $type = shift;
129 0 my $orphan = shift; # nonzero when this is a (ExD-like) dependent of a deleted conjunct
130 0 my $symbol = shift; # nonzero if this is a punctuation symbol
131 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
132 0 my @pmod = @_; # list of dependent nodes (not participants of this coordination!)
133 0 my $participants = $self->_get_participants();
134 0 my $smod = $self->_get_smod();
135 0 $self->check_that_node_is_new($node, $participants, $smod);
136 0 my %record =
137 (
138 'node' => $node,
139 'type' => $type,
140 'orphan' => $orphan,
141 'symbol' => $symbol,
142 'pmod' => []
143 );
144 0 push(@{$participants}, \%record);
145 0 foreach my $pm (@pmod)
146 {
147 0 $self->check_that_node_is_new($pm, $participants, $smod);
148 0 push(@{$record{pmod}}, $pm);
149 }
150 0 return \%record;
151 }
152  
153  
154  
155 #------------------------------------------------------------------------------
156 # Removes participant from coordination.
157 #------------------------------------------------------------------------------
158 sub remove_participant
159 {
160 0 ▶ my $self = shift;
Subroutine remove_participant: not called CC=4 SCAR=30.0
Pod undocumented
161 0 my $node = shift;
162 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
163 0 my $participants = $self->_get_participants();
164 0 ▶ for(my $i = 0; $i<=$#{$participants}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$participants;}) 0 0 0
165 {
166 0 ▶ if($participants->[$i]{node}==$node)
Branch: 1 branch
BranchTrueFalseTotal
if ($participants->[$i]{"node"} == $node) 0 0 0
167 {
168 0 my $participant = $participants->[$i];
169 0 splice(@{$participants}, $i, 1);
170 0 return $participant;
171 }
172 }
173 # If we are here we did not find the participant to remove.
174 0 log_fatal("Unknown participant");
175 }
176  
177  
178  
179 #------------------------------------------------------------------------------
180 # Adds conjunct to coordination.
181 #------------------------------------------------------------------------------
182 sub add_conjunct
183 {
184 0 ▶ my $self = shift;
Subroutine add_conjunct: not called CC=2 SCAR=17.9
Pod undocumented
185 0 my $node = shift;
186 0 my $orphan = shift; # nonzero when this is a (ExD-like) dependent of a deleted conjunct
187 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
188 0 my @pmod = @_; # list of dependent nodes (not participants of this coordination!)
189 0 return $self->add_participant($node, 'conjunct', $orphan, 0, @pmod);
190 }
191  
192  
193  
194 #------------------------------------------------------------------------------
195 # Adds conjunct delimiter (conjunction, punctuation) to coordination.
196 #------------------------------------------------------------------------------
197 sub add_delimiter
198 {
199 0 ▶ my $self = shift;
Subroutine add_delimiter: not called CC=2 SCAR=17.9
Pod undocumented
200 0 my $node = shift;
201 0 my $symbol = shift; # nonzero if this is a punctuation symbol
202 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
203 0 my @pmod = @_; # list of dependent nodes (not participants of this coordination!)
204 0 return $self->add_participant($node, 'delimiter', 0, $symbol, @pmod);
205 }
206  
207  
208  
209 #------------------------------------------------------------------------------
210 # Adds shared modifier to coordination.
211 #------------------------------------------------------------------------------
212 sub add_shared_modifier
213 {
214 0 ▶ my $self = shift;
Subroutine add_shared_modifier: not called CC=2 SCAR=17.9
Pod undocumented
215 0 my $node = shift;
216 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
217 0 my $participants = $self->_get_participants();
218 0 my $smod = $self->_get_smod();
219 0 $self->check_that_node_is_new($node, $participants, $smod);
220 0 push(@{$smod}, $node);
221 0 return;
222 }
223  
224  
225  
226 #------------------------------------------------------------------------------
227 # Finds a private modifier of a conjunct and makes it shared modifier.
228 #------------------------------------------------------------------------------
229 sub change_private_modifier_to_shared
230 {
231 0 ▶ my $self = shift;
Subroutine change_private_modifier_to_shared: not called CC=6 SCAR=37.4
Pod undocumented
232 0 my $node = shift;
233 0 my $conjunct = shift; # helps find the modifier
234 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
235 0 my $participants = $self->_get_participants();
236 0 foreach my $p (@{$participants})
237 {
238 0 ▶ if($p->{node}==$conjunct)
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"node"} == $conjunct) 0 0 0
239 {
240 0 ▶ for(my $i = 0; $i<=$#{$p->{pmod}}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$$p{"pmod"};}) 0 0 0
241 {
242 0 ▶ if($p->{pmod}[$i]==$node)
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"pmod"}[$i] == $node) 0 0 0
243 {
244 # Remove it from the list of private modifiers.
245 0 splice(@{$p->{pmod}}, $i, 1);
246 # Add it to the list of shared modifiers.
247 0 my $smod = $self->_get_smod();
248 0 push(@{$smod}, $node);
249 # Return success (if we get past the loops, it means we didn't find it).
250 0 return 1;
251 }
252 }
253 0 log_fatal("Unknown private modifier of a conjunct");
254 }
255 }
256 0 log_fatal("Unknown conjunct");
257 }
258  
259  
260  
261 #------------------------------------------------------------------------------
262 # Finds a shared modifier and makes it private modifier of a conjunct.
263 #------------------------------------------------------------------------------
264 sub change_shared_modifier_to_private
265 {
266 0 ▶ my $self = shift;
Subroutine change_shared_modifier_to_private: not called CC=6 SCAR=37.4
Pod undocumented
267 0 my $node = shift;
268 0 my $conjunct = shift;
269 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
270 0 my $smod = $self->_get_smod();
271 0 ▶ for(my $i = 0; $i<=$#{$smod}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$smod;}) 0 0 0
272 {
273 0 ▶ if($smod->[$i]==$node)
Branch: 1 branch
BranchTrueFalseTotal
if ($smod->[$i] == $node) 0 0 0
274 {
275 0 my $participants = $self->_get_participants();
276 0 foreach my $p (@{$participants})
277 {
278 0 ▶ if($p->{node}==$conjunct)
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"node"} == $conjunct) 0 0 0
279 {
280 # Remove it from the list of shared modifiers.
281 0 splice(@{$smod}, $i, 1);
282 # Add it to the list of private modifiers.
283 0 push(@{$p->{pmod}}, $node);
284 # Return success (if we get past the loops, it means we didn't find it).
285 0 return 1;
286 }
287 }
288 0 log_fatal("Unknown conjunct");
289 }
290 }
291 0 log_fatal("Unknown shared modifier");
292 }
293  
294  
295  
296 #------------------------------------------------------------------------------
297 # Returns the list of participants (all conjuncts and delimiters).
298 #------------------------------------------------------------------------------
299 sub get_participants
300 {
301 0 ▶ my $self = shift;
Subroutine get_participants: not called CC=2 SCAR=17.9
Pod undocumented
302 0 my %prm = @_;
303 0 my @list = map {$_->{node}} (@{$self->_get_participants()});
304 0 ▶ if($prm{ordered})
Branch: 1 branch
BranchTrueFalseTotal
if ($prm{"ordered"}) 0 0 0
305 {
306 0 @list = sort {$a->ord() <=> $b->ord()} (@list);
307 }
308 0 return @list;
309 }
310  
311  
312  
313 #------------------------------------------------------------------------------
314 # Returns the list of conjuncts (including orphans).
315 #------------------------------------------------------------------------------
316 sub get_conjuncts
317 {
318 0 ▶ my $self = shift;
Subroutine get_conjuncts: not called CC=2 SCAR=17.9
Pod undocumented
319 0 my %prm = @_;
320 0 my @list = map {$_->{node}} (grep {$_->{type} eq 'conjunct'} @{$self->_get_participants()});
321 0 ▶ if($prm{ordered})
Branch: 1 branch
BranchTrueFalseTotal
if ($prm{"ordered"}) 0 0 0
322 {
323 0 @list = sort {$a->ord() <=> $b->ord()} (@list);
324 }
325 0 return @list;
326 }
327  
328  
329  
330 #------------------------------------------------------------------------------
331 # Returns the list of orphan conjuncts.
332 #------------------------------------------------------------------------------
333 sub get_orphans
334 {
335 0 ▶ my $self = shift;
Subroutine get_orphans: not called CC=3 SCAR=24.8
Pod undocumented
336 0 my %prm = @_;
337 0 ▶ my @list = map {$_->{node}} (grep {$_->{type} eq 'conjunct' && $_->{orphan}} @{$self->_get_participants()});
Branch: 1 branch
BranchTrueFalseTotal
$_->{"type"} eq "conjunct" and $_->{"orphan"} 0 0 0
338 0 ▶ if($prm{ordered})
Branch: 1 branch
BranchTrueFalseTotal
if ($prm{"ordered"}) 0 0 0
339 {
340 0 @list = sort {$a->ord() <=> $b->ord()} (@list);
341 }
342 0 return @list;
343 }
344  
345  
346  
347 #------------------------------------------------------------------------------
348 # Returns the list of delimiters.
349 #------------------------------------------------------------------------------
350 sub get_delimiters
351 {
352 0 ▶ my $self = shift;
Subroutine get_delimiters: not called CC=2 SCAR=17.9
Pod undocumented
353 0 my %prm = @_;
354 0 my @list = map {$_->{node}} (grep {$_->{type} eq 'delimiter'} @{$self->_get_participants()});
355 0 ▶ if($prm{ordered})
Branch: 1 branch
BranchTrueFalseTotal
if ($prm{"ordered"}) 0 0 0
356 {
357 0 @list = sort {$a->ord() <=> $b->ord()} (@list);
358 }
359 0 return @list;
360 }
361  
362  
363  
364 #------------------------------------------------------------------------------
365 # Returns the list of conjunctions, i.e. non-symbol delimiters.
366 #------------------------------------------------------------------------------
367 sub get_conjunctions
368 {
369 0 ▶ my $self = shift;
Subroutine get_conjunctions: not called CC=3 SCAR=24.8
Pod undocumented
370 0 my %prm = @_;
371 0 ▶ my @list = map {$_->{node}} (grep {$_->{type} eq 'delimiter' && !$_->{symbol}} @{$self->_get_participants()});
Branch: 1 branch
BranchTrueFalseTotal
$_->{"type"} eq "delimiter" and not $_->{"symbol"} 0 0 0
372 0 ▶ if($prm{ordered})
Branch: 1 branch
BranchTrueFalseTotal
if ($prm{"ordered"}) 0 0 0
373 {
374 0 @list = sort {$a->ord() <=> $b->ord()} (@list);
375 }
376 0 return @list;
377 }
378  
379  
380  
381 #------------------------------------------------------------------------------
382 # Returns the list of shared modifiers.
383 #------------------------------------------------------------------------------
384 sub get_shared_modifiers
385 {
386 0 ▶ my $self = shift;
Subroutine get_shared_modifiers: not called CC=2 SCAR=17.9
Pod undocumented
387 0 my %prm = @_;
388 0 my @list = @{$self->_get_smod()};
389 0 ▶ if($prm{ordered})
Branch: 1 branch
BranchTrueFalseTotal
if ($prm{"ordered"}) 0 0 0
390 {
391 0 @list = sort {$a->ord() <=> $b->ord()} (@list);
392 }
393 0 return @list;
394 }
395  
396  
397  
398 #------------------------------------------------------------------------------
399 # Returns the list of private modifiers of a given conjunct.
400 #------------------------------------------------------------------------------
401 sub get_private_modifiers
402 {
403 0 ▶ my $self = shift;
Subroutine get_private_modifiers: not called CC=5 SCAR=34.0
Pod undocumented
404 0 my $conjunct = shift; # Node
405 0 ▶ log_fatal("Unknown conjunct") unless(defined($conjunct));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $conjunct 0 0 0
406 0 my %prm = @_;
407 0 my $participants = $self->_get_participants();
408 0 my @list;
409 0 foreach my $participant (@{$participants})
410 {
411 0 ▶ if($participant->{node}==$conjunct)
Branch: 1 branch
BranchTrueFalseTotal
if ($participant->{"node"} == $conjunct) 0 0 0
412 {
413 0 @list = @{$participant->{pmod}};
414 0 last;
415 }
416 }
417 0 ▶ if($prm{ordered})
Branch: 1 branch
BranchTrueFalseTotal
if ($prm{"ordered"}) 0 0 0
418 {
419 0 @list = sort {$a->ord() <=> $b->ord()} (@list);
420 }
421 0 return @list;
422 }
423  
424  
425  
426 #------------------------------------------------------------------------------
427 # Returns the list of immediate dependents of the coordination, i.e. shared and
428 # private modifiers.
429 #------------------------------------------------------------------------------
430 sub get_children
431 {
432 0 ▶ my $self = shift;
Subroutine get_children: not called CC=3 SCAR=24.8
Pod undocumented
433 0 my %prm = @_;
434 0 my @list = $self->get_shared_modifiers();
435 0 foreach my $participant (@{$self->_get_participants()})
436 {
437 0 push(@list, @{$participant->{pmod}});
438 }
439 0 ▶ if($prm{ordered})
Branch: 1 branch
BranchTrueFalseTotal
if ($prm{"ordered"}) 0 0 0
440 {
441 0 @list = sort {$a->ord() <=> $b->ord()} (@list);
442 }
443 0 return @list;
444 }
445 sub children
446 {
447 0 ▶ return get_children(@_);
Subroutine children: not called CC=1 SCAR=6.9
Pod undocumented
448 }
449  
450  
451  
452 #------------------------------------------------------------------------------
453 # Detects coordination structure according to current annotation (dependency
454 # links between nodes and labels of the relations). Expects Prague style,
455 # including normalization of AuxP/AuxC and nested coordinations. Thus it calls
456 # $node->set/get_real_afun().
457 # That makes the method suitable for repeated conversion between the tree (i.e.
458 # dependency relations and afuns between Node objects) and the Coordination
459 # object, during the later stages of normalization and after normalization.
460 #------------------------------------------------------------------------------
461 sub detect_prague
462 {
463 0 ▶ my $self = shift;
Subroutine detect_prague: not called CC=7 SCAR=40.3
Pod undocumented
464 0 my $node = shift; # suspected root node of coordination
465 0 ▶ return if $node->afun ne 'Coord';
Branch: 1 branch
BranchTrueFalseTotal
if $node->afun ne "Coord" 0 0 0
466 0 $self->set_parent($node->parent());
467 0 $self->set_is_member($node->is_member());
468 0 $self->set_afun('ExD'); # for the case that all conjuncts are ExD
469 # Note that $symbol is a guess only here.
470 # Also, the current labeling scheme does not allow for private modifiers of this delimiter.
471 0 my $symbol = $node->form() !~ m/^\pL+$/;
472 0 $self->add_delimiter($node, $symbol);
473 0 my @children = $node->children();
474 0 foreach my $child (@children)
475 {
476 0 ▶ if($child->is_member())
Branch: 2 branches
BranchTrueFalseTotal
if ($child->is_member) { } 0 0 0
elsif ($child->afun =~ /^Aux[GXY]$/) { } 0 0 0
477 {
478 # Note that this is a guess only.
479 # ExD could also mean that the whole coordination is in ExD (broken) relation to its parent.
480 0 my $orphan = 0;
481 0 ▶ if($child->get_real_afun() eq 'ExD')
Branch: 2 branches
BranchTrueFalseTotal
if ($child->get_real_afun eq 'ExD') { } 0 0 0
elsif ($self->afun eq 'ExD') { } 0 0 0
482 {
483 0 $orphan = 1;
484 }
485 elsif($self->afun() eq 'ExD') # take the first non-ExD encountered
486 {
487 # Coordination will never have afun AuxP or AuxC.
488 # Neither will it have Coord (it marks the head but it's not afun of the whole structure).
489 # If the first conjunct is a nested coordination, get_real_afun() will look for the afun among nested conjuncts.
490 0 $self->set_afun($child->get_real_afun());
491 }
492 0 $self->add_conjunct($child, $orphan, $child->children());
493 }
494 # No need for get_real_afun() here: these three auxiliaries should never appear with preposition or as nested conjuncts!
495 elsif($child->afun() =~ m/^Aux[GXY]$/)
496 {
497 # Note that the current labeling style does not allow to distinguish between:
498 # - delimiters between conjuncts (commas, semicolons, dashes, conjunctions etc.)
499 # - dependents of the head delimiter (comma right before conjunction; other words of multiword conjunction)
500 # - dependents of the whole coordination if they are symbols (e.g. quotation marks around coordination)
501 ###!!! At least quotation marks and parentheses at the outer margin could be excluded?
502 0 my $symbol = $child->afun() =~ m/^Aux[GX]$/;
503 0 $self->add_delimiter($child, $symbol, $child->children());
504 }
505 else
506 {
507 0 $self->add_shared_modifier($child);
508 }
509 }
510 0 return;
511 }
512  
513  
514  
515 #------------------------------------------------------------------------------
516 # Sets and labels parent-child relations between nodes so that they reflect the
517 # roles of the nodes in coordination. Uses Prague style. Returns the head node.
518 #------------------------------------------------------------------------------
519 sub shape_prague
520 {
521 0 ▶ my $self = shift;
Subroutine shape_prague: not called CC=15 SCAR=54.8
Pod undocumented
522 0 my @conjuncts = $self->get_conjuncts();
523 0 my @delimiters = $self->get_delimiters();
524 0 my @shared_modifiers = $self->get_shared_modifiers();
525 # Select the last delimiter as the new root.
526 0 ▶ if ( scalar(@delimiters)==0 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @delimiters == 0) 0 0 0
527 {
528 0 log_warn('Coordination has no delimiters.');
529 # It can happen, however rare, that there are no delimiters between the coordinated nodes.
530 # We have to be robust and to survive such cases if possible.
531 0 ▶ if ( scalar(@conjuncts)==0 )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @conjuncts == 0) { } 0 0 0
elsif (scalar @conjuncts == 1) { } 0 0 0
532 {
533 # Give the user at least some pointer to the tree.
534 0 ▶ log_warn($self->parent()) if(defined($self->parent()));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->parent 0 0 0
535 # Robustness has limits. Where would we attach shared modifiers?
536 0 log_fatal('Trying to shape an empty coordination (no conjuncts and no delimiters).');
537 }
538 elsif ( scalar(@conjuncts)==1 )
539 {
540 # Accompany the above warning by the address of the conjunct.
541 0 log_warn($conjuncts[0]->get_address());
542 # If there was one conjunct and one delimiter, it would be a deficient (typically clausal) coordination.
543 # The conjunct would depend on the delimiter.
544 # In this case however there is one "conjunct" and no delimiters.
545 # It is thus a normal node and we will act as if there was no coordination at all.
546 0 $conjuncts[0]->set_parent($self->parent());
547 0 $conjuncts[0]->set_real_afun($self->afun());
548 0 $conjuncts[0]->set_is_member($self->is_member());
549 # Attach all shared modifiers to the node.
550 0 foreach my $modifier ( @shared_modifiers )
551 {
552 0 $modifier->set_parent($conjuncts[0]);
553 0 $modifier->set_is_member(0);
554 }
555 0 return $conjuncts[0];
556 }
557 else
558 {
559 # Accompany the above warning by the address of the conjunct.
560 0 log_warn($conjuncts[0]->get_address());
561 # Since there seems to be no better solution, the first member of the coordination will become the root.
562 # It will no longer be recognizable as coordination member. The coordination may now be deficient and have only one member.
563 ###!!! Another possible solution would be to resort to Tesnière style and attach the conjuncts directly to the parent.
564 0 push( @delimiters, shift( @conjuncts ) );
565 }
566 }
567 # There is no guarantee that we obtained ordered lists of members and delimiters.
568 # They may have been added during tree traversal, which is not ordered linearly.
569 0 my @conjunctions = $self->get_conjunctions();
570 # Some punctuation symbols (comma, semicolon, colon, hyphen) are better coordinators than others (period, exclamation, question, quotation, brackets).
571 ###!!! Punctuation between conjuncts is probably better than punctuation after the last conjunct but we do not currently take this into account.
572 0 my @better_punctuation = grep {$_->form() =~ m/^[-,;:]$/} (@delimiters);
573 0 ▶ my @ordered_delimiters = sort {$a->ord() <=> $b->ord()} (@conjunctions ? @conjunctions : @better_punctuation ? @better_punctuation : @delimiters);
Branch: 2 branches
BranchTrueFalseTotal
@conjunctions ? : 0 0 0
@better_punctuation ? : 0 0 0
574 0 my $croot = pop(@ordered_delimiters);
575 # Attach the new root to the parent of the coordination.
576 0 $croot->set_parent($self->parent());
577 0 $croot->set_afun('Coord');
578 0 $croot->set_is_member($self->is_member());
579 # Martin's transformations might also need the flag whether a node is coordinating conjunction.
580 0 $croot->wild()->{is_coord_conjunction} = 1;
581 # Attach all coordination members to the new root.
582 0 foreach my $conjunct ( @conjuncts )
583 {
584 0 $conjunct->set_parent($croot);
585 0 $conjunct->set_is_member(1);
586 # Assign the afun of the whole coordination to the member.
587 # Prepositional members require special treatment: the afun goes to the argument of the preposition.
588 # Some members are in fact orphan dependents of an ellided member.
589 # Their current afun is ExD and they shall keep it, unlike the normal members.
590 0 ▶ $conjunct->set_real_afun($self->afun()) unless ( $conjunct->get_real_afun() eq 'ExD' );
Branch: 1 branch
BranchTrueFalseTotal
unless $conjunct->get_real_afun eq "ExD" 0 0 0
591 }
592 # Attach all remaining delimiters to the new root.
593 # We need the $symbol attribute, thus we cannot use @ordered_delimiters.
594 0 ▶ my @otherdelim = grep {$_->{type} eq 'delimiter' && $_->{node}!=$croot} (@{$self->_get_participants()});
Branch: 1 branch
BranchTrueFalseTotal
$_->{"type"} eq "delimiter" and $_->{"node"} != $croot 0 0 0
595 0 foreach my $delimrec ( @otherdelim )
596 {
597 0 my $delimiter = $delimrec->{node};
598 0 my $symbol = $delimrec->{symbol};
599 0 $delimiter->set_parent($croot);
600 0 $delimiter->set_is_member(0);
601 0 ▶ if ( $delimiter->form() eq ',' )
Branch: 2 branches
BranchTrueFalseTotal
if ($delimiter->form eq ',') { } 0 0 0
elsif ($symbol) { } 0 0 0
602 {
603 0 $delimiter->set_afun('AuxX');
604 }
605 elsif ( $symbol )
606 {
607 0 $delimiter->set_afun('AuxG');
608 }
609 else
610 {
611 0 $delimiter->set_afun('AuxY');
612 # Martin's transformations might also need the flag whether a node is coordinating conjunction.
613 0 $delimiter->wild()->{is_coord_conjunction} = 1;
614 }
615 }
616 # Attach all shared modifiers to the new root.
617 0 foreach my $modifier ( @shared_modifiers )
618 {
619 0 $modifier->set_parent($croot);
620 0 $modifier->set_is_member(0);
621 0 $modifier->set_is_shared_modifier(1);
622 }
623 0 return $croot;
624 }
625  
626  
627  
628 #------------------------------------------------------------------------------
629 # Detects coordination structure according to current annotation (dependency
630 # links between nodes and labels of the relations). Expects the Alpino (Dutch)
631 # variant of the Prague style, i.e. the head of the coordination bears the
632 # label of the relation between the coordination and its parent. The afuns
633 # (and wild attributes) of conjuncts just mark them as conjuncts.
634 # The method assumes that nothing has been normalized yet. In particular it
635 # assumes that there are no AuxP/AuxC afuns (there are PrepArg/SubArg instead).
636 # Thus the method does not call $node->set/get_real_afun().
637 #------------------------------------------------------------------------------
638 sub detect_alpino
639 {
640 0 ▶ my $self = shift;
Subroutine detect_alpino: not called CC=6 SCAR=37.4
Pod undocumented
641 0 my $node = shift; # suspected root node of coordination
642 # Root of the tree cannot be the head of coordination structure.
643 0 ▶ return if($node->is_root());
Branch: 1 branch
BranchTrueFalseTotal
if $node->is_root 0 0 0
644 # Are there any children that are conjuncts?
645 0 my @children = $node->children();
646 0 my @conjuncts = grep {$_->wild()->{conjunct}} (@children);
647 0 ▶ return unless(@conjuncts);
Branch: 1 branch
BranchTrueFalseTotal
unless @conjuncts 0 0 0
648 0 $self->set_parent($node->parent());
649 0 $self->set_is_member($node->is_member());
650 0 $self->set_afun($node->afun());
651 # Note that $symbol is a guess only here.
652 # Also, the current labeling scheme does not allow for private modifiers of this delimiter.
653 0 my $symbol = $node->form() !~ m/^\pL+$/;
654 0 $self->add_delimiter($node, $symbol);
655 0 foreach my $child (@children)
656 {
657 # The wild attribute conjunct should have been filled during deprel_to_afun().
658 0 ▶ if($child->wild()->{conjunct})
Branch: 2 branches
BranchTrueFalseTotal
if ($child->wild->{'conjunct'}) { } 0 0 0
elsif ($child->afun =~ /^Aux[GXY]$/) { } 0 0 0
659 {
660 0 my $orphan = 0;
661 0 $self->add_conjunct($child, $orphan, $child->children());
662 }
663 # No need for get_real_afun() here: these three auxiliaries should never appear with preposition or as nested conjuncts!
664 elsif($child->afun() =~ m/^Aux[GXY]$/)
665 {
666 # Note that the current labeling style does not allow to distinguish between:
667 # - delimiters between conjuncts (commas, semicolons, dashes, conjunctions etc.)
668 # - dependents of the head delimiter (comma right before conjunction; other words of multiword conjunction)
669 # - dependents of the whole coordination if they are symbols (e.g. quotation marks around coordination)
670 ###!!! At least quotation marks and parentheses at the outer margin could be excluded?
671 0 my $symbol = $child->afun() =~ m/^Aux[GX]$/;
672 0 $self->add_delimiter($child, $symbol, $child->children());
673 }
674 else
675 {
676 0 $self->add_shared_modifier($child);
677 }
678 }
679 # We now know all we can.
680 # It's time for a few more heuristics.
681 # Even though the Alpino style belongs to the Prague family, it does not seem to take the opportunity to distinguish shared modifiers.
682 # There are frequent non-projective dependents of the first conjunct that appear in the sentence after the last conjunct.
683 0 $self->reconsider_distant_private_modifiers();
684 0 return;
685 }
686  
687  
688  
689 #------------------------------------------------------------------------------
690 # Detects coordination structure according to current annotation (dependency
691 # links between nodes and labels of the relations). Expects Moscow or Stanford
692 # style, without nested coordinations and without shared modifiers (example
693 # treebank is Danish):
694 # - the root of the coordination is not marked
695 # - conjuncts have wild->{conjunct}
696 # (the afun 'CoordArg' may have not survived Aux[CP] normalization)
697 # - conjunctions have wild->{coordinator}
698 # (the afun 'Coord' may have not survived Aux[CP] normalization)
699 # - all such children are collected recursively
700 # - all other children along the way are private modifiers
701 # The method assumes that nothing has been normalized yet. In particular it
702 # assumes that there are no AuxP/AuxC afuns (there are PrepArg/SubArg instead).
703 # Thus the method does not call $node->set/get_real_afun().
704 #------------------------------------------------------------------------------
705 sub detect_mosford
706 {
707 0 ▶ my $self = shift;
Subroutine detect_mosford: not called CC=25 SCAR=64.8
Pod undocumented
708 0 my $node = shift; # suspected root node of coordination
709 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
710 # This function is recursive. If we already have conjuncts then we know this is not the top level.
711 0 my $top = scalar($self->get_conjuncts())==0;
712 ###!!!DEBUG
713 0 my $debug = 0;
714 0 ▶ if($debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
715 {
716 0 my $form = $node->form();
717 0 ▶ $form = '' if(!defined($form));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 0 0 0
718 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) { } 0 0 0
719 {
720 0 $node->set_form("T:$form");
721 }
722 else
723 {
724 0 $node->set_form("X:$form");
725 }
726 }
727 ###!!!END
728 0 my @children = $node->children();
729 my @participants = grep
730 {
731 0 $_->wild()->{coordinator} ||
732 $_->wild()->{conjunct} ||
733 # We cannot use get_real_afun() because the foreign data is not yet fully normalized
734 # and there are things like AuxP with two children, first AuxX, second AuxC.
735 # get_real_afun() would return AuxX, then we would think it is a delimiter rather than modifier,
736 # even though the preposition governs a whole modifier subtree.
737 # Also, get_real_afun() processes coordinations, and our coordination is not yet valid.
738 #$_->get_real_afun() =~ m/^Aux[GXY]$/
739 0 ▶ $_->afun() =~ m/^Aux[GXY]$/
Branch: 1 branch
BranchTrueFalseTotal
$_->wild->{"coordinator"} or $_->wild->{"conjunct"} or $_->afun =~ /^Aux[GXY]$/ 0 0 0
Condition0%0/3
$_->wild->{"coordinator"} or $_->wild->{"conjunct"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->wild->{"coordinator"} or $_->wild->{"conjunct"}
$_->wild->{"coordinator"} $_->wild->{"conjunct"}
Truth table0%0/3
A or B
A= $_->wild->{"coordinator"}B= $_->wild->{"conjunct"}
ABresult
1X1
011
000
740 }
741 @children;
742 my @recursive_participants = grep
743 {
744 0 $_->wild()->{coordinator} ||
745 $_->wild()->{conjunct}
746 0 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
$_->wild->{"coordinator"} or $_->wild->{"conjunct"} 0 0 0
747 @participants;
748 0 my $bottom = scalar(@recursive_participants)==0;
749 0 ▶ if($top && $bottom)
Branch: 1 branch
BranchTrueFalseTotal
if ($top and $bottom) 0 0 0
Condition0%0/3
$top and $bottom
!ll&&!rl&&r
000
MC/DC0%0/2
$top and $bottom
$top $bottom
Truth table0%0/3
A and B
A= $topB= $bottom
ABresult
0X0
100
111
750 {
751 # No participants found. This $node is not a root of coordination.
752 0 return;
753 }
754 # Orphans are treated similarly to conjuncts but they can be only detected under Coord
755 # and there will be no recursion over them.
756 0 ▶ my $exdorphans = !$top && $node->wild()->{coordinator};
Condition0%0/3
!$top && $node->wild->{'coordinator'}
!ll&&!rl&&r
000
MC/DC0%0/2
!$top && $node->wild->{'coordinator'}
!$top $node->wild->{'coordinator'}
Truth table0%0/3
not(A) && B
A= !$topB= $node->wild->{'coordinator'}
ABresult
0X0
100
111
757 0 ▶ if($exdorphans)
Branch: 1 branch
BranchTrueFalseTotal
if ($exdorphans) 0 0 0
758 {
759 0 my @orphans = grep {$_->afun() eq 'ExD'} @children;
760 # Orphans can be added right away. There will be no recursion over them.
761 0 foreach my $orphan (@orphans)
762 {
763 0 $self->add_conjunct($orphan, 1, $orphan->children());
764 }
765 }
766 my @modifiers = grep
767 {
768 # We cannot use get_real_afun() because the foreign data is not yet fully normalized (see above).
769 #my $afun = $_->get_real_afun();
770 0 my $afun = $_->afun();
771 !$_->wild()->{coordinator} &&
772 !$_->wild()->{conjunct} &&
773 0 ▶ $afun !~ m/^Aux[GXY]$/ &&
Branch: 1 branch
BranchTrueFalseTotal
not $_->wild->{"coordinator"} || $_->wild->{"conjunct"} || $afun =~ /^Aux[GXY]$/ and !$exdorphans || $afun ne "ExD" 0 0 0
Condition0%0/12
!($_->wild->{'coordinator'} || $_->wild->{'conjunct'} || $afun =~ /^Aux[GXY]$/) && (!$exdorphans || $afun ne 'ExD')
!ll&&!rl&&r
000
$_->wild->{'coordinator'} || $_->wild->{'conjunct'} || $afun =~ /^Aux[GXY]$/
l!l&&r!l&&!r
000
$_->wild->{"coordinator"} or $_->wild->{"conjunct"}
l!l&&r!l&&!r
000
not $exdorphans or $afun ne "ExD"
l!l&&r!l&&!r
000
MC/DC0%0/5
!($_->wild->{'coordinator'} || $_->wild->{'conjunct'} || $afun =~ /^Aux[GXY]$/) && (!$exdorphans || $afun ne 'ExD')
$_->wild->{"coordinator"} $_->wild->{"conjunct"} $afun =~ /^Aux[GXY]$/ not $exdorphans $afun ne "ExD"
Truth table0%0/6
not(A or B || C) && not(D) or E
A= $_->wild->{"coordinator"}B= $_->wild->{"conjunct"}C= $afun =~ /^Aux[GXY]$/D= not $exdorphansE= $afun ne "ExD"
ABCDEresult
1XXXX0
01XXX0
001XX0
000000
0001X1
000011
774 (
775 !$exdorphans ||
776 $afun ne 'ExD'
777 )
778 }
779 @children;
780 0 ▶ if($bottom)
Branch: 1 branch
BranchTrueFalseTotal
if ($bottom) 0 0 0
781 {
782 # Return my modifiers to the upper level. They will need them when they add me as participant.
783 0 return @modifiers;
784 }
785 # If we are here we have participants: either conjuncts or delimiters or both.
786 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
787 {
788 # Add the root conjunct before recursion. That's how the lower levels will know they're not the top level.
789 0 my $orphan = 0;
790 0 $self->add_conjunct($node, $orphan, @modifiers);
791 # Save the relation of the coordination to its parent.
792 0 $self->set_parent($node->parent());
793 # We cannot use get_real_afun() because the foreign data is not yet fully normalized (see above).
794 #$self->set_afun($node->get_real_afun());
795 0 $self->set_afun($node->afun());
796 0 $self->set_is_member($node->is_member());
797 }
798 0 foreach my $participant (@participants)
799 {
800 0 ▶ my $recursive = $participant->wild()->{coordinator} || $participant->wild()->{conjunct};
Condition0%0/3
$participant->wild->{'coordinator'} || $participant->wild->{'conjunct'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$participant->wild->{'coordinator'} || $participant->wild->{'conjunct'}
$participant->wild->{'coordinator'} $participant->wild->{'conjunct'}
Truth table0%0/3
A || B
A= $participant->wild->{'coordinator'}B= $participant->wild->{'conjunct'}
ABresult
1X1
011
000
801 # Recursion first. Someone must sort the grandchildren as participants vs. modifiers.
802 # Conjunction and conjunct require recursion. Aux nodes terminate it even if they have children.
803 0 ▶ my @partmodifiers = $recursive ? $self->detect_mosford($participant) : $participant->children();
Branch: 1 branch
BranchTrueFalseTotal
$recursive ? : 0 0 0
804 0 ▶ if($participant->wild()->{conjunct})
Branch: 1 branch
BranchTrueFalseTotal
if ($participant->wild->{'conjunct'}) { } 0 0 0
805 {
806 0 my $orphan = 0;
807 0 $self->add_conjunct($participant, $orphan, @partmodifiers);
808 }
809 else
810 {
811 # We cannot use get_real_afun() because the foreign data is not yet fully normalized (see above).
812 #my $afun = $participant->get_real_afun();
813 0 my $afun = $participant->afun();
814 0 my $symbol = $afun =~ m/^Aux[GX]$/;
815 0 $self->add_delimiter($participant, $symbol, @partmodifiers);
816 }
817 }
818 # If this is the top level, we now know all we can.
819 # It's time for a few more heuristics.
820 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
821 {
822 0 $self->reconsider_distant_private_modifiers();
823 }
824 # Return the list of modifiers to the upper level.
825 # They will need it when they add me as a participant.
826 0 ▶ unless($top)
Branch: 1 branch
BranchTrueFalseTotal
unless ($top) 0 0 0
827 {
828 0 return @modifiers;
829 }
830 }
831  
832  
833  
834 #------------------------------------------------------------------------------
835 # Detects coordination structure according to current annotation (dependency
836 # links between nodes and labels of the relations). Expects left-to-right
837 # Moscow style with conjunctions and commas attached to the following conjunct.
838 # This style allows limited representation of nested coordination. It cannot
839 # distinguish (A,(B,C)) from (A,B,C). Having nested coordination as the
840 # last conjunct is a problem. Example treebank is Swedish. (Note however that
841 # the Swedish treebank distinguishes conjunct labels CJ and CC. We do not
842 # understand the difference and convert both to CoordArg. They may be able to
843 # describe nested coordination in full!)
844 # - the root of the coordination is not marked
845 # - conjuncts have wild->{conjunct}
846 # (the afun 'CoordArg' may have not survived normalization)
847 # - if a conjunct has two or more conjuncts as children, there is nested
848 # coordination. The parent conjunct first combines with the first child
849 # conjunct (and its descendants, if any). The resulting coordination is a
850 # conjunct that combines with the next child conjunct (and its descendants).
851 # The process goes on until all child conjuncts are processed.
852 # - conjunctions have wild->{coordinator}
853 # (the afun 'Coord' may have not survived normalization)
854 # Any such child of a conjunct is collected; no conjuncts are expected under
855 # it.
856 # - punctuation lying to the left of a conjunct and attached to it is
857 # considered delimiter
858 # - all other children along the way are private modifiers
859 # The method assumes that nothing has been normalized yet. In particular it
860 # assumes that there are no AuxP/AuxC afuns (there are PrepArg/SubArg instead).
861 # Thus the method does not call $node->set/get_real_afun().
862 #------------------------------------------------------------------------------
863 sub detect_moscow
864 {
865 0 ▶ my $self = shift;
Subroutine detect_moscow: not called CC=21 SCAR=61.4
Pod undocumented
866 0 my $node = shift; # suspected root node of coordination
867 0 my $nontop = shift; # other than top level of recursion?
868 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
869 0 my $top = !$nontop;
870 ###!!!DEBUG
871 0 my $debug = 0;
872 0 ▶ if($debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
873 {
874 0 my $form = $node->form();
875 0 ▶ $form = '' if(!defined($form));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 0 0 0
876 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) { } 0 0 0
877 {
878 0 $node->set_form("T:$form");
879 }
880 else
881 {
882 0 $node->set_form("X:$form");
883 }
884 }
885 ###!!!END
886 0 my @children = $node->children();
887 0 my @conjuncts = grep {$_->wild()->{conjunct}} @children;
888 0 my $bottom = scalar(@conjuncts)==0;
889 0 ▶ if($top && $bottom)
Branch: 1 branch
BranchTrueFalseTotal
if ($top and $bottom) 0 0 0
Condition0%0/3
$top and $bottom
!ll&&!rl&&r
000
MC/DC0%0/2
$top and $bottom
$top $bottom
Truth table0%0/3
A and B
A= $topB= $bottom
ABresult
0X0
100
111
890 {
891 # No participants found. This $node is not a root of coordination.
892 # (We do not expect delimiters under a node that is not a conjunct (first or not).)
893 0 return;
894 }
895 # Even if there are no conjuncts and no recursion ($bottom) there may be delimiters which we have to add.
896 0 my @delimiters = map {$_->wild()->{is_coord_delimiter} = 1; $_} grep
897 {
898 0 ! $_->wild()->{conjunct} &&
899 # Very rarely (and probably erroneously) a conjunction is attached to the left.
900 # Ignoring it here would mean that it keeps the Coord afun without actually heading a coordination.
901 # The issue does not affect punctuation.
902 (
903 $_->wild()->{coordinator} ||
904 0 ▶ $_->afun() =~ m/^Aux[GXY]$/ &&
Branch: 1 branch
BranchTrueFalseTotal
not $_->wild->{"conjunct"} and $_->wild->{"coordinator"} || $_->afun =~ /^Aux[GXY]$/ && $_->ord < $node->ord 0 0 0
Condition0%0/9
!$_->wild->{'conjunct'} && ($_->wild->{'coordinator'} || $_->afun =~ /^Aux[GXY]$/ && $_->ord < $node->ord)
!ll&&!rl&&r
000
$_->wild->{"coordinator"} or $_->afun =~ /^Aux[GXY]$/ and $_->ord < $node->ord
l!l&&r!l&&!r
000
$_->afun =~ /^Aux[GXY]$/ and $_->ord < $node->ord
!ll&&!rl&&r
000
MC/DC0%0/4
!$_->wild->{'conjunct'} && ($_->wild->{'coordinator'} || $_->afun =~ /^Aux[GXY]$/ && $_->ord < $node->ord)
!$_->wild->{'conjunct'} $_->wild->{"coordinator"} $_->afun =~ /^Aux[GXY]$/ $_->ord < $node->ord
Truth table0%0/5
not(A) && B or C and D
A= !$_->wild->{'conjunct'}B= $_->wild->{"coordinator"}C= $_->afun =~ /^Aux[GXY]$/D= $_->ord < $node->ord
ABCDresult
0XXX0
100X0
10100
11XX1
10111
905 $_->ord() < $node->ord()
906 )
907 }
908 @children;
909 # Some commas may still have not been recognized as delimiters.
910 # Comma that is the left neighbor of a conjunct or a delimiter (", and") is also a delimiter.
911 0 foreach my $node (@conjuncts, @delimiters)
912 {
913 0 my $left = $node->get_left_neighbor();
914 0 ▶ if($left && !$left->wild()->{is_coord_delimiter} && $left->afun() =~ m/^Aux[GX]$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($left and not $left->wild->{"is_coord_delimiter"} and $left->afun =~ /^Aux[GX]$/) 0 0 0
Condition0%0/6
$left and not $left->wild->{"is_coord_delimiter"} and $left->afun =~ /^Aux[GX]$/
!ll&&!rl&&r
000
$left and not $left->wild->{"is_coord_delimiter"}
!ll&&!rl&&r
000
MC/DC0%0/3
$left and not $left->wild->{"is_coord_delimiter"} and $left->afun =~ /^Aux[GX]$/
$left not $left->wild->{"is_coord_delimiter"} $left->afun =~ /^Aux[GX]$/
Truth table0%0/4
A and not(B) and C
A= $leftB= not $left->wild->{"is_coord_delimiter"}C= $left->afun =~ /^Aux[GX]$/
ABCresult
0XX0
10X0
1100
1111
915 {
916 0 push(@delimiters, $left);
917 0 $left->wild()->{is_coord_delimiter} = 1;
918 }
919 }
920 my @modifiers = grep
921 {
922 0 ! $_->wild()->{conjunct} &&
923 ! $_->wild()->{is_coord_delimiter}
924 0 ▶ }
Condition0%0/3
$_->wild->{'conjunct'} || $_->wild->{'is_coord_delimiter'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->wild->{'conjunct'} || $_->wild->{'is_coord_delimiter'}
$_->wild->{'conjunct'} $_->wild->{'is_coord_delimiter'}
Truth table0%0/3
A || B
A= $_->wild->{'conjunct'}B= $_->wild->{'is_coord_delimiter'}
ABresult
1X1
011
000
925 @children;
926 # If we are here we have participants: either conjuncts or delimiters or both.
927 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
928 {
929 # Add the root conjunct.
930 # Note: root of the tree is never a conjunct! If this is the tree root, we are dealing with a deficient (probably clausal) coordination.
931 0 ▶ unless($node->is_root())
Branch: 1 branch
BranchTrueFalseTotal
if ($node->is_root) { } 0 0 0
932 {
933 0 my $orphan = 0;
934 0 $self->add_conjunct($node, $orphan, @modifiers);
935 # Save the relation of the coordination to its parent.
936 0 $self->set_parent($node->parent());
937 0 $self->set_afun($node->afun());
938 0 $self->set_is_member($node->is_member());
939 }
940 else
941 {
942 ###!!! The coordination still needs to know its parent (the root) and afun (which we are guessing here but we should find a real conjunct instead).
943 0 $self->set_parent($node);
944 0 $self->set_afun('Pred');
945 0 $self->set_is_member(0);
946 }
947 }
948 ###!!! POZOR! Když to zůstane takhle, budeme rozpouštět vnořené koordinace!
949 ###!!! Je potřeba zjistit, zda máme více než jedno dítě, které je členem koordinace.
950 ###!!! Dokud máme dvě nebo více takových dětí, je třeba se spojit s prvním z nich a vytvořit vnořenou koordinaci.
951 ###!!! To znamená nový objekt Coordination, kompletní běh detect_moscow(), potom asi už i shape_prague() a novým kořenem si nahradit náš člen.
952 ###!!! Další obtíž se skrývá v tom, že nás pravděpodobně zavolal někdo, kdo chce postupně rozpoznat všechny koordinace ve větě.
953 ###!!! Čili jednak je tu disproporce, protože pro nevnořené koordinace si shape_prague() volá ten někdo sám.
954 ###!!! A za druhé ten někdo chce pak detekci zavolat také na všechna rozvití (sdílená i soukromá) a všechny sirotky té koordinace, kterou mu vrátíme.
955 ###!!! OTÁZKA: Vnořená koordinace má svá sdílená i soukromá rozvití. Dostaneme opravdu všechna do seznamu soukromých rozvití člena, který je tvořen vnořenou koordinací?
956 0 foreach my $conjunct (@conjuncts)
957 {
958 0 my $orphan = 0;
959 0 my $nontop = 1;
960 0 my @partmodifiers = $self->detect_moscow($conjunct, $nontop);
961 0 $self->add_conjunct($conjunct, $orphan, @partmodifiers);
962 }
963 0 foreach my $delimiter (@delimiters)
964 {
965 0 my $symbol = $delimiter->afun() =~ m/^Aux[GX]$/;
966 0 my @partmodifiers = $delimiter->children();
967 0 $self->add_delimiter($delimiter, $symbol, @partmodifiers);
968 }
969 # If this is the top level, we now know all we can.
970 # It's time for a few more heuristics.
971 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
972 {
973 0 $self->reconsider_distant_private_modifiers();
974 }
975 # Return the list of modifiers to the upper level.
976 # They will need it when they add me as a participant.
977 0 ▶ unless($top)
Branch: 1 branch
BranchTrueFalseTotal
unless ($top) 0 0 0
978 {
979 0 return @modifiers;
980 }
981 }
982  
983  
984  
985 #------------------------------------------------------------------------------
986 # Detects coordination structure according to current annotation (dependency
987 # links between nodes and labels of the relations). Expects left-to-right
988 # Moscow style. Conjunction is on the path between two conjuncts. Punctuation
989 # might be attached sidewise to conjuncts but there are no punctuation nodes in
990 # the Russian treebank. This style allows limited representation of nested
991 # coordination. It cannot distinguish (A,(B,C)) from (A,B,C). Having nested
992 # coordination as the last conjunct is a problem. Example treebank is Russian.
993 # - the root of the coordination is not marked
994 # - conjuncts have wild->{conjunct}
995 # (the afun 'CoordArg' may have not survived normalization)
996 # non-first conjunct is attached to previous conjunct or conjunction
997 # - conjunctions have wild->{coordinator}
998 # (the afun 'Coord' may have not survived normalization)
999 # conjunction is attached to previous conjunct
1000 # - if a conjunct has two or more children that are either conjunctions or
1001 # conjuncts, there is nested coordination. The parent conjunct first combines
1002 # with the first child (and its descendants, if any). The resulting
1003 # coordination is a conjunct that combines with the next child (and its
1004 # descendants). The process goes on until all child conjuncts are processed.
1005 # - punctuation lying to the left of a conjunct and attached to it is
1006 # considered delimiter
1007 # - all other children along the way are private modifiers
1008 # The method assumes that nothing has been normalized yet. In particular it
1009 # assumes that there are no AuxP/AuxC afuns (there are PrepArg/SubArg instead).
1010 # Thus the method does not call $node->set/get_real_afun().
1011 #------------------------------------------------------------------------------
1012 sub detect_moscow2
1013 {
1014 0 ▶ my $self = shift;
Subroutine detect_moscow2: not called CC=15 SCAR=54.8
Pod undocumented
1015 0 my $node = shift; # suspected root node of coordination
1016 0 my $nontop = shift; # other than top level of recursion?
1017 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
1018 0 my $top = !$nontop;
1019 ###!!!DEBUG
1020 0 my $debug = 0;
1021 0 ▶ if($debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
1022 {
1023 0 my $form = $node->form();
1024 0 ▶ $form = '' if(!defined($form));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 0 0 0
1025 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) { } 0 0 0
1026 {
1027 0 $node->set_form("T:$form");
1028 }
1029 else
1030 {
1031 0 $node->set_form("X:$form");
1032 }
1033 }
1034 ###!!!END
1035 0 my @children = $node->children();
1036 0 my @conjuncts = grep {$_->wild()->{conjunct}} @children;
1037 0 my @delimiters = grep {$_->wild()->{coordinator}} @children;
1038 0 my @conodes = (@conjuncts, @delimiters);
1039 0 my $bottom = scalar(@conodes)==0;
1040 0 ▶ if($top && $bottom)
Branch: 1 branch
BranchTrueFalseTotal
if ($top and $bottom) 0 0 0
Condition0%0/3
$top and $bottom
!ll&&!rl&&r
000
MC/DC0%0/2
$top and $bottom
$top $bottom
Truth table0%0/3
A and B
A= $topB= $bottom
ABresult
0X0
100
111
1041 {
1042 # No participants found. This $node is not a root of coordination.
1043 # (We do not expect delimiters under a node that is not a conjunct (first or not).)
1044 0 return;
1045 }
1046 my @modifiers = grep
1047 {
1048 0 ! $_->wild()->{conjunct} &&
1049 ! $_->wild()->{coordinator} &&
1050 ! $_->wild()->{is_coord_delimiter}
1051 0 ▶ }
Condition0%0/6
$_->wild->{'conjunct'} || $_->wild->{'coordinator'} || $_->wild->{'is_coord_delimiter'}
l!l&&r!l&&!r
000
$_->wild->{"conjunct"} or $_->wild->{"coordinator"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->wild->{'conjunct'} || $_->wild->{'coordinator'} || $_->wild->{'is_coord_delimiter'}
$_->wild->{"conjunct"} $_->wild->{"coordinator"} $_->wild->{'is_coord_delimiter'}
Truth table0%0/4
A or B || C
A= $_->wild->{"conjunct"}B= $_->wild->{"coordinator"}C= $_->wild->{'is_coord_delimiter'}
ABCresult
1XX1
01X1
0011
0000
1052 @children;
1053 # If we are here we have participants: either conjuncts or delimiters or both.
1054 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
1055 {
1056 # Add the root conjunct.
1057 # Note: root of the tree is never a conjunct! If this is the tree root, we are dealing with a deficient (probably clausal) coordination.
1058 0 ▶ unless($node->is_root())
Branch: 1 branch
BranchTrueFalseTotal
if ($node->is_root) { } 0 0 0
1059 {
1060 0 my $orphan = 0;
1061 0 $self->add_conjunct($node, $orphan, @modifiers);
1062 # Save the relation of the coordination to its parent.
1063 0 $self->set_parent($node->parent());
1064 0 $self->set_afun($node->afun());
1065 0 $self->set_is_member($node->is_member());
1066 }
1067 else
1068 {
1069 ###!!! The coordination still needs to know its parent (the root) and afun (which we are guessing here but we should find a real conjunct instead).
1070 0 $self->set_parent($node);
1071 0 $self->set_afun('Pred');
1072 0 $self->set_is_member(0);
1073 }
1074 }
1075 # If two or more children are conjunctions or conjuncts, we have a nested coordination.
1076 ###!!! POZOR! Když to zůstane takhle, budeme rozpouštět vnořené koordinace!
1077 ###!!! Je potřeba zjistit, zda máme více než jedno dítě, které je členem koordinace.
1078 ###!!! Dokud máme dvě nebo více takových dětí, je třeba se spojit s prvním z nich a vytvořit vnořenou koordinaci.
1079 ###!!! To znamená nový objekt Coordination, kompletní běh detect_moscow2(), potom asi už i shape_prague() a novým kořenem si nahradit náš člen.
1080 ###!!! Další obtíž se skrývá v tom, že nás pravděpodobně zavolal někdo, kdo chce postupně rozpoznat všechny koordinace ve větě.
1081 ###!!! Čili jednak je tu disproporce, protože pro nevnořené koordinace si shape_prague() volá ten někdo sám.
1082 ###!!! A za druhé ten někdo chce pak detekci zavolat také na všechna rozvití (sdílená i soukromá) a všechny sirotky té koordinace, kterou mu vrátíme.
1083 ###!!! OTÁZKA: Vnořená koordinace má svá sdílená i soukromá rozvití. Dostaneme opravdu všechna do seznamu soukromých rozvití člena, který je tvořen vnořenou koordinací?
1084 0 foreach my $conode (@conodes)
1085 {
1086 0 my $nontop = 1;
1087 0 my @partmodifiers = $self->detect_moscow2($conode, $nontop);
1088 0 ▶ if($conode->wild()->{conjunct})
Branch: 1 branch
BranchTrueFalseTotal
if ($conode->wild->{'conjunct'}) { } 0 0 0
1089 {
1090 0 my $orphan = 0;
1091 0 $self->add_conjunct($conode, $orphan, @partmodifiers);
1092 }
1093 else # conjunction
1094 {
1095 0 my $symbol = 0;
1096 0 $self->add_delimiter($conode, $symbol, @partmodifiers);
1097 }
1098 }
1099 # If this is the top level, we now know all we can.
1100 # It's time for a few more heuristics.
1101 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
1102 {
1103 0 $self->reconsider_distant_private_modifiers();
1104 }
1105 # Return the list of modifiers to the upper level.
1106 # They will need it when they add me as a participant.
1107 0 ▶ unless($top)
Branch: 1 branch
BranchTrueFalseTotal
unless ($top) 0 0 0
1108 {
1109 0 return @modifiers;
1110 }
1111 }
1112  
1113  
1114  
1115 #------------------------------------------------------------------------------
1116 # Detects coordination structure according to current annotation (dependency
1117 # links between nodes and labels of the relations). Expects right-to-left
1118 # Moscow style. Coordinator (conjunction or comma) is on the path between two
1119 # conjuncts. This style allows limited representation of nested coordination.
1120 # It cannot distinguish ((A,B),C) from (A,B,C). Having nested coordination as
1121 # the first conjunct is a problem. Example treebank is Turkish (METU/ODTÜ).
1122 # - the root of the coordination is not marked
1123 # - coordinators (either conjunctions or commas) have wild->{coordinator}
1124 # (the afun 'Coord' may have not survived normalization)
1125 # coordinator is attached to the next conjunct
1126 # - conjuncts are not specifically marked but they can be recognized via their
1127 # attachment: every conjunct is attached to the following coordinator
1128 # the last conjunct is the head of the coordination
1129 # all conjuncts have the same afun: that of the whole coordination
1130 # - if a conjunct has two or more children that are coordinators, there is
1131 # nested coordination. The parent conjunct first combines with the last child
1132 # (and its descendants, if any). The resulting coordination is a conjunct
1133 # that combines with the previous child (and its descendants). The process
1134 # goes on until all child conjuncts are processed.
1135 # - all other children along the way are private modifiers
1136 # The method assumes that nothing has been normalized yet. In particular it
1137 # assumes that there are no AuxP/AuxC afuns (there are PrepArg/SubArg instead).
1138 # Thus the method does not call $node->set/get_real_afun().
1139 #------------------------------------------------------------------------------
1140 sub detect_ankara
1141 {
1142 0 ▶ my $self = shift;
Subroutine detect_ankara: not called CC=15 SCAR=54.8
Pod undocumented
1143 0 my $node = shift; # suspected root node of coordination
1144 0 my $nontop = shift; # other than top level of recursion?
1145 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
1146 0 my $top = !$nontop;
1147 ###!!!DEBUG
1148 0 my $debug = 0;
1149 0 ▶ if($debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
1150 {
1151 0 my $form = $node->form();
1152 0 ▶ $form = '' if(!defined($form));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 0 0 0
1153 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) { } 0 0 0
1154 {
1155 0 $node->set_form("T:$form");
1156 }
1157 else
1158 {
1159 0 $node->set_form("X:$form");
1160 }
1161 }
1162 ###!!!END
1163 0 my @children = $node->children();
1164 0 my @conjuncts;
1165 my @delimiters;
1166 0 my $bottom;
1167 # If this is a coordinator, we expect exactly one child: the previous conjunct.
1168 0 ▶ if($node->wild()->{coordinator})
Branch: 1 branch
BranchTrueFalseTotal
if ($node->wild->{'coordinator'}) { } 0 0 0
1169 {
1170 0 my $nc = scalar(@children);
1171 ###!!! There are 2662 nodes in the METU-Sabanci treebank labeled as COORDINATION.
1172 ###!!! Out of this number, 228 have other number of children than 1.
1173 ###!!! Among them are the two-word conjunctions ya-ya (either-or) and ne-ne (neither-nor).
1174 ###!!! The first word of the conjunction should be attached at the end of the chain as a leaf and labeled COORDINATION.
1175 ###!!! The other cases are annotation errors. Sometimes the conjunction is attached sidewise of the chain.
1176 ###!!! Sometimes a conjunction has two conjunct children (in addition to the one conjunct parent).
1177 ###!!! Sometimes conjunction has two children but only one is conjunct (e.g. SENTENCE) while the other has different label (e.g. S.MODIFIER).
1178 ###!!! Sometimes the DERIV empty nodes are included in the chain and we have to go further to find the real label.
1179 ###!!! Sometimes the ROOT node (usually the final punctuation) also heads a coordination of SENTENCE nodes.
1180 ###!!! Etc. etc. Some of the errors can be caught here, others will result in weird structrues.
1181 ###!!! We leave it for future work. One just cannot expect non-weird output when input is weird.
1182 #log_warn("Expected 1 child of coordinator, found $nc. ".$node->get_address()) if($nc!=1);
1183 0 @conjuncts = @children;
1184 0 $bottom = $nc==0;
1185 }
1186 else # not coordinator
1187 {
1188 # Are there any coordinators among the children?
1189 0 @delimiters = grep {$_->wild()->{coordinator}} @children;
1190 0 $bottom = scalar(@delimiters)==0;
1191 }
1192 0 ▶ if($top && $bottom)
Branch: 1 branch
BranchTrueFalseTotal
if ($top and $bottom) 0 0 0
Condition0%0/3
$top and $bottom
!ll&&!rl&&r
000
MC/DC0%0/2
$top and $bottom
$top $bottom
Truth table0%0/3
A and B
A= $topB= $bottom
ABresult
0X0
100
111
1193 {
1194 # No participants found. This $node is not a root of coordination.
1195 0 return;
1196 }
1197 0 my @modifiers;
1198 # We can find modifiers attached to a conjunct but not to a coordinator.
1199 0 ▶ unless($node->wild()->{coordinator})
Branch: 1 branch
BranchTrueFalseTotal
unless ($node->wild->{"coordinator"}) 0 0 0
1200 {
1201 0 @modifiers = grep {!$_->wild()->{coordinator}} @children;
1202 }
1203 # If we are here we have participants: either conjuncts or delimiters or both.
1204 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
1205 {
1206 # Add the root conjunct.
1207 # Note: root of the tree is never a conjunct! If this is the tree root, we are dealing with a deficient (probably clausal) coordination.
1208 0 ▶ unless($node->is_root())
Branch: 1 branch
BranchTrueFalseTotal
if ($node->is_root) { } 0 0 0
1209 {
1210 0 my $orphan = 0;
1211 0 $self->add_conjunct($node, $orphan, @modifiers);
1212 # Save the relation of the coordination to its parent.
1213 0 $self->set_parent($node->parent());
1214 0 $self->set_afun($node->afun());
1215 0 $self->set_is_member($node->is_member());
1216 }
1217 else
1218 {
1219 ###!!! The coordination still needs to know its parent (the root) and afun (which we are guessing here but we should find a real conjunct instead).
1220 0 $self->set_parent($node);
1221 0 $self->set_afun('Pred');
1222 0 $self->set_is_member(0);
1223 }
1224 }
1225 # If two or more children are conjunctions or conjuncts, we have a nested coordination.
1226 ###!!! POZOR! Když to zůstane takhle, budeme rozpouštět vnořené koordinace!
1227 ###!!! Je potřeba zjistit, zda máme více než jedno dítě, které je členem koordinace.
1228 ###!!! Dokud máme dvě nebo více takových dětí, je třeba se spojit s prvním z nich a vytvořit vnořenou koordinaci.
1229 ###!!! To znamená nový objekt Coordination, kompletní běh detect_moscow2(), potom asi už i shape_prague() a novým kořenem si nahradit náš člen.
1230 ###!!! Další obtíž se skrývá v tom, že nás pravděpodobně zavolal někdo, kdo chce postupně rozpoznat všechny koordinace ve větě.
1231 ###!!! Čili jednak je tu disproporce, protože pro nevnořené koordinace si shape_prague() volá ten někdo sám.
1232 ###!!! A za druhé ten někdo chce pak detekci zavolat také na všechna rozvití (sdílená i soukromá) a všechny sirotky té koordinace, kterou mu vrátíme.
1233 ###!!! OTÁZKA: Vnořená koordinace má svá sdílená i soukromá rozvití. Dostaneme opravdu všechna do seznamu soukromých rozvití člena, který je tvořen vnořenou koordinací?
1234 0 foreach my $conjunct (@conjuncts)
1235 {
1236 0 my $nontop = 1;
1237 0 my @partmodifiers = $self->detect_ankara($conjunct, $nontop);
1238 0 my $orphan = 0;
1239 0 $self->add_conjunct($conjunct, $orphan, @partmodifiers);
1240 }
1241 0 foreach my $delimiter (@delimiters)
1242 {
1243 0 my $nontop = 1;
1244 0 my @partmodifiers = $self->detect_ankara($delimiter, $nontop);
1245 0 my $symbol = $delimiter->afun() =~ m/^Aux[XG]$/;
1246 0 $self->add_delimiter($delimiter, $symbol, @partmodifiers);
1247 }
1248 # If this is the top level, we now know all we can.
1249 # It's time for a few more heuristics.
1250 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
1251 {
1252 0 $self->reconsider_distant_private_modifiers();
1253 }
1254 # Return the list of modifiers to the upper level.
1255 # They will need it when they add me as a participant.
1256 0 ▶ unless($top)
Branch: 1 branch
BranchTrueFalseTotal
unless ($top) 0 0 0
1257 {
1258 0 return @modifiers;
1259 }
1260 }
1261  
1262  
1263  
1264 #------------------------------------------------------------------------------
1265 # Detects coordination structure according to current annotation (dependency
1266 # links between nodes and labels of the relations). Expects left-to-right
1267 # Stanford style.
1268 # This style allows limited representation of nested coordination. It cannot
1269 # distinguish ((A,B),C) from (A,B,C). Having nested coordination as the first
1270 # conjunct is a problem. Example treebank is Bulgarian.
1271 # - the root of the coordination is not marked
1272 # - conjuncts have wild->{conjunct}
1273 # (the afun 'CoordArg' may have not survived normalization)
1274 # - conjunctions have wild->{coordinator}
1275 # (the afun 'Coord' may have not survived normalization)
1276 # - punctuation lying to the left of a conjunct and attached to the first
1277 # conjunct is considered delimiter
1278 # - the second and any consequent conjuncts, as well as all conjunctions and
1279 # conjunct-delimiting punctuation are attached to the first conjunct.
1280 # There is no recursion. If a non-first conjunct has a child that is also
1281 # conjunct, then there is nested coordination.
1282 # - all other children of the first conjunct are its private modifiers
1283 # The method assumes that nothing has been normalized yet. In particular it
1284 # assumes that there are no AuxP/AuxC afuns (there are PrepArg/SubArg instead).
1285 # Thus the method does not call $node->set/get_real_afun().
1286 #------------------------------------------------------------------------------
1287 sub detect_stanford
1288 {
1289 0 ▶ my $self = shift;
Subroutine detect_stanford: not called CC=18 SCAR=58.3
Pod undocumented
1290 0 my $node = shift; # suspected root node of coordination
1291 0 my $nontop = shift; # other than top level of recursion?
1292 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
1293 0 my $top = !$nontop;
1294 ###!!!DEBUG
1295 0 my $debug = 0;
1296 0 ▶ if($debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
1297 {
1298 0 my $form = $node->form();
1299 0 ▶ $form = '' if(!defined($form));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 0 0 0
1300 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) { } 0 0 0
1301 {
1302 0 $node->set_form("T:$form");
1303 }
1304 else
1305 {
1306 0 $node->set_form("X:$form");
1307 }
1308 }
1309 ###!!!END
1310 0 my @children = $node->children();
1311 0 my @conjuncts = grep {$_->wild()->{conjunct}} @children;
1312 0 my $bottom = scalar(@conjuncts)==0;
1313 0 ▶ if($bottom)
Branch: 1 branch
BranchTrueFalseTotal
if ($bottom) 0 0 0
1314 {
1315 # No conjuncts found, so we do not look for delimiters.
1316 0 return;
1317 }
1318 # Delimiting conjunctions are attached at the same level as conjuncts.
1319 # Distinguish delimiting form non-delimiting punctuation.
1320 0 foreach my $child (@children)
1321 {
1322 0 ▶ if($child->get_iset('pos') eq 'punc')
Branch: 1 branch
BranchTrueFalseTotal
if ($child->get_iset("pos") eq "punc") 0 0 0
1323 {
1324 0 my $rsibling = $child->get_right_neighbor();
1325 ###!!! What if there is comma first, then quotation mark, then the conjunct?
1326 ###!!! In the end the quotation mark should be attached to the conjunct but now we are in the middle of the normalization process.
1327 0 ▶ if(defined($rsibling) && $rsibling->wild()->{conjunct})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rsibling and $rsibling->wild->{"conjunct"}) 0 0 0
Condition0%0/3
defined $rsibling and $rsibling->wild->{"conjunct"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rsibling and $rsibling->wild->{"conjunct"}
defined $rsibling $rsibling->wild->{"conjunct"}
Truth table0%0/3
A and B
A= defined $rsiblingB= $rsibling->wild->{"conjunct"}
ABresult
0X0
100
111
1328 {
1329 0 $child->wild()->{coordinator} = 1;
1330 }
1331 }
1332 }
1333 my @delimiters = grep
1334 {
1335 0 ! $_->wild()->{conjunct} &&
1336 $_->wild()->{coordinator}
1337 0 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
not $_->wild->{"conjunct"} and $_->wild->{"coordinator"} 0 0 0
1338 @children;
1339 my @modifiers = grep
1340 {
1341 0 ! $_->wild()->{conjunct} &&
1342 ! $_->wild()->{coordinator}
1343 0 ▶ }
Condition0%0/3
$_->wild->{'conjunct'} || $_->wild->{'coordinator'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->wild->{'conjunct'} || $_->wild->{'coordinator'}
$_->wild->{'conjunct'} $_->wild->{'coordinator'}
Truth table0%0/3
A || B
A= $_->wild->{'conjunct'}B= $_->wild->{'coordinator'}
ABresult
1X1
011
000
1344 @children;
1345 # If we are here we have conjuncts.
1346 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
1347 {
1348 # Add the head conjunct.
1349 # Note: root of the tree is never a conjunct! If this is the tree root, we are dealing with a deficient (probably clausal) coordination.
1350 0 ▶ unless($node->is_root())
Branch: 1 branch
BranchTrueFalseTotal
unless ($node->is_root) 0 0 0
1351 {
1352 0 my $orphan = 0;
1353 0 $self->add_conjunct($node, $orphan, @modifiers);
1354 # Save the relation of the coordination to its parent.
1355 0 $self->set_parent($node->parent());
1356 0 $self->set_afun($node->afun());
1357 0 $self->set_is_member($node->is_member());
1358 }
1359 }
1360 # Add all non-head conjuncts.
1361 0 foreach my $conjunct (@conjuncts)
1362 {
1363 0 my $orphan = 0;
1364 0 my @partmodifiers = $conjunct->children();
1365 0 $self->add_conjunct($conjunct, $orphan, @partmodifiers);
1366 }
1367 0 foreach my $delimiter (@delimiters)
1368 {
1369 0 my $symbol = $delimiter->afun() =~ m/^Aux[GX]$/;
1370 0 my @partmodifiers = $delimiter->children();
1371 0 $self->add_delimiter($delimiter, $symbol, @partmodifiers);
1372 }
1373 # If this is the top level, we now know all we can.
1374 # It's time for a few more heuristics.
1375 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
1376 {
1377 0 $self->reconsider_distant_private_modifiers();
1378 }
1379 # Return the list of modifiers to the upper level.
1380 # They will need it when they add me as a participant.
1381 0 ▶ unless($top)
Branch: 1 branch
BranchTrueFalseTotal
unless ($top) 0 0 0
1382 {
1383 0 return @modifiers;
1384 }
1385 }
1386  
1387  
1388  
1389 #------------------------------------------------------------------------------
1390 # Sets and labels parent-child relations between nodes so that they reflect the
1391 # roles of the nodes in coordination. Uses Stanford (Universal Dependencies)
1392 # style. Fills labels in the afun attribute, even though the required labels
1393 # are not defined in the Treex XML schema. Returns the head node.
1394 #------------------------------------------------------------------------------
1395 sub shape_stanford
1396 {
1397 0 ▶ my $self = shift;
Subroutine shape_stanford: not called CC=8 SCAR=42.8
Pod undocumented
1398 # There is no guarantee that we obtained ordered lists of members and delimiters.
1399 # They may have been added during tree traversal, which is not ordered linearly.
1400 0 my @conjuncts = sort {$a->ord() <=> $b->ord()} $self->get_conjuncts();
1401 0 my @shared_modifiers = $self->get_shared_modifiers();
1402 0 ▶ if ( scalar(@conjuncts)==0 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @conjuncts == 0) 0 0 0
1403 {
1404 # Give the user at least some pointer to the tree.
1405 0 ▶ log_warn($self->parent()) if(defined($self->parent()));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->parent 0 0 0
1406 0 log_fatal('Trying to shape an empty coordination (no conjuncts).');
1407 }
1408 # Select the first conjunct as the new root.
1409 0 my $croot = shift(@conjuncts);
1410 # Attach the new root to the parent of the coordination.
1411 0 $croot->set_parent($self->parent());
1412 0 $croot->set_afun($self->afun());
1413 0 $croot->set_is_member($self->is_member());
1414 # Attach all coordination members to the new root.
1415 0 foreach my $conjunct ( @conjuncts )
1416 {
1417 0 $conjunct->set_parent($croot);
1418 0 $conjunct->set_afun('conj');
1419 # The is_member attribute is not necessary in the Stanford style, non-first conjuncts will be recognized by the 'conj' dependency relation.
1420 # But we will set it anyway.
1421 0 $conjunct->set_is_member(1);
1422 }
1423 # Attach all delimiters to the new root.
1424 # We need the $symbol attribute, thus we cannot use @delimiters.
1425 0 ▶ my @otherdelim = grep {$_->{type} eq 'delimiter' && $_->{node}!=$croot} (@{$self->_get_participants()});
Branch: 1 branch
BranchTrueFalseTotal
$_->{"type"} eq "delimiter" and $_->{"node"} != $croot 0 0 0
1426 0 foreach my $delimrec ( @otherdelim )
1427 {
1428 0 my $delimiter = $delimrec->{node};
1429 0 my $symbol = $delimrec->{symbol};
1430 0 $delimiter->set_parent($croot);
1431 0 $delimiter->set_is_member(0);
1432 0 ▶ if ($symbol)
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol) { } 0 0 0
1433 {
1434 0 $delimiter->set_afun('punct');
1435 }
1436 else
1437 {
1438 0 $delimiter->set_afun('cc');
1439 # Martin's transformations might also need the flag whether a node is coordinating conjunction.
1440 0 $delimiter->wild()->{is_coord_conjunction} = 1;
1441 }
1442 }
1443 # Attach all shared modifiers to the new root.
1444 0 foreach my $modifier ( @shared_modifiers )
1445 {
1446 0 $modifier->set_parent($croot);
1447 0 $modifier->set_is_member(0);
1448 # This is much more important in the Stanford style than in the Prague style:
1449 # Distinguish shared modifiers of the coordination from private modifiers of the first conjunct.
1450 0 $modifier->set_is_shared_modifier(1);
1451 }
1452 0 return $croot;
1453 }
1454  
1455  
1456  
1457 #------------------------------------------------------------------------------
1458 # Detects coordination structure according to current annotation (dependency
1459 # links between nodes and labels of the relations). Expects Tesnière style as
1460 # it is found in the Szeged treebank. Nested coordination is not expected and
1461 # some instances may not be recognizable correctly.
1462 # - conjuncts, conjunctions and commas are separately attached to the parent of
1463 # the coordination
1464 # - no formal marking of conjuncts
1465 # - conjunctions have wild->{coordinator} ###!!!
1466 # The method assumes that nothing has been normalized yet. In particular it
1467 # assumes that there are no AuxP/AuxC afuns (there are PrepArg/SubArg instead).
1468 # Thus the method does not call $node->set/get_real_afun().
1469 #------------------------------------------------------------------------------
1470 sub detect_szeged
1471 {
1472 0 ▶ my $self = shift;
Subroutine detect_szeged: not called CC=30 SCAR=68.4
Pod undocumented
1473 0 my $node = shift; # suspected root node of coordination
1474 # $nontop is mentioned for reasons of compatibility with other detection functions.
1475 # It is not really needed here as there will be no recursion.
1476 0 my $nontop = shift; # other than top level of recursion?
1477 0 ▶ log_fatal("Missing node") unless(defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
1478 0 my $top = !$nontop;
1479 ###!!!DEBUG
1480 0 my $debug = 0;
1481 0 ▶ if($debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
1482 {
1483 0 my $form = $node->form();
1484 0 ▶ $form = '' if(!defined($form));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 0 0 0
1485 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) { } 0 0 0
1486 {
1487 0 $node->set_form("T:$form");
1488 }
1489 else
1490 {
1491 0 $node->set_form("X:$form");
1492 }
1493 }
1494 ###!!!END
1495 # Looking for Tesnièrian coordination starts at the conjunction.
1496 # Once we see a conjunction we look at its siblings and check whether they have matching dependency labels.
1497 0 ▶ return unless($node->wild()->{coordinator});
Branch: 1 branch
BranchTrueFalseTotal
unless $node->wild->{"coordinator"} 0 0 0
1498 0 my @punctuation;
1499 0 my $lsibling = skip_commas($node->get_left_neighbor(), 'left', \@punctuation);
1500 0 my $rsibling = skip_commas($node->get_right_neighbor(), 'right', \@punctuation);
1501 0 ▶ if($lsibling && $rsibling && $lsibling->afun() eq $rsibling->afun() && $lsibling->afun() ne 'Coord')
Branch: 2 branches
BranchTrueFalseTotal
if ($lsibling and $rsibling and $lsibling->afun eq $rsibling->afun and $lsibling->afun ne 'Coord') { } 0 0 0
elsif ($node->ord == 1 and defined $node->parent and defined $node->parent->parent and $node->parent->parent->is_root) { } 0 0 0
Condition0%0/9
$lsibling and $rsibling and $lsibling->afun eq $rsibling->afun and $lsibling->afun ne "Coord"
!ll&&!rl&&r
000
$lsibling and $rsibling and $lsibling->afun eq $rsibling->afun
!ll&&!rl&&r
000
$lsibling and $rsibling
!ll&&!rl&&r
000
MC/DC0%0/4
$lsibling and $rsibling and $lsibling->afun eq $rsibling->afun and $lsibling->afun ne "Coord"
$lsibling $rsibling $lsibling->afun eq $rsibling->afun $lsibling->afun ne "Coord"
Truth table0%0/5
A and B and C and D
A= $lsiblingB= $rsiblingC= $lsibling->afun eq $rsibling->afunD= $lsibling->afun ne "Coord"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1502 {
1503 # We have found a conjunction and two conjuncts around it.
1504 # Let's add them to the coordination.
1505 0 my $symbol = 0;
1506 0 my @partmodifiers = $node->children();
1507 0 $self->add_delimiter($node, $symbol, @partmodifiers);
1508 0 my $orphan = 0;
1509 0 foreach my $conjunct ($lsibling, $rsibling)
1510 {
1511 0 my @partmodifiers = $conjunct->children();
1512 0 $self->add_conjunct($conjunct, $orphan, @partmodifiers);
1513 }
1514 # Save the skipped commas (and possibly other punctuation).
1515 0 $symbol = 1;
1516 0 foreach my $delimiter (@punctuation)
1517 {
1518 # Hopefully the comma has no children but just in case.
1519 0 my @partmodifiers = $delimiter->children();
1520 0 $self->add_delimiter($delimiter, $symbol, @partmodifiers);
1521 }
1522 # Save the relation of the coordination to its parent.
1523 0 $self->set_parent($node->parent());
1524 0 $self->set_afun($lsibling->afun());
1525 0 $self->set_is_member($node->is_member());
1526 # Are there additional conjuncts to the left, separated by punctuation?
1527 0 my @candidates = $lsibling->get_siblings({preceding_only => 1});
1528 0 ▶ while(scalar(@candidates)>=2)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @candidates >= 2) 0 0 0
1529 {
1530 0 my $comma = pop(@candidates);
1531 0 my $conjunct = pop(@candidates);
1532 0 ▶ if($comma->form() =~ m/^[,;:—]$/ && $conjunct->afun() eq $lsibling->afun() && !$comma->is_member() && !$conjunct->is_member())
Branch: 1 branch
BranchTrueFalseTotal
if ($comma->form =~ /^[,;:\x{2014}]$/ and $conjunct->afun eq $lsibling->afun and not $comma->is_member and not $conjunct->is_member) { } 0 0 0
Condition0%0/9
$comma->form =~ /^[,;:\x{2014}]$/ and $conjunct->afun eq $lsibling->afun and not $comma->is_member and not $conjunct->is_member
!ll&&!rl&&r
000
$comma->form =~ /^[,;:\x{2014}]$/ and $conjunct->afun eq $lsibling->afun and not $comma->is_member
!ll&&!rl&&r
000
$comma->form =~ /^[,;:\x{2014}]$/ and $conjunct->afun eq $lsibling->afun
!ll&&!rl&&r
000
MC/DC0%0/4
$comma->form =~ /^[,;:\x{2014}]$/ and $conjunct->afun eq $lsibling->afun and not $comma->is_member and not $conjunct->is_member
$comma->form =~ /^[,;:\x{2014}]$/ $conjunct->afun eq $lsibling->afun not $comma->is_member not $conjunct->is_member
Truth table0%0/5
A and B and not(C) and not(D)
A= $comma->form =~ /^[,;:\x{2014}]$/B= $conjunct->afun eq $lsibling->afunC= not $comma->is_memberD= not $conjunct->is_member
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1533 {
1534 # Hopefully the comma has no children but just in case.
1535 0 my @partmodifiers = $comma->children();
1536 0 $self->add_delimiter($comma, 1, @partmodifiers);
1537 0 @partmodifiers = $conjunct->children();
1538 0 $self->add_conjunct($conjunct, 0, @partmodifiers);
1539 }
1540 else
1541 {
1542 0 last;
1543 }
1544 }
1545 }
1546 ▶ elsif($node->ord()==1 && defined($node->parent()) && defined($node->parent()->parent()) && $node->parent()->parent()->is_root())
Condition0%0/9
$node->ord == 1 and defined $node->parent and defined $node->parent->parent and $node->parent->parent->is_root
!ll&&!rl&&r
000
$node->ord == 1 and defined $node->parent and defined $node->parent->parent
!ll&&!rl&&r
000
$node->ord == 1 and defined $node->parent
!ll&&!rl&&r
000
MC/DC0%0/4
$node->ord == 1 and defined $node->parent and defined $node->parent->parent and $node->parent->parent->is_root
$node->ord == 1 defined $node->parent defined $node->parent->parent $node->parent->parent->is_root
Truth table0%0/5
A and B and C and D
A= $node->ord == 1B= defined $node->parentC= defined $node->parent->parentD= $node->parent->parent->is_root
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1547 {
1548 # Deficient (single-conjunct) sentence coordination.
1549 0 my $conjunct = $node->parent();
1550 0 my $root = $conjunct->parent();
1551 0 $self->set_parent($root);
1552 0 $self->set_afun($conjunct->afun());
1553 0 $self->set_is_member(undef);
1554 0 $self->add_delimiter($node, 0, $node->children());
1555 0 $self->add_conjunct($conjunct, 0, grep {$_!=$node} ($conjunct->children()));
1556 }
1557 else
1558 {
1559 # The Szeged treebank is not always strictly Tesnièrian with respect to coordination.
1560 # Some cases (especially coordinate main predicates) are analyzed as shallow Prague-like structures, i.e. conjunction heads the predicates.
1561 # If we failed using the conditions above, perhaps we are dealing with this sort of coordinate structure.
1562 0 ▶ my (@left_conjuncts) = grep {!$_->is_punctuation() && $_->precedes($node)} $node->children();
Branch: 1 branch
BranchTrueFalseTotal
not $_->is_punctuation and $_->precedes($node) 0 0 0
1563 0 ▶ my (@right_conjuncts) = grep {!$_->is_punctuation() && !$_->precedes($node)} $node->children();
Condition0%0/3
$_->is_punctuation || $_->precedes($node)
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->is_punctuation || $_->precedes($node)
$_->is_punctuation $_->precedes($node)
Truth table0%0/3
A || B
A= $_->is_punctuationB= $_->precedes($node)
ABresult
1X1
011
000
1564 0 ▶ if(scalar(@left_conjuncts)==1 && scalar(@right_conjuncts)==1 && $left_conjuncts[0]->afun() eq $right_conjuncts[0]->afun() && $left_conjuncts[0]->afun() ne 'Coord')
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @left_conjuncts == 1 and scalar @right_conjuncts == 1 and $left_conjuncts[0]->afun eq $right_conjuncts[0]->afun and $left_conjuncts[0]->afun ne "Coord") 0 0 0
Condition0%0/9
scalar @left_conjuncts == 1 and scalar @right_conjuncts == 1 and $left_conjuncts[0]->afun eq $right_conjuncts[0]->afun and $left_conjuncts[0]->afun ne "Coord"
!ll&&!rl&&r
000
scalar @left_conjuncts == 1 and scalar @right_conjuncts == 1 and $left_conjuncts[0]->afun eq $right_conjuncts[0]->afun
!ll&&!rl&&r
000
scalar @left_conjuncts == 1 and scalar @right_conjuncts == 1
!ll&&!rl&&r
000
MC/DC0%0/4
scalar @left_conjuncts == 1 and scalar @right_conjuncts == 1 and $left_conjuncts[0]->afun eq $right_conjuncts[0]->afun and $left_conjuncts[0]->afun ne "Coord"
scalar @left_conjuncts == 1 scalar @right_conjuncts == 1 $left_conjuncts[0]->afun eq $right_conjuncts[0]->afun $left_conjuncts[0]->afun ne "Coord"
Truth table0%0/5
A and B and C and D
A= scalar @left_conjuncts == 1B= scalar @right_conjuncts == 1C= $left_conjuncts[0]->afun eq $right_conjuncts[0]->afunD= $left_conjuncts[0]->afun ne "Coord"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1565 {
1566 0 my $symbol = 0;
1567 # The only children of the conjunction are the two conjuncts and possible additional punctuation.
1568 # There are no other private modifiers of the conjunction.
1569 0 $self->add_delimiter($node, $symbol);
1570 0 my @punctuation = grep {$_->is_punctuation()} $node->children();
1571 0 foreach my $delimiter (@punctuation)
1572 {
1573 # Hopefully the comma has no children but just in case.
1574 0 my @partmodifiers = $delimiter->children();
1575 0 $self->add_delimiter($delimiter, $symbol, @partmodifiers);
1576 }
1577 0 my $orphan = 0;
1578 0 foreach my $conjunct (@left_conjuncts, @right_conjuncts)
1579 {
1580 0 my @partmodifiers = $conjunct->children();
1581 0 $self->add_conjunct($conjunct, $orphan, @partmodifiers);
1582 }
1583 # Save the relation of the coordination to its parent.
1584 0 $self->set_parent($node->parent());
1585 0 $self->set_afun($left_conjuncts[0]->afun());
1586 0 $self->set_is_member($node->is_member());
1587 }
1588 }
1589 # If this is the top level, we now know all we can.
1590 # It's time for a few more heuristics.
1591 0 ▶ if($top)
Branch: 1 branch
BranchTrueFalseTotal
if ($top) 0 0 0
1592 {
1593 0 $self->reconsider_distant_private_modifiers();
1594 }
1595 # Other detection methods return (unless this is $top) the list of modifiers to the upper level,
1596 # where it is needed when the current node is added as a participant.
1597 # In this style however there is no recursion and no nested coordinations so we do not have to return anything.
1598 0 return;
1599 }
1600  
1601  
1602  
1603 #------------------------------------------------------------------------------
1604 # Helper function to find conjuncts around a conjunction. If called on a
1605 # punctuation node (presumably on comma), moves to its sibling and repeats this
1606 # until a non-punctuation node is found.
1607 #------------------------------------------------------------------------------
1608 sub skip_commas
1609 {
1610 0 ▶ my $node = shift;
Subroutine skip_commas: not called CC=5 SCAR=34.0
Pod undocumented
1611 0 my $direction = shift; # left | right
1612 0 my $punctuation = shift; # ref to array; store skipped punctuation here
1613 0 ▶ return if(!defined($node));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
1614 0 ▶ if ($node->is_punctuation() && $node->form() !~ m/^[\"\.\!\?]$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($node->is_punctuation and not $node->form =~ /^[\"\.\!\?]$/) 0 0 0
Condition0%0/3
$node->is_punctuation and not $node->form =~ /^[\"\.\!\?]$/
!ll&&!rl&&r
000
MC/DC0%0/2
$node->is_punctuation and not $node->form =~ /^[\"\.\!\?]$/
$node->is_punctuation not $node->form =~ /^[\"\.\!\?]$/
Truth table0%0/3
A and not(B)
A= $node->is_punctuationB= not $node->form =~ /^[\"\.\!\?]$/
ABresult
0X0
100
111
1615 {
1616 0 push(@{$punctuation}, $node);
1617 0 ▶ if ($direction eq 'left')
Branch: 1 branch
BranchTrueFalseTotal
if ($direction eq 'left') { } 0 0 0
1618 {
1619 0 return skip_commas($node->get_left_neighbor(), $direction, $punctuation);
1620 }
1621 else
1622 {
1623 0 return skip_commas($node->get_right_neighbor(), $direction, $punctuation);
1624 }
1625 }
1626 0 return $node;
1627 }
1628  
1629  
1630  
1631 #------------------------------------------------------------------------------
1632 # Examines private modifiers of the first (word-order-wise) conjunct. If they
1633 # lie after the last conjunct, the function reclassifies them as shared
1634 # modifiers. This is a heuristic that should work well with coordinations that
1635 # were originally encoded in left-to-right Moscow or Stanford styles.
1636 #------------------------------------------------------------------------------
1637 sub reconsider_distant_private_modifiers
1638 {
1639 0 ▶ my $self = shift;
Subroutine reconsider_distant_private_modifiers: not called CC=4 SCAR=30.0
Pod undocumented
1640 0 my @conjuncts = $self->get_conjuncts('ordered' => 1);
1641 0 ▶ return if(scalar(@conjuncts)<2);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @conjuncts < 2 0 0 0
1642 # We will only compare the root nodes of the constituents, not the whole subtrees that could be interleaved.
1643 0 my $maxord = $conjuncts[-1]->ord();
1644 0 my @pord = $self->get_private_modifiers($conjuncts[0]);
1645 0 foreach my $po (@pord)
1646 {
1647 0 ▶ if($po->ord() > $maxord)
Branch: 1 branch
BranchTrueFalseTotal
if ($po->ord > $maxord) 0 0 0
1648 {
1649 0 $self->change_private_modifier_to_shared($po, $conjuncts[0]);
1650 }
1651 }
1652 0 return;
1653 }
1654  
1655  
1656  
1657 #------------------------------------------------------------------------------
1658 # If there is a comma that transitively depends on a conjunct and lies word-
1659 # order-wise between two conjuncts (or between a conjunct and a conjunction),
1660 # it should be considered a coordination delimiter and raised accordingly.
1661 # This is a heuristic that applies e.g. to the Dutch Alpino treebank where
1662 # punctuation symbols are attached to neighboring tokens.
1663 #------------------------------------------------------------------------------
1664 sub capture_commas
1665 {
1666 0 ▶ my $self = shift;
Subroutine capture_commas: not called CC=9 SCAR=45.0
Pod undocumented
1667 0 my $participants = $self->_get_participants();
1668 # Get the limits of every subtree.
1669 0 my @descendants;
1670 0 foreach my $participant (@{$participants})
1671 {
1672 # Get descendants of the current conjunct. Examine the span of the subtree.
1673 # To not depend on the current way of annotation of coordination in the dependency tree,
1674 # do not call $conjunct->get_descendants(). Look at the private conjunct modifiers
1675 # known to the Coordination object instead.
1676 0 my @current_descendants = ($participant->{node});
1677 0 foreach my $pm (@{$participant->{pmod}})
1678 {
1679 0 push(@current_descendants, $pm->get_descendants({'add_self' => 1}));
1680 }
1681 0 @current_descendants = sort {$a->{ord} <=> $b->{ord}} (@current_descendants);
1682 0 push(@descendants, \@current_descendants);
1683 }
1684 # Search for commas between conjuncts.
1685 0 ▶ for(my $i = 1; $i<=$#descendants; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#descendants) 0 0 0
1686 {
1687 # Search for comma between this and the previous conjunct.
1688 # Skip this position if the two subtrees overlap.
1689 0 ▶ next if($descendants[$i][0]->ord()<$descendants[$i-1][-1]->ord());
Branch: 1 branch
BranchTrueFalseTotal
if $descendants[$i][0]->ord < $descendants[$i - 1][-1]->ord 0 0 0
1690 # Is the last node in the left subtree a comma?
1691 0 ▶ if($participants->[$i-1]{type} eq 'conjunct' && $descendants[$i-1][-1]->form() eq ',')
Branch: 1 branch
BranchTrueFalseTotal
if ($$participants[$i - 1]{"type"} eq "conjunct" and $descendants[$i - 1][-1]->form eq ",") 0 0 0
Condition0%0/3
$$participants[$i - 1]{"type"} eq "conjunct" and $descendants[$i - 1][-1]->form eq ","
!ll&&!rl&&r
000
MC/DC0%0/2
$$participants[$i - 1]{"type"} eq "conjunct" and $descendants[$i - 1][-1]->form eq ","
$$participants[$i - 1]{"type"} eq "conjunct" $descendants[$i - 1][-1]->form eq ","
Truth table0%0/3
A and B
A= $$participants[$i - 1]{"type"} eq "conjunct"B= $descendants[$i - 1][-1]->form eq ","
ABresult
0X0
100
111
1692 {
1693 # Make the comma a delimiter in the coordination.
1694 # Re-attachment will be taken care of later during re-shaping of the coordination.
1695 # If the comma is currently known as private modifier, remove it from the list of private modifiers.
1696 0 @{$participants->[$i-1]{pmod}} = grep {$_!=$descendants[$i-1][-1]} (@{$participants->[$i-1]{pmod}});
1697 0 $self->add_delimiter($descendants[$i-1][-1], 1);
1698 }
1699 # Is the first node in the right subtree a comma?
1700 0 ▶ if($participants->[$i]{type} eq 'conjunct' && $descendants[$i][0]->form() eq ',')
Branch: 1 branch
BranchTrueFalseTotal
if ($participants->[$i]{"type"} eq "conjunct" and $descendants[$i][0]->form eq ",") 0 0 0
Condition0%0/3
$participants->[$i]{"type"} eq "conjunct" and $descendants[$i][0]->form eq ","
!ll&&!rl&&r
000
MC/DC0%0/2
$participants->[$i]{"type"} eq "conjunct" and $descendants[$i][0]->form eq ","
$participants->[$i]{"type"} eq "conjunct" $descendants[$i][0]->form eq ","
Truth table0%0/3
A and B
A= $participants->[$i]{"type"} eq "conjunct"B= $descendants[$i][0]->form eq ","
ABresult
0X0
100
111
1701 {
1702 # Make the comma a delimiter in the coordination.
1703 # Re-attachment will be taken care of later during re-shaping of the coordination.
1704 # If the comma is currently known as private modifier, remove it from the list of private modifiers.
1705 0 @{$participants->[$i]{pmod}} = grep {$_!=$descendants[$i][0]} (@{$participants->[$i]{pmod}});
1706 0 $self->add_delimiter($descendants[$i][0], 1);
1707 }
1708 }
1709 0 return;
1710 }
1711  
1712  
1713  
1714 2 1;
1715  
1716  
1717  
1718 =for Pod::Coverage BUILD
1719  
1720 =encoding utf-8
1721  
1722 =head1 NAME
1723  
1724 Treex::Core::Coordination
1725  
1726 =head1 VERSION
1727  
1728 version 2.20151210
1729  
1730 =head1 DESCRIPTION
1731  
1732 Coordination is an object that collect information about a coordination structure in a dependency tree.
1733 It knows all nodes involved in the coordination, i.e. it holds references to the corresponding Node objects.
1734  
1735 =over 4
1736  
1737 =item conjuncts (root nodes of subtrees that represent a conjunct and its dependents)
1738  
1739 =item orphan conjuncts can be distinguished: ExD orphans of deleted real conjuncts
1740  
1741 =item delimiters (conjunctions and punctuation delimiting conjuncts, such as commas)
1742  
1743 =item conjunctions can have their own private dependents (multi-word-conjunctions such as Czech "nejen-ale"; comma-conjunction pair etc.);
1744 then, we link to the head node of the conjunction subtree
1745  
1746 =item shared modifiers (root nodes of subtrees that depend on the whole coordination,
1747 either linguistically motivated (e.g. shared subject of three verb conjuncts)
1748 or a technical rule (e.g. attach quotation marks to the root of the text between them))
1749  
1750 =item private modifiers (direct dependents of any conjunct, or, in exceptional cases,
1751 of a delimiter)
1752  
1753 =back
1754  
1755 All this information is stored independently of the current parent-child relations in the tree,
1756 i.e. independently of the scheme currently used to represent a paratactic structure using dependencies and labels.
1757 The Coordination object is thus useful to collect and store information about coordination during its transformation between two schemes.
1758  
1759 Nevertheless, there are methods that can use the current parent-child links
1760 and labels to identify the nodes participating in coordination and to register
1761 them within this object.
1762 And there are other methods that can relink the current nodes using a
1763 particular annotation scheme.
1764  
1765 Important:
1766  
1767 Logically, participants and modifiers are subtrees.
1768 We store references to the current root nodes of the subtrees.
1769 If the inner topology of the subtree changes our references will no longer be valid.
1770 We may still be pointing into the subtree but we will not hold its local root.
1771 In particular, if the participant or modifier is a nested coordination,
1772 it is covered by a separate Coordination object,
1773 and a method of that object is invoked
1774 to reshape the coordination according to a particular annotation scheme,
1775 our reference will get broken.
1776  
1777 This issue requires special care when manipulating coordinations.
1778 We have to be aware of what we are doing outside the Coordination object and that it is rather short-lived.
1779  
1780 A possible partial solution would be to setup a function that handles root changes.
1781 The node we refer to would get a reference to the handler as a wild attribute.
1782 Coordination-aware transformations could call it when they downgrade the node within its own subtree.
1783 We would still be vulnerable to other manipulations from the outer world.
1784 The handler would get references to the old and the new root of the subtree.
1785 Wherever it would find reference to the old root in the coordination, it would redirect it to the new root.
1786 It would also have to change the list of its private modifiers
1787 (which could be even conjuncts of the nested coordination;
1788 as long as they do not participate in our coordination, it is OK).
1789  
1790 Another partial solution would be to define an abstract object class that could be
1791 either Node or Coordination. Lists of participants and modifiers would refer to
1792 objects of this class instead of just Nodes. If a nested coordination was detected,
1793 the target object would be a Coordination.
1794  
1795 =head1 METHODS
1796  
1797 =head1 AUTHORS
1798  
1799 Daniel Zeman <zeman@ufal.mff.cuni.cz>
1800  
1801 =head1 COPYRIGHT AND LICENSE
1802  
1803 Copyright © 2013 by Institute of Formal and Applied Linguistics, Charles University in Prague
1804  
1805 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« Treex/Core/TredView/Styles.pm ↑ Summary Treex/Core/TredView/Labels.pm »