| 1 | package Treex::Core::Cloud; | ||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $Treex::Core::Cloud::VERSION = '2.20151210'; | |||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Treex::Core::Log; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Treex::Core::Node; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Treex::Core::Coordination; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||
| 13 | # type = node: simple wrapper around a Node object | ||||||||||||||||||||||||||||||||||||||||
| 14 | # type = coordination: wrapper around a Coordination object | ||||||||||||||||||||||||||||||||||||||||
| 15 | # type = cloud: group of clouds of arbitrary types | ||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | has type => | |||||||||||||||||||||||||||||||||||||||
| 17 | ( | ||||||||||||||||||||||||||||||||||||||||
| 18 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||
| 19 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||
| 20 | writer => '_set_type', | ||||||||||||||||||||||||||||||||||||||||
| 21 | reader => 'type' | ||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | has node => | |||||||||||||||||||||||||||||||||||||||
| 25 | ( | ||||||||||||||||||||||||||||||||||||||||
| 26 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||
| 27 | isa => 'Treex::Core::Node', | ||||||||||||||||||||||||||||||||||||||||
| 28 | writer => '_set_node', | ||||||||||||||||||||||||||||||||||||||||
| 29 | reader => '_get_node' | ||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | has coordination => | |||||||||||||||||||||||||||||||||||||||
| 33 | ( | ||||||||||||||||||||||||||||||||||||||||
| 34 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||
| 35 | isa => 'Treex::Core::Coordination', | ||||||||||||||||||||||||||||||||||||||||
| 36 | writer => '_set_coordination', | ||||||||||||||||||||||||||||||||||||||||
| 37 | reader => '_get_coordination' | ||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||
| 40 | # Shared modifiers are clouds that depend on the whole cloud, not just one of its participants. | ||||||||||||||||||||||||||||||||||||||||
| 41 | has _smod => | ||||||||||||||||||||||||||||||||||||||||
| 42 | ( | ||||||||||||||||||||||||||||||||||||||||
| 43 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||
| 44 | isa => 'ArrayRef[Treex::Core::Cloud]', | ||||||||||||||||||||||||||||||||||||||||
| 45 | reader => '_get_smod', | ||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ); | |||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | has parent => | |||||||||||||||||||||||||||||||||||||||
| 50 | ( | ||||||||||||||||||||||||||||||||||||||||
| 51 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||
| 52 | isa => 'Treex::Core::Cloud', | ||||||||||||||||||||||||||||||||||||||||
| 53 | writer => '_set_parent', | ||||||||||||||||||||||||||||||||||||||||
| 54 | reader => 'parent' | ||||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||
| 59 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 60 | # Wraps a Node object in this Cloud object, i.e. creates a node-type cloud. | ||||||||||||||||||||||||||||||||||||||||
| 61 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 62 | sub create_from_node | ||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_from_node: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | log_fatal('Undefined node.') if(!defined($node) || ref($node) ne 'Treex::Core::Node::A'); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $node or ref $node ne "Treex::Core::Node::A"
MC/DC0%0/2
not defined $node or ref $node ne "Treex::Core::Node::A"
not defined $node
ref $node ne "Treex::Core::Node::A"
Truth table0%0/3
not(A) or B
A= not defined $nodeB= ref $node ne "Treex::Core::Node::A"
| |||||||||||||||||||||||||||||||||||||||||
| 67 | # If the node is delimiter of Coordination and we already know it, | ||||||||||||||||||||||||||||||||||||||||
| 68 | # i.e. we have been called through create_from_coordination(), | ||||||||||||||||||||||||||||||||||||||||
| 69 | # then we do not mind whether its afun is Coord | ||||||||||||||||||||||||||||||||||||||||
| 70 | # and we need the list of its private modifiers because we cannot process all its children. | ||||||||||||||||||||||||||||||||||||||||
| 71 | # If it is conjunct then we check the afun normally, as it could be a nested Coordination. | ||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $coordination_delimiter = shift; | |||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $private_modifiers = shift; | |||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if($coordination_delimiter) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $self->_set_type('node'); | |||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $self->_set_node($node); | |||||||||||||||||||||||||||||||||||||||
| 78 | # Wrap all children as clouds. | ||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $smod = $self->_get_smod(); | |||||||||||||||||||||||||||||||||||||||
| 80 | 0 | foreach my $child (@{$private_modifiers}) | |||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $ccloud = Treex::Core::Cloud->new; | |||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $ccloud->create_from_node($child); | |||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $ccloud->_set_parent($self); | |||||||||||||||||||||||||||||||||||||||
| 85 | 0 | push(@{$smod}, $ccloud); | |||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||
| 88 | else | ||||||||||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $afun = $node->afun(); | |||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | $afun = '' if(!defined($afun)); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if($afun eq 'Coord') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $coordination = Treex::Core::Coordination->new; | |||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $coordination->detect_prague($node); | |||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $self->create_from_coordination($coordination); | |||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||
| 98 | else | ||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $self->_set_type('node'); | |||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->_set_node($node); | |||||||||||||||||||||||||||||||||||||||
| 102 | # Wrap all children as clouds. | ||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $smod = $self->_get_smod(); | |||||||||||||||||||||||||||||||||||||||
| 104 | 0 | foreach my $child ($node->children()) | |||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $ccloud = Treex::Core::Cloud->new; | |||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $ccloud->create_from_node($child); | |||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $ccloud->_set_parent($self); | |||||||||||||||||||||||||||||||||||||||
| 109 | 0 | push(@{$smod}, $ccloud); | |||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||
| 118 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 119 | # Wraps a Coordination object in this Cloud object, i.e. creates a | ||||||||||||||||||||||||||||||||||||||||
| 120 | # coordination-type cloud. | ||||||||||||||||||||||||||||||||||||||||
| 121 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 122 | sub create_from_coordination | ||||||||||||||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_from_coordination: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $coordination = shift; | |||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->_set_type('coordination'); | |||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->_set_coordination($coordination); | |||||||||||||||||||||||||||||||||||||||
| 128 | # Wrap all shared modifiers as clouds. | ||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $smod = $self->_get_smod(); | |||||||||||||||||||||||||||||||||||||||
| 130 | 0 | foreach my $modifier ($coordination->get_shared_modifiers()) | |||||||||||||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $ccloud = Treex::Core::Cloud->new; | |||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $ccloud->create_from_node($modifier); | |||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $ccloud->_set_parent($self); | |||||||||||||||||||||||||||||||||||||||
| 135 | 0 | push(@{$smod}, $ccloud); | |||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||
| 137 | # Wrap all participants as clouds. | ||||||||||||||||||||||||||||||||||||||||
| 138 | # We do not need the conjunct-delimiter distinction but we do not want to lose it. | ||||||||||||||||||||||||||||||||||||||||
| 139 | # We could copy all the information from the Coordination object and store it in a parallel array. | ||||||||||||||||||||||||||||||||||||||||
| 140 | # That would mean a lot of copying back and forth and we would have to change it each time the implementation of Coordination changes. | ||||||||||||||||||||||||||||||||||||||||
| 141 | # It will be better in future if the concept of Cloud proves viable and we make the Coordination class a derivative of Cloud. | ||||||||||||||||||||||||||||||||||||||||
| 142 | # For the moment however, we just abuse the list of records about participants within Coordination, and store the link to the sub-Cloud there. | ||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $participants = $coordination->_get_participants(); | |||||||||||||||||||||||||||||||||||||||
| 144 | 0 | foreach my $participant (@{$participants}) | |||||||||||||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $node = $participant->{node}; | |||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $ccloud = Treex::Core::Cloud->new; | |||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if($participant->{type} eq 'delimiter') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $ccloud->create_from_node($node, 1, $participant->{pmod}); | |||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||
| 152 | else | ||||||||||||||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $ccloud->create_from_node($node); | |||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $participant->{cloud} = $ccloud; | |||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||
| 163 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 164 | # Disconnects a cloud from its parent cloud. Discards the link from child to | ||||||||||||||||||||||||||||||||||||||||
| 165 | # parent and removes the link to the child from the list of modifiers kept | ||||||||||||||||||||||||||||||||||||||||
| 166 | # with the parent. We must do this manually to prevent memory leaks. Perl | ||||||||||||||||||||||||||||||||||||||||
| 167 | # garbage collection will not work because of cyclic references. | ||||||||||||||||||||||||||||||||||||||||
| 168 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 169 | sub disconnect_from_parent | ||||||||||||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect_from_parent: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $parent = $self->parent(); | |||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if(defined($parent)) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||||||||||||||
| 175 | # Moose will not allow _set_parent(undef) because undef is not of class Treex::Core::Cloud. | ||||||||||||||||||||||||||||||||||||||||
| 176 | # We will create a dummy object instead. Parent will have the only reference to it and Perl will be able to discard it. | ||||||||||||||||||||||||||||||||||||||||
| 177 | # I am sure that there must be a better way to do this but I don't know how. | ||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $self->_set_parent(Treex::Core::Cloud->new); | |||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $opsmod = $parent->_get_smod(); | |||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | for(my $i = 0; $i<=$#{$opsmod}; $i++) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if($opsmod->[$i]==$self) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | splice(@{$opsmod}, $i, 1); | |||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $found = 1; | |||||||||||||||||||||||||||||||||||||||
| 187 | 0 | last; | |||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if(!$found) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | log_fatal('Parent cloud does not know me as its shared modifier.'); | |||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||
| 199 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 200 | # Manual cleanup top-down: destroy my descendants. Disconnect them from me | ||||||||||||||||||||||||||||||||||||||||
| 201 | # manually (Perl garbage collector would not work with cyclic references). | ||||||||||||||||||||||||||||||||||||||||
| 202 | # (DZ: I tried to monitor memory usage with and without this cleanup and I did | ||||||||||||||||||||||||||||||||||||||||
| 203 | # not observe any difference. But I am leaving it here, just in case.) | ||||||||||||||||||||||||||||||||||||||||
| 204 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 205 | sub destroy_children | ||||||||||||||||||||||||||||||||||||||||
| 206 | { | ||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
destroy_children: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $smod = $self->_get_smod(); | |||||||||||||||||||||||||||||||||||||||
| 209 | 0 | foreach my $child (@{$smod}) | |||||||||||||||||||||||||||||||||||||||
| 210 | { | ||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $child->destroy_children(); | |||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $child->_set_parent(Treex::Core::Cloud->new); # disconnect from me | |||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | splice(@{$smod}); | |||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if($self->type() eq 'coordination') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my $participants = $self->_get_coordination()->_get_participants(); | |||||||||||||||||||||||||||||||||||||||
| 218 | 0 | foreach my $participant (@{$participants}) | |||||||||||||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $participant->{cloud}->destroy_children(); | |||||||||||||||||||||||||||||||||||||||
| 221 | 0 | delete($participant->{cloud}); | |||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||
| 229 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 230 | # Sets the parent cloud of this cloud. Makes sure to also appropriately | ||||||||||||||||||||||||||||||||||||||||
| 231 | # reattach the corresponding nodes. This node will become a shared modifier | ||||||||||||||||||||||||||||||||||||||||
| 232 | # (not participant) of the parent cloud. | ||||||||||||||||||||||||||||||||||||||||
| 233 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 234 | sub set_parent | ||||||||||||||||||||||||||||||||||||||||
| 235 | { | ||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_parent: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $pcloud = shift; | |||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | log_fatal('Unknown new parent.') if(!defined($pcloud)); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $type = $self->type(); | |||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $ptype = $pcloud->type(); | |||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $node; | |||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if($type eq 'node') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $node = $self->_get_node(); | |||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||
| 246 | elsif($type eq 'coordination') | ||||||||||||||||||||||||||||||||||||||||
| 247 | { | ||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $node = $self->_get_coordination()->shape_prague(); | |||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $opcloud = $self->parent(); | |||||||||||||||||||||||||||||||||||||||
| 251 | # Cleanup: remove me from the list of modifiers of the old parent. | ||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if(defined($opcloud)) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||||||||||||||
| 254 | # If it is a coordination we must do the same with the list of shared modifer nodes in the Coordination. | ||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if($opcloud->type() eq 'coordination') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 256 | { | ||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $opcsmod = $opcloud->_get_coordination()->_get_smod(); | |||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | for(my $i = 0; $i<=$#{$opcsmod}; $i++) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 260 | { | ||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if($opcsmod->[$i]==$node) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | splice(@{$opcsmod}, $i, 1); | |||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $found = 1; | |||||||||||||||||||||||||||||||||||||||
| 265 | 0 | last; | |||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if(!$found) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 269 | { | ||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | log_fatal('Parent coordination does not know me as its shared modifier.'); | |||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $self->disconnect_from_parent(); | |||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $self->_set_parent($pcloud); | |||||||||||||||||||||||||||||||||||||||
| 276 | # Reattach the corresponding nodes. | ||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if($type eq 'node' && $ptype eq 'node') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
$type eq "node" and $ptype eq "node"
MC/DC0%0/2
$type eq "node" and $ptype eq "node"
$type eq "node"
$ptype eq "node"
Truth table0%0/3
A and B
A= $type eq "node"B= $ptype eq "node"
| |||||||||||||||||||||||||||||||||||||||||
| 278 | { | ||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $node->set_parent($pcloud->_get_node()); | |||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||
| 281 | ▶ | elsif($type eq 'node' && $ptype eq 'coordination') | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$type eq "node" and $ptype eq "coordination"
MC/DC0%0/2
$type eq "node" and $ptype eq "coordination"
$type eq "node"
$ptype eq "coordination"
Truth table0%0/3
A and B
A= $type eq "node"B= $ptype eq "coordination"
| |||||||||||||||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $pcoordination = $pcloud->_get_coordination(); | |||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $pcoordination->add_shared_modifier($node); | |||||||||||||||||||||||||||||||||||||||
| 285 | 0 | $pcoordination->shape_prague(); | |||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||
| 287 | ▶ | elsif($type eq 'coordination' && $ptype eq 'coordination') | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$type eq "coordination" and $ptype eq "coordination"
MC/DC0%0/2
$type eq "coordination" and $ptype eq "coordination"
$type eq "coordination"
$ptype eq "coordination"
Truth table0%0/3
A and B
A= $type eq "coordination"B= $ptype eq "coordination"
| |||||||||||||||||||||||||||||||||||||||||
| 288 | { | ||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my $pcoordination = $pcloud->_get_coordination(); | |||||||||||||||||||||||||||||||||||||||
| 290 | 0 | $pcoordination->add_shared_modifier($node); | |||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $pcoordination->shape_prague(); | |||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||
| 293 | ▶ | elsif($type eq 'coordination' && $ptype eq 'node') | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$type eq "coordination" and $ptype eq "node"
MC/DC0%0/2
$type eq "coordination" and $ptype eq "node"
$type eq "coordination"
$ptype eq "node"
Truth table0%0/3
A and B
A= $type eq "coordination"B= $ptype eq "node"
| |||||||||||||||||||||||||||||||||||||||||
| 294 | { | ||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $coordination = $self->_get_coordination(); | |||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $coordination->set_parent($pcloud->_get_node()); | |||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $coordination->shape_prague(); | |||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||
| 304 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 305 | # Returns non-zero if this cloud is coordination. | ||||||||||||||||||||||||||||||||||||||||
| 306 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 307 | sub is_coordination | ||||||||||||||||||||||||||||||||||||||||
| 308 | { | ||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_coordination: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | return $self->type() eq 'coordination'; | |||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||
| 315 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 316 | # Sets the afun of the cloud. It describes its relation to the parent cloud. | ||||||||||||||||||||||||||||||||||||||||
| 317 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 318 | sub set_afun | ||||||||||||||||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_afun: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $afun = shift; | |||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if($self->type() eq 'node') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 323 | { | ||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $self->_get_node()->set_afun($afun); | |||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||
| 326 | elsif($self->type() eq 'coordination') | ||||||||||||||||||||||||||||||||||||||||
| 327 | { | ||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $coordination = $self->_get_coordination(); | |||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $coordination->set_afun($afun); | |||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $coordination->shape_prague(); | |||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||
| 337 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 338 | # Returns the afun of the cloud. It describes its relation to the parent cloud. | ||||||||||||||||||||||||||||||||||||||||
| 339 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 340 | sub afun | ||||||||||||||||||||||||||||||||||||||||
| 341 | { | ||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
afun: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if($self->type() eq 'node') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 344 | { | ||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | return $self->_get_node()->afun(); | |||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||
| 347 | elsif($self->type() eq 'coordination') | ||||||||||||||||||||||||||||||||||||||||
| 348 | { | ||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | return $self->_get_coordination()->afun(); | |||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||
| 355 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 356 | # Returns the list of clouds that function as shared modifiers of this cloud. | ||||||||||||||||||||||||||||||||||||||||
| 357 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 358 | sub get_shared_modifiers | ||||||||||||||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_shared_modifiers: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $smod = $self->_get_smod(); | |||||||||||||||||||||||||||||||||||||||
| 362 | 0 | my @list = @{$smod}; | |||||||||||||||||||||||||||||||||||||||
| 363 | 0 | return @list; | |||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||
| 368 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 369 | # Returns the list of clouds that are participants of this cloud. This function | ||||||||||||||||||||||||||||||||||||||||
| 370 | # is used for recursion and it does not return anything for single-node clouds. | ||||||||||||||||||||||||||||||||||||||||
| 371 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 372 | sub get_participants | ||||||||||||||||||||||||||||||||||||||||
| 373 | { | ||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_participants: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my @list; | |||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | if($self->type() eq 'coordination') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 377 | { | ||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my $coordination = $self->_get_coordination(); | |||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my $participants = $coordination->_get_participants(); | |||||||||||||||||||||||||||||||||||||||
| 380 | 0 | foreach my $participant (@{$participants}) | |||||||||||||||||||||||||||||||||||||||
| 381 | { | ||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | push(@list, $participant->{cloud}); | |||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | return @list; | |||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||
| 390 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 391 | # Returns the list of all participants and shared modifiers (clouds). This is | ||||||||||||||||||||||||||||||||||||||||
| 392 | # useful for recursion, if we want to traverse all clouds in the tree. | ||||||||||||||||||||||||||||||||||||||||
| 393 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 394 | sub get_participants_and_modifiers | ||||||||||||||||||||||||||||||||||||||||
| 395 | { | ||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_participants_and_modifiers: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my @list = $self->get_shared_modifiers(); | |||||||||||||||||||||||||||||||||||||||
| 398 | 0 | push(@list, $self->get_participants()); | |||||||||||||||||||||||||||||||||||||||
| 399 | 0 | return @list; | |||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||
| 404 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 405 | # Selects a node inside the cloud as the representative of the cloud and | ||||||||||||||||||||||||||||||||||||||||
| 406 | # returns its address. | ||||||||||||||||||||||||||||||||||||||||
| 407 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||
| 408 | sub get_address | ||||||||||||||||||||||||||||||||||||||||
| 409 | { | ||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_address: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | if($self->type() eq 'node') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 412 | { | ||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | return $self->_get_node()->get_address(); | |||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||
| 415 | # It is not clear which node should represent a non-trivial cloud. | ||||||||||||||||||||||||||||||||||||||||
| 416 | # Remember, we want a cloud to be independent of the current dependency representation of intra-cloud relations. | ||||||||||||||||||||||||||||||||||||||||
| 417 | # We pick the first participant at the moment. | ||||||||||||||||||||||||||||||||||||||||
| 418 | else | ||||||||||||||||||||||||||||||||||||||||
| 419 | { | ||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my @participants = $self->get_participants(); | |||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if(scalar(@participants)>0) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 422 | { | ||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | return $participants[0]->get_address(); | |||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||
| 425 | else | ||||||||||||||||||||||||||||||||||||||||
| 426 | { | ||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | log_fatal("Cannot identify a node in the cloud to get address of"); | |||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||
| 434 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||
| 438 | =for Pod::Coverage BUILD | ||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||
| 440 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||
| 442 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||
| 444 | Treex::Core::Cloud | ||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||
| 446 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||
| 448 | version 2.20151210 | ||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||
| 450 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||
| 452 | Cloud is a group of nodes. It can be also thought of as a group of subtrees headed by the nodes. | ||||||||||||||||||||||||||||||||||||||||
| 453 | There is a relation between the nodes but we are not sure (or do not yet want to explicitly mark) | ||||||||||||||||||||||||||||||||||||||||
| 454 | what direction the dependencies should go. An example is a preposition and its noun phrase: | ||||||||||||||||||||||||||||||||||||||||
| 455 | one annotation scheme requires that the noun phrase depends on the preposition, another scheme | ||||||||||||||||||||||||||||||||||||||||
| 456 | wants the preposition to depend on the noun phrase. | ||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||
| 458 | The nodes (subtrees) that are members of the cloud are called I<participants>. Before they entered | ||||||||||||||||||||||||||||||||||||||||
| 459 | the cloud one of them was probably the head and the others were its dependents. We may need these | ||||||||||||||||||||||||||||||||||||||||
| 460 | dependencies in order to detect and construct a Cloud object but then they are not important for | ||||||||||||||||||||||||||||||||||||||||
| 461 | the cloud. Before the cloud is destroyed, it will select one of the participants the head and make | ||||||||||||||||||||||||||||||||||||||||
| 462 | the others depend on it, based on user preferences. Cloud is a temporary internal structure that | ||||||||||||||||||||||||||||||||||||||||
| 463 | will not be saved in the Treex format on the disk. | ||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||
| 465 | Cloud can behave as a generalized Node. It has a parent, an afun (i.e. label of its relation to its | ||||||||||||||||||||||||||||||||||||||||
| 466 | parent), and the is_member attribute (i.e. it can be a conjunct). Besides the children of the | ||||||||||||||||||||||||||||||||||||||||
| 467 | individual participants, hidden in their subtrees, there can be also I<shared modifiers>: nodes | ||||||||||||||||||||||||||||||||||||||||
| 468 | (subtrees) depending on the whole cloud. When we are finished with the cloud, these subtrees will | ||||||||||||||||||||||||||||||||||||||||
| 469 | be attached to whatever node we select as the head of the cloud. | ||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||
| 471 | Technically all referenced nodes (participants, parent and shared modifiers) are objects of the | ||||||||||||||||||||||||||||||||||||||||
| 472 | class Cloud, not Node. Undirected dependencies can just be handled recursively and they will interact | ||||||||||||||||||||||||||||||||||||||||
| 473 | correctly (for instance, a chain of AuxP-AuxC-something). Any Node can be trivially converted to | ||||||||||||||||||||||||||||||||||||||||
| 474 | a Cloud with a single participant. | ||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||
| 476 | The concept of cloud adds a new dimension of relations to the node network we keep in Treex. | ||||||||||||||||||||||||||||||||||||||||
| 477 | The first dimension is the linear ordering of nodes according to the word order. | ||||||||||||||||||||||||||||||||||||||||
| 478 | The second dimension contains the parent-child relations between nodes or clouds. | ||||||||||||||||||||||||||||||||||||||||
| 479 | The third dimension connects subtrees (or clouds) that are participants of the same cloud. | ||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||
| 481 | Cloud should be useful for transformations between different annotation styles, especially in cases | ||||||||||||||||||||||||||||||||||||||||
| 482 | where multiple clouds with different rules interact. | ||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||
| 484 | We may want in future to make the Coordination class a special (and most complex) case of Cloud. | ||||||||||||||||||||||||||||||||||||||||
| 485 | Philosophically, coordination is a cloud. Technically however, our current implementation of | ||||||||||||||||||||||||||||||||||||||||
| 486 | the Coordination class operates on Nodes, not Clouds. Therefore if a Node involved in Coordination | ||||||||||||||||||||||||||||||||||||||||
| 487 | is also part of a Cloud and the head preference within the Cloud changes, the Coordination will be | ||||||||||||||||||||||||||||||||||||||||
| 488 | no longer valid (see also discussion in the documentation of Coordination). Similarly the current | ||||||||||||||||||||||||||||||||||||||||
| 489 | implementation of Cloud must carefully check (using Coord afun and is_member attribute) whether | ||||||||||||||||||||||||||||||||||||||||
| 490 | the Nodes it deals with are involved in coordination. | ||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||
| 492 | The implementation must also make sure that code that does not know about clouds will still see | ||||||||||||||||||||||||||||||||||||||||
| 493 | a valid tree. It may be achieved by adding new temporary Node objects: | ||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||
| 495 | =over | ||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||
| 497 | =item There are two temporary artificial nodes: the I<head node> and the I<cloud node>. | ||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||
| 499 | =item An artificial node with afun C<Cloud> will serve as the temporary parent of all participants. | ||||||||||||||||||||||||||||||||||||||||
| 500 | They keep their original afuns. We may need the afuns when we reorganize the relations between | ||||||||||||||||||||||||||||||||||||||||
| 501 | participants. | ||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||
| 503 | =item Another artificial node will be the parent of the C<Cloud> node and of any shared modifiers. | ||||||||||||||||||||||||||||||||||||||||
| 504 | This node will be attached to the parent node of the cloud, with the afun that reflects the relation | ||||||||||||||||||||||||||||||||||||||||
| 505 | between the cloud and its parent. | ||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||
| 507 | =item If the parent of the cloud is a participant of another cloud, our head node's parent is directly | ||||||||||||||||||||||||||||||||||||||||
| 508 | the participant node. If the parent is the other cloud as a whole (we are a shared modifier), our | ||||||||||||||||||||||||||||||||||||||||
| 509 | head node's parent is the head node of the parent cloud. | ||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||
| 511 | =item Single nodes that do not participate in any explicitly defined cloud can be viewed as clouds | ||||||||||||||||||||||||||||||||||||||||
| 512 | with head and cloud nodes collapsed into one. No artificial nodes will be generated for them. | ||||||||||||||||||||||||||||||||||||||||
| 513 | There is no need to distinguish between shared and private modifiers. | ||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||
| 515 | =back | ||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||
| 517 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||
| 519 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||
| 521 | Daniel Zeman <zeman@ufal.mff.cuni.cz> | ||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||
| 523 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||
| 525 | Copyright © 2013 by Institute of Formal and Applied Linguistics, Charles University in Prague | ||||||||||||||||||||||||||||||||||||||||
| 526 | This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||