| 1 | package Treex::Core::Bundle; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 34 | $Treex::Core::Bundle::VERSION = '2.20210102'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 34 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 34 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 34 | ▶ | use Treex::Core::Common; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 34 | ▶ | use MooseX::NonMoose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 34 | extends 'Treex::PML::Node'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 34 | with 'Treex::Core::WildAttr'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 34 | has document => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | writer => '_set_document', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | reader => 'get_document', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 34 | has id => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 34 | ▶ | use Treex::Core::Node; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 34 | ▶ | use Treex::Core::Node::A; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 34 | ▶ | use Treex::Core::Node::T; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 34 | ▶ | use Treex::Core::Node::N; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 34 | ▶ | use Treex::Core::Node::P; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 34 | ▶ | use Treex::Core::BundleZone; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 34 | ▶ | use Treex::Core::Log; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # --------- ACCESS TO ZONES ------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | log_fatal 'Because of node indexing, no bundles can be created outside of documents. ' | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | . 'You have to use $document->create_bundle() instead of $bundle->new().'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 74 | ▶ | sub get_zone { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_zone: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 74 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 74 | my ( $language, $selector ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | { isa => 'Treex::Type::LangCode' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | { isa => 'Treex::Type::Selector', default => '' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 74 | ▶ | if ( defined $self->{zones} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 52 | foreach my $element ( $self->{zones}->elements ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 85 | my ( undef, $value ) = @$element; # $name is not needed | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 85 | ▶ | if (( $value->{language} eq $language or $language eq 'mul' ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition87%7/8
$value->{"language"} eq $language || $language eq "mul" and ($value->{"selector"} || "") eq $selector
$value->{"language"} eq $language or $language eq "mul"
$value->{'selector'} || ''
MC/DC66%2/3
$value->{"language"} eq $language || $language eq "mul" and ($value->{"selector"} || "") eq $selector
$value->{"language"} eq $language
$language eq "mul"
$value->{'selector'}
Truth table60%3/5
A or B and C
A= $value->{"language"} eq $languageB= $language eq "mul"C= $value->{'selector'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | and ( $value->{selector} || '' ) eq $selector | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 37 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 37 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 35 | ▶ | sub create_zone { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_zone: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 35 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 35 | my ( $language, $selector, $params_rf ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | { isa => 'Treex::Type::LangCode' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | { isa => 'Treex::Type::Selector', default => '' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | { isa => 'Ref' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 35 | ▶ | if ( $self->get_zone( $language, $selector ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | if (defined $params_rf and $params_rf->{overwrite}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $params_rf and $params_rf->{"overwrite"}
MC/DC50%1/2
defined $params_rf and $params_rf->{"overwrite"}
defined $params_rf
$params_rf->{"overwrite"}
Truth table66%2/3
A and B
A= defined $params_rfB= $params_rf->{"overwrite"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | log_fatal("Bundle already contains a zone with language='$language' and selector='$selector'. " | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | . "Use create_zone(...,{overwrite=>1}) to remove it first.") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 34 | my $new_zone = Treex::Core::BundleZone->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 'language' => $language, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 'selector' => $selector, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 34 | my $new_element = Treex::PML::Seq::Element->new( 'zone', $new_zone ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 34 | $new_zone->_set_bundle($self); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # $new_subbundle->set_type_by_name( $self->get_document->metaData('schema'), 'zone' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 34 | ▶ | if ( defined $self->{zones} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 13 | $self->{zones}->unshift_element_obj($new_element); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 21 | $self->{zones} = Treex::PML::Seq->new( [$new_element] ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 34 | return $new_zone; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 4 | ▶ | sub get_or_create_zone { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_or_create_zone: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | my ( $language, $selector ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | { isa => 'Treex::Type::LangCode' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | { isa => 'Treex::Type::Selector', default => '' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | my $zone = $self->get_zone( $language, $selector ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | if ( !defined $zone ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | $zone = $self->create_zone( $language, $selector ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | return $zone; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 154 | ▶ | sub get_all_zones { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_zones: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 154 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 154 | ▶ | if ( $self->{zones} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 133 | return map { $_->value() } $self->{zones}->elements; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 21 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | ▶ | sub remove_zone { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_zone: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | my ( $self, $language, $selector ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 6 | my $zone = $self->get_zone( $language, $selector ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | ▶ | if ( !$zone ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | log_fatal "Non-existing zone cannot be removed"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # remove all trees first, so that their nodes are correctly removed from the index | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 6 | foreach my $tree ( $zone->get_all_trees ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 15 | $zone->remove_tree( $tree->get_layer ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | ▶ | $self->{zones}->delete_value($zone) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | or log_fatal "Zone to be deleted was not found. This should never happen"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | ▶ | sub remove { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # clean the bundle's content first (to ensure de-indexing) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | foreach my $zone ( $self->get_all_zones ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | $self->remove_zone( $zone->language, $zone->selector ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | my $position = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # find the bundle's position (this is quite inefficient, as the info about | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # bundle's position is stored nowhere), and delete the bundle using Treex::PML API | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | BUNDLE: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | foreach my $bundle ( $self->get_document->get_bundles ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | ▶ | if ( $bundle eq $self ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | last BUNDLE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | $position++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 3 | $self->get_document->delete_tree($position); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 3 | bless $self, 'Treex::Core::Node::Removed'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # --------- ACCESS TO TREES ------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub get_all_trees { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_trees: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ($Treex::Core::Config::params_validate) { ## no critic (ProhibitPackageVars) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | pos_validated_list( \@_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | return () if !$self->{zones}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my @trees; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | foreach my $zone ( $self->{zones}->elements ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $structure = $zone->value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | foreach my $layer (Treex::Core::Types::layers()) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $layer = lc $layer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ( exists $structure->{trees}->{"${layer}_tree"} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | push @trees, $structure->{trees}->{"${layer}_tree"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | return @trees; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | ▶ | sub create_tree { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_tree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | my ( $language, $layer, $selector ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | { isa => 'Treex::Type::LangCode' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | { isa => 'Treex::Type::Selector', default => '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 4 | my $zone = $self->get_or_create_zone( $language, $selector ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | my $tree_root = $zone->create_tree($layer); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | return $tree_root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 5 | ▶ | sub get_tree { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_tree: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 5 | my ( $language, $layer, $selector ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | { isa => 'Treex::Type::LangCode' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | { isa => 'Treex::Type::Selector', default => '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 5 | my $zone = $self->get_zone( $language, $selector ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 5 | ▶ | log_fatal "Unavailable zone for selector=$selector language=$language\n" if !$zone; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 5 | return $zone->get_tree($layer); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 5 | ▶ | sub has_tree { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_tree: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 5 | my ( $language, $layer, $selector ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | { isa => 'Treex::Type::LangCode' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | { isa => 'Treex::Type::Layer' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | { isa => 'Treex::Type::Selector', default => '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | my $zone = $self->get_zone( $language, $selector ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | ▶ | return defined $zone && $zone->has_tree($layer); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $zone && $zone->has_tree($layer)
MC/DC50%1/2
defined $zone && $zone->has_tree($layer)
defined $zone
$zone->has_tree($layer)
Truth table66%2/3
A && B
A= defined $zoneB= $zone->has_tree($layer)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | ▶ | sub get_position { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_position: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # search for position of the bundle | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # (ineffective, because there's no caching of positions of bundles so far) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | my $position_of_reference; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | my $fsfile = $self->get_document->_pmldoc; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | foreach my $position ( 0 .. $fsfile->lastTreeNo ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | ▶ | if ( $fsfile->tree($position) eq $self ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | $position_of_reference = $position; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | ▶ | if ( !defined $position_of_reference ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | log_fatal "document structure inconsistency: can't detect position of bundle $self"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | return $position_of_reference; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # --------- ACCESS TO ATTRIBUTES ------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub get_attr { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_attr: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | my ($attr_name) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | { isa => 'Str' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | return $self->{$attr_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # ------- other ------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 40 | ▶ | sub following { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
following: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 40 | return Treex::Core::Node::following(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 34 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 34 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||