| 1 | package Treex::Core::BundleZone; | ||||||||||||||||||||||||||||
| 2 | 35 | $Treex::Core::BundleZone::VERSION = '2.20210102'; | |||||||||||||||||||||||||||
| 3 | 35 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 35 | ▶ | use Treex::Core::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 35 | ▶ | use MooseX::NonMoose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 35 | ▶ | use Treex::Core::Node::A; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 35 | ▶ | use Treex::Core::Node::T; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 35 | ▶ | use Treex::Core::Node::N; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 35 | ▶ | use Treex::Core::Node::P; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 35 | extends 'Treex::Core::Zone'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 48 | ▶ | sub _set_bundle { | ||||||||||||||||||||||||||
|
Subroutine
_set_bundle: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 48 | my $self = shift; | |||||||||||||||||||||||||||
| 16 | 48 | my ($bundle) = pos_validated_list( | |||||||||||||||||||||||||||
| 17 | \@_, | ||||||||||||||||||||||||||||
| 18 | { isa => 'Treex::Core::Bundle' }, | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | 48 | $self->set_attr( '_bundle', $bundle ); | |||||||||||||||||||||||||||
| 21 | 48 | weaken $self->{'_bundle'}; | |||||||||||||||||||||||||||
| 22 | 48 | return; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1281 | ▶ | sub get_bundle { | ||||||||||||||||||||||||||
|
Subroutine
get_bundle: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 1281 | my $self = shift; | |||||||||||||||||||||||||||
| 27 | 1281 | return $self->get_attr('_bundle'); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 42 | ▶ | sub get_document { | ||||||||||||||||||||||||||
|
Subroutine
get_document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 42 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | 42 | return $self->get_bundle->get_document; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 9 | ▶ | sub create_atree { | ||||||||||||||||||||||||||
|
Subroutine
create_atree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 9 | my ($self,$params_rf) = @_; | |||||||||||||||||||||||||||
| 37 | 9 | return $self->create_tree('a',$params_rf); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 10 | ▶ | sub create_ttree { | ||||||||||||||||||||||||||
|
Subroutine
create_ttree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 10 | my ($self,$params_rf) = @_; | |||||||||||||||||||||||||||
| 42 | 10 | return $self->create_tree('t',$params_rf); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 4 | ▶ | sub create_ntree { | ||||||||||||||||||||||||||
|
Subroutine
create_ntree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 4 | my ($self,$params_rf) = @_; | |||||||||||||||||||||||||||
| 47 | 4 | return $self->create_tree('n',$params_rf); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 6 | ▶ | sub create_ptree { | ||||||||||||||||||||||||||
|
Subroutine
create_ptree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 6 | my ($self,$params_rf) = @_; | |||||||||||||||||||||||||||
| 52 | 6 | return $self->create_tree('p',$params_rf); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 78 | ▶ | sub create_tree { | ||||||||||||||||||||||||||
|
Subroutine
create_tree: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 78 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | 78 | my ($layer,$params_rf) = pos_validated_list( | |||||||||||||||||||||||||||
| 58 | \@_, | ||||||||||||||||||||||||||||
| 59 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||
| 60 | { isa => 'Ref' }, | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | 78 | $layer = lc $layer; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 78 | ▶ | if ($self->has_tree($layer)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 12 | ▶ | if (defined $params_rf and $params_rf->{overwrite}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $params_rf and $params_rf->{"overwrite"}
MC/DC0%0/2
defined $params_rf and $params_rf->{"overwrite"}
defined $params_rf
$params_rf->{"overwrite"}
Truth table33%1/3
A and B
A= defined $params_rfB= $params_rf->{"overwrite"}
| |||||||||||||||||||||||||||||
| 66 | 12 | $self->remove_tree($layer); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||
| 69 | 0 | log_fatal("Zone already contains tree at $layer layer"); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | #my $class = "Treex::Core::Node::" . uc($layer); | ||||||||||||||||||||||||||||
| 74 | #my $tree_root = eval { $class->new( { _called_from_core_ => 1 } ) } or log_fatal $!; #layer subclasses not available yet | ||||||||||||||||||||||||||||
| 75 | 78 | my $opts = { _called_from_core_ => 1 }; | |||||||||||||||||||||||||||
| 76 | 78 | ▶ | my $tree_root = $layer eq 'a' ? Treex::Core::Node::A->new($opts) | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 77 | : $layer eq 't' ? Treex::Core::Node::T->new($opts) | ||||||||||||||||||||||||||||
| 78 | : $layer eq 'n' ? Treex::Core::Node::N->new($opts) | ||||||||||||||||||||||||||||
| 79 | : $layer eq 'p' ? Treex::Core::Node::P->new($opts) | ||||||||||||||||||||||||||||
| 80 | : log_fatal "Cannot create tree for unknown layer $layer"; | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 78 | my $bundle = $self->get_bundle; | |||||||||||||||||||||||||||
| 83 | 78 | $tree_root->_set_zone($self); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 78 | my $new_tree_name = $layer . "_tree"; | |||||||||||||||||||||||||||
| 86 | 78 | $self->{trees}->{$new_tree_name} = $tree_root; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 78 | my $new_id = "$new_tree_name-" . $self->get_label . "-" . $bundle->get_id . "-root"; | |||||||||||||||||||||||||||
| 89 | 78 | $tree_root->set_id($new_id); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # pml-typing | ||||||||||||||||||||||||||||
| 92 | #$tree_root->set_type_by_name( $self->get_document->metaData('schema'), lc($layer) . '-root.type' ); | ||||||||||||||||||||||||||||
| 93 | # $tree_root->set_type_by_name( $self->get_document->metaData('schema'), $tree_root->get_pml_type_name() ); | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 78 | $tree_root->fix_pml_type(); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # vyresit usporadavaci atribut! | ||||||||||||||||||||||||||||
| 98 | # TODO: if $tree_root->does('Treex::Core::Role::OrderedTree') | ||||||||||||||||||||||||||||
| 99 | 78 | my $ordering_attribute = $tree_root->get_ordering_member_name; | |||||||||||||||||||||||||||
| 100 | 78 | ▶ | if ( defined $ordering_attribute ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 52 | $tree_root->set_attr( $ordering_attribute, 0 ); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 78 | return $tree_root; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 42 | ▶ | sub remove_tree { | ||||||||||||||||||||||||||
|
Subroutine
remove_tree: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 42 | my $self = shift; | |||||||||||||||||||||||||||
| 109 | 42 | my ($layer) = pos_validated_list( | |||||||||||||||||||||||||||
| 110 | \@_, | ||||||||||||||||||||||||||||
| 111 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # remove all nodes ($tree_root->remove does not work, in order to not be used by users) | ||||||||||||||||||||||||||||
| 115 | 42 | my $tree_root = $self->get_tree($layer); | |||||||||||||||||||||||||||
| 116 | 42 | foreach my $child ( $tree_root->get_children() ) { | |||||||||||||||||||||||||||
| 117 | 13 | $child->remove(); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 42 | ▶ | if ( $tree_root->id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 42 | $self->get_document->index_node_by_id( $tree_root->id, undef ); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 42 | delete $self->{trees}{ lc($layer) . '_tree' }; | |||||||||||||||||||||||||||
| 123 | 42 | return; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 108 | ▶ | sub get_tree { | ||||||||||||||||||||||||||
|
Subroutine
get_tree: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 108 | my $self = shift; | |||||||||||||||||||||||||||
| 128 | 108 | my ($layer) = pos_validated_list( | |||||||||||||||||||||||||||
| 129 | \@_, | ||||||||||||||||||||||||||||
| 130 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 108 | my $tree_name = lc($layer) . "_tree"; | |||||||||||||||||||||||||||
| 134 | 108 | my $tree = $self->{trees}->{$tree_name}; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 108 | ▶ | if ( not defined $tree ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | log_fatal( "No $tree_name available in bundle ".$self->get_bundle->get_attr('id')." in zone " . $self->get_label() ); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | 108 | return $tree; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 9 | ▶ | sub get_atree { | ||||||||||||||||||||||||||
|
Subroutine
get_atree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 144 | 9 | return $self->get_tree('a'); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 9 | ▶ | sub get_ttree { | ||||||||||||||||||||||||||
|
Subroutine
get_ttree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 148 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 149 | 9 | return $self->get_tree('t'); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 7 | ▶ | sub get_ntree { | ||||||||||||||||||||||||||
|
Subroutine
get_ntree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 154 | 7 | return $self->get_tree('n'); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 6 | ▶ | sub get_ptree { | ||||||||||||||||||||||||||
|
Subroutine
get_ptree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 159 | 6 | return $self->get_tree('p'); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 130 | ▶ | sub has_tree { | ||||||||||||||||||||||||||
|
Subroutine
has_tree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 130 | my $self = shift; | |||||||||||||||||||||||||||
| 164 | 130 | my ($layer) = pos_validated_list( | |||||||||||||||||||||||||||
| 165 | \@_, | ||||||||||||||||||||||||||||
| 166 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||
| 168 | 130 | my $tree_name = lc($layer) . "_tree"; | |||||||||||||||||||||||||||
| 169 | 130 | return defined $self->{trees}->{$tree_name}; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 3 | ▶ | sub has_atree { | ||||||||||||||||||||||||||
|
Subroutine
has_atree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 173 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 174 | 3 | return $self->has_tree('a'); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 3 | ▶ | sub has_ttree { | ||||||||||||||||||||||||||
|
Subroutine
has_ttree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 178 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 179 | 3 | return $self->has_tree('t'); | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 3 | ▶ | sub has_ntree { | ||||||||||||||||||||||||||
|
Subroutine
has_ntree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 183 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 184 | 3 | return $self->has_tree('n'); | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 3 | ▶ | sub has_ptree { | ||||||||||||||||||||||||||
|
Subroutine
has_ptree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 189 | 3 | return $self->has_tree('p'); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 459 | ▶ | sub get_all_trees { | ||||||||||||||||||||||||||
|
Subroutine
get_all_trees: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 193 | 459 | my $self = shift; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 1836 | return grep {defined} | |||||||||||||||||||||||||||
| 196 | 459 | map { $self->{trees}->{ $_ . "_tree" }; } qw(a t n p); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub sentence { | ||||||||||||||||||||||||||
|
Subroutine
sentence: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 200 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 201 | 0 | return $self->get_attr('sentence'); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub set_sentence { | ||||||||||||||||||||||||||
|
Subroutine
set_sentence: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 205 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 206 | 0 | my ($text) = pos_validated_list( | |||||||||||||||||||||||||||
| 207 | \@_, | ||||||||||||||||||||||||||||
| 208 | { isa => 'Str' }, | ||||||||||||||||||||||||||||
| 209 | ); | ||||||||||||||||||||||||||||
| 210 | 0 | return $self->set_attr( 'sentence', $text ); | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub copy { | ||||||||||||||||||||||||||
|
Subroutine
copy: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 214 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 215 | 0 | my $selector1 = shift; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # Get the bundle the zone is in. | ||||||||||||||||||||||||||||
| 218 | 0 | my $bundle = $self->get_bundle(); | |||||||||||||||||||||||||||
| 219 | 0 | my $zone1 = $bundle->get_or_create_zone( $self->language(), $selector1 ); | |||||||||||||||||||||||||||
| 220 | ### TO DO: copy other trees, too (currently only copies a-tree and p-tree) | ||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if($self->has_atree()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||
| 223 | 0 | my $aroot0 = $self->get_atree(); | |||||||||||||||||||||||||||
| 224 | 0 | my $aroot1 = $zone1->create_atree(); | |||||||||||||||||||||||||||
| 225 | 0 | $aroot0->copy_atree($aroot1); | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | 0 | ▶ | if($self->has_ptree()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | { | ||||||||||||||||||||||||||||
| 229 | 0 | my $proot0 = $self->get_ptree(); | |||||||||||||||||||||||||||
| 230 | 0 | my $proot1 = $zone1->create_ptree(); | |||||||||||||||||||||||||||
| 231 | 0 | $proot0->copy_ptree($proot1); | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | 0 | return $zone1; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 35 | 1; | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | __END__ | ||||||||||||||||||||||||||||