| 1 | package Treex::Tool::Parser::MSTperl::Config; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 3 | $Treex::Tool::Parser::MSTperl::Config::VERSION = '0.11949'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use autodie; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Treex::Tool::Parser::MSTperl::FeaturesControl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Treex::Tool::Parser::MSTperl::ModelAdditional; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # varied levels of debug info, | ||||||||||||||||||||||||||||
| 15 | # ranging from 0 (no debug info) | ||||||||||||||||||||||||||||
| 16 | # through 1 (progress messages - this is the default setting) | ||||||||||||||||||||||||||||
| 17 | # through 2, 3 and 4 to 5 (more and more debug info) | ||||||||||||||||||||||||||||
| 18 | 3 | has 'DEBUG' => ( | |||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||
| 20 | isa => 'Int', | ||||||||||||||||||||||||||||
| 21 | default => '1', | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Viterbi settings | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 3 | has 'SEQUENCE_BOUNDARY_LABEL' => ( | |||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||
| 28 | isa => 'Str', | ||||||||||||||||||||||||||||
| 29 | default => '###', | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 3 | has 'VITERBI_STATES_NUM_THRESHOLD' => ( | |||||||||||||||||||||||||||
| 33 | is => 'rw', | ||||||||||||||||||||||||||||
| 34 | isa => 'Int', | ||||||||||||||||||||||||||||
| 35 | default => 5, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # stopping criterion of EM algorithm (when the sum of change of smoothing | ||||||||||||||||||||||||||||
| 39 | # parameters is lower than the epsilon, the algorithm stops) | ||||||||||||||||||||||||||||
| 40 | 3 | has 'EM_EPSILON' => ( | |||||||||||||||||||||||||||
| 41 | is => 'rw', | ||||||||||||||||||||||||||||
| 42 | isa => 'Num', | ||||||||||||||||||||||||||||
| 43 | default => 0.00001, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # strmost sigmoidy | ||||||||||||||||||||||||||||
| 47 | 3 | has 'SIGM_LAMBDA' => ( | |||||||||||||||||||||||||||
| 48 | is => 'rw', | ||||||||||||||||||||||||||||
| 49 | isa => 'Num', | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # default => 0.0015, probably good for data as they used to be :-) | ||||||||||||||||||||||||||||
| 52 | default => 1, | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # added to emission probs to make them non-negative | ||||||||||||||||||||||||||||
| 56 | # has 'EMISSIONS_SHIFT' => ( | ||||||||||||||||||||||||||||
| 57 | # is => 'rw', | ||||||||||||||||||||||||||||
| 58 | # isa => 'Int', | ||||||||||||||||||||||||||||
| 59 | # default => 500, | ||||||||||||||||||||||||||||
| 60 | # ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # where in training data do heldout data for EM algorithm start | ||||||||||||||||||||||||||||
| 63 | # (a number between 0 and 1, eg. 0.75 means that first 75% of sentences | ||||||||||||||||||||||||||||
| 64 | # are training data and the last 25% are heldout data) | ||||||||||||||||||||||||||||
| 65 | 3 | has 'EM_heldout_data_at' => ( | |||||||||||||||||||||||||||
| 66 | is => 'rw', | ||||||||||||||||||||||||||||
| 67 | isa => 'Num', | ||||||||||||||||||||||||||||
| 68 | default => 0.9, | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 3 | has 'config_file' => ( | |||||||||||||||||||||||||||
| 72 | is => 'ro', | ||||||||||||||||||||||||||||
| 73 | isa => 'Str', | ||||||||||||||||||||||||||||
| 74 | required => '1', | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 3 | has 'unlabelledFeaturesControl' => ( | |||||||||||||||||||||||||||
| 78 | isa => 'Maybe[Treex::Tool::Parser::MSTperl::FeaturesControl]', | ||||||||||||||||||||||||||||
| 79 | is => 'rw', | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 3 | has 'labelledFeaturesControl' => ( | |||||||||||||||||||||||||||
| 83 | isa => 'Maybe[Treex::Tool::Parser::MSTperl::FeaturesControl]', | ||||||||||||||||||||||||||||
| 84 | is => 'rw', | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # has 'imlabelledFeaturesControl' => ( | ||||||||||||||||||||||||||||
| 88 | # isa => 'Maybe[Treex::Tool::Parser::MSTperl::FeaturesControl]', | ||||||||||||||||||||||||||||
| 89 | # is => 'rw', | ||||||||||||||||||||||||||||
| 90 | # ); | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # CONFIGURATION | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # only assigning is_member (as opposed to afun labelling) | ||||||||||||||||||||||||||||
| 95 | # has 'is_member_labelling' => ( | ||||||||||||||||||||||||||||
| 96 | # is => 'ro', | ||||||||||||||||||||||||||||
| 97 | # isa => 'Bool', | ||||||||||||||||||||||||||||
| 98 | # default => '0', | ||||||||||||||||||||||||||||
| 99 | # ); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # training mode or parsing mode | ||||||||||||||||||||||||||||
| 102 | 3 | has 'training' => ( | |||||||||||||||||||||||||||
| 103 | is => 'ro', | ||||||||||||||||||||||||||||
| 104 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 105 | default => '0', | ||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # (default is parsing mode) | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # has 'ord_field_index' => ( | ||||||||||||||||||||||||||||
| 111 | # is => 'rw', | ||||||||||||||||||||||||||||
| 112 | # isa => 'Int', | ||||||||||||||||||||||||||||
| 113 | # ); | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # just temporary before it is found out | ||||||||||||||||||||||||||||
| 116 | # which algorithm is the best one | ||||||||||||||||||||||||||||
| 117 | 3 | has 'labeller_algorithm' => ( | |||||||||||||||||||||||||||
| 118 | is => 'rw', | ||||||||||||||||||||||||||||
| 119 | isa => 'Int', | ||||||||||||||||||||||||||||
| 120 | default => '0', | ||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 3 | has 'parent_ord' => ( | |||||||||||||||||||||||||||
| 124 | is => 'rw', | ||||||||||||||||||||||||||||
| 125 | isa => 'Str', | ||||||||||||||||||||||||||||
| 126 | trigger => \&_parent_ord_set, | ||||||||||||||||||||||||||||
| 127 | ); | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # sets parent_ord_field_index | ||||||||||||||||||||||||||||
| 130 | 1 | ▶ | sub _parent_ord_set { | ||||||||||||||||||||||||||
|
Subroutine
_parent_ord_set: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 131 | 1 | my ( $self, $parent_ord ) = @_; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # set index of parent's ord field | ||||||||||||||||||||||||||||
| 134 | 1 | my $parent_ord_index = $self->field_name2index($parent_ord); | |||||||||||||||||||||||||||
| 135 | 1 | $self->parent_ord_field_index($parent_ord_index); | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | return; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 3 | has 'parent_ord_field_index' => ( | |||||||||||||||||||||||||||
| 141 | is => 'rw', | ||||||||||||||||||||||||||||
| 142 | isa => 'Int', | ||||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 3 | has 'label' => ( | |||||||||||||||||||||||||||
| 146 | is => 'rw', | ||||||||||||||||||||||||||||
| 147 | isa => 'Str', | ||||||||||||||||||||||||||||
| 148 | trigger => \&_label_set, | ||||||||||||||||||||||||||||
| 149 | ); | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | # sets label_field_index | ||||||||||||||||||||||||||||
| 152 | 1 | ▶ | sub _label_set { | ||||||||||||||||||||||||||
|
Subroutine
_label_set: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 153 | 1 | my ( $self, $label ) = @_; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # set index of label field | ||||||||||||||||||||||||||||
| 156 | 1 | my $label_index = $self->field_name2index($label); | |||||||||||||||||||||||||||
| 157 | 1 | $self->label_field_index($label_index); | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 1 | return; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 3 | has 'label_field_index' => ( | |||||||||||||||||||||||||||
| 163 | is => 'rw', | ||||||||||||||||||||||||||||
| 164 | isa => 'Maybe[Int]', | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # default => 'undef', | ||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # has 'ismember' => ( | ||||||||||||||||||||||||||||
| 170 | # is => 'rw', | ||||||||||||||||||||||||||||
| 171 | # isa => 'Str', | ||||||||||||||||||||||||||||
| 172 | # trigger => \&_ismember_set, | ||||||||||||||||||||||||||||
| 173 | # ); | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # sets ismember_field_index | ||||||||||||||||||||||||||||
| 176 | # sub _ismember_set { | ||||||||||||||||||||||||||||
| 177 | # my ( $self, $ismember ) = @_; | ||||||||||||||||||||||||||||
| 178 | # | ||||||||||||||||||||||||||||
| 179 | # # set index of ismember field | ||||||||||||||||||||||||||||
| 180 | # my $ismember_index = $self->field_name2index($ismember); | ||||||||||||||||||||||||||||
| 181 | # $self->ismember_field_index($ismember_index); | ||||||||||||||||||||||||||||
| 182 | # | ||||||||||||||||||||||||||||
| 183 | # return; | ||||||||||||||||||||||||||||
| 184 | # } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | # has 'ismember_field_index' => ( | ||||||||||||||||||||||||||||
| 187 | # is => 'rw', | ||||||||||||||||||||||||||||
| 188 | # isa => 'Maybe[Int]', | ||||||||||||||||||||||||||||
| 189 | # | ||||||||||||||||||||||||||||
| 190 | # # default => 'undef', | ||||||||||||||||||||||||||||
| 191 | # ); | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | has 'root_field_values' => ( | ||||||||||||||||||||||||||||
| 194 | is => 'rw', | ||||||||||||||||||||||||||||
| 195 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 196 | 1 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 197 | 3 | trigger => \&_root_field_values_set, | |||||||||||||||||||||||||||
| 198 | ); | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | # checks number of root field values | ||||||||||||||||||||||||||||
| 201 | 1 | ▶ | sub _root_field_values_set { | ||||||||||||||||||||||||||
|
Subroutine
_root_field_values_set: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 202 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | # check number of fields | ||||||||||||||||||||||||||||
| 205 | 1 | my $root_fields_count = scalar( @{ $self->root_field_values } ); | |||||||||||||||||||||||||||
| 206 | 1 | ▶ | if ( $root_fields_count != $self->field_names_count ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | croak "MSTperl config file error: " . | |||||||||||||||||||||||||||
| 208 | "Incorrect number of root field values ($root_fields_count), " . | ||||||||||||||||||||||||||||
| 209 | "must be same as number of field names (" . | ||||||||||||||||||||||||||||
| 210 | $self->field_names_count . ")!"; | ||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 1 | return; | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 3 | has 'number_of_iterations' => ( | |||||||||||||||||||||||||||
| 217 | isa => 'Int', | ||||||||||||||||||||||||||||
| 218 | is => 'rw', | ||||||||||||||||||||||||||||
| 219 | default => 3, | ||||||||||||||||||||||||||||
| 220 | ); | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 3 | has 'labeller_number_of_iterations' => ( | |||||||||||||||||||||||||||
| 223 | isa => 'Int', | ||||||||||||||||||||||||||||
| 224 | is => 'rw', | ||||||||||||||||||||||||||||
| 225 | default => 3, | ||||||||||||||||||||||||||||
| 226 | ); | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | # has 'imlabeller_number_of_iterations' => ( | ||||||||||||||||||||||||||||
| 229 | # isa => 'Int', | ||||||||||||||||||||||||||||
| 230 | # is => 'rw', | ||||||||||||||||||||||||||||
| 231 | # default => 3, | ||||||||||||||||||||||||||||
| 232 | # ); | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 3 | has 'use_edge_features_cache' => ( | |||||||||||||||||||||||||||
| 235 | is => 'rw', | ||||||||||||||||||||||||||||
| 236 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 237 | default => '0', | ||||||||||||||||||||||||||||
| 238 | ); | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 3 | has 'labeller_use_edge_features_cache' => ( | |||||||||||||||||||||||||||
| 241 | is => 'rw', | ||||||||||||||||||||||||||||
| 242 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 243 | default => '0', | ||||||||||||||||||||||||||||
| 244 | ); | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | # has 'imlabeller_use_edge_features_cache' => ( | ||||||||||||||||||||||||||||
| 247 | # is => 'rw', | ||||||||||||||||||||||||||||
| 248 | # isa => 'Bool', | ||||||||||||||||||||||||||||
| 249 | # default => '0', | ||||||||||||||||||||||||||||
| 250 | # ); | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | # using cache turned off to fit into RAM by default | ||||||||||||||||||||||||||||
| 253 | # turn on if training with a lot of RAM or on small training data | ||||||||||||||||||||||||||||
| 254 | # turned off when parsing (does not make any sense for parsing) | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | # Distance buckets | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | has 'distance_buckets' => ( | ||||||||||||||||||||||||||||
| 259 | is => 'rw', | ||||||||||||||||||||||||||||
| 260 | isa => 'ArrayRef[Int]', | ||||||||||||||||||||||||||||
| 261 | 1 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 262 | 3 | trigger => \&_distance_buckets_set, | |||||||||||||||||||||||||||
| 263 | ); | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | # sets distance2bucket, maxBucket and minBucket | ||||||||||||||||||||||||||||
| 266 | 1 | ▶ | sub _distance_buckets_set { | ||||||||||||||||||||||||||
|
Subroutine
_distance_buckets_set: called CC=8 SCAR=21.7
| |||||||||||||||||||||||||||||
| 267 | 1 | my ( $self, $distance_buckets ) = @_; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 1 | my %distance2bucket; | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | # find maximal bucket & partly fill %distance2bucket | ||||||||||||||||||||||||||||
| 272 | 1 | my $maxBucket = 0; | |||||||||||||||||||||||||||
| 273 | 1 | foreach my $bucket ( @{$distance_buckets} ) { | |||||||||||||||||||||||||||
| 274 | 6 | ▶ | if ( $distance2bucket{$bucket} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 275 | 0 | warn "Bucket '$bucket' is defined more than once; " . | |||||||||||||||||||||||||||
| 276 | "disregarding its later definitions.\n"; | ||||||||||||||||||||||||||||
| 277 | } elsif ( $bucket <= 0 ) { | ||||||||||||||||||||||||||||
| 278 | 0 | croak "MSTperl config file error: " . | |||||||||||||||||||||||||||
| 279 | "Error on bucket '$bucket' - " . | ||||||||||||||||||||||||||||
| 280 | "buckets must be positive integers."; | ||||||||||||||||||||||||||||
| 281 | } else { | ||||||||||||||||||||||||||||
| 282 | 6 | $distance2bucket{$bucket} = $bucket; | |||||||||||||||||||||||||||
| 283 | 6 | $distance2bucket{ -$bucket } = -$bucket; | |||||||||||||||||||||||||||
| 284 | 6 | ▶ | if ( $bucket > $maxBucket ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 6 | $maxBucket = $bucket; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | # set maxBucket and minBucket | ||||||||||||||||||||||||||||
| 291 | 1 | my $minBucket = -$maxBucket; | |||||||||||||||||||||||||||
| 292 | 1 | $self->maxBucket($maxBucket); | |||||||||||||||||||||||||||
| 293 | 1 | $self->minBucket($minBucket); | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | # fill %distance2bucket from minBucket to maxBucket | ||||||||||||||||||||||||||||
| 296 | 1 | ▶ | if ( !$distance2bucket{1} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 0 | warn "Bucket '1' is not defined, which does not make any sense; " . | |||||||||||||||||||||||||||
| 298 | "adding definition of bucket '1'.\n"; | ||||||||||||||||||||||||||||
| 299 | 0 | $distance2bucket{1} = 1; | |||||||||||||||||||||||||||
| 300 | 0 | $distance2bucket{-1} = -1; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | 1 | my $lastBucket = 1; | |||||||||||||||||||||||||||
| 303 | 1 | ▶ | for ( my $distance = 2; $distance < $maxBucket; $distance++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 8 | ▶ | if ( $distance2bucket{$distance} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | # the distance defines a bucket | ||||||||||||||||||||||||||||
| 307 | 4 | $lastBucket = $distance2bucket{$distance}; | |||||||||||||||||||||||||||
| 308 | } else { | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | # the distance falls into the highest lower bucket | ||||||||||||||||||||||||||||
| 311 | 4 | $distance2bucket{$distance} = $lastBucket; | |||||||||||||||||||||||||||
| 312 | 4 | $distance2bucket{ -$distance } = -$lastBucket; | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | 1 | $self->distance2bucket( \%distance2bucket ); | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 1 | return; | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | has 'distance2bucket' => ( | ||||||||||||||||||||||||||||
| 321 | is => 'rw', | ||||||||||||||||||||||||||||
| 322 | isa => 'HashRef[Int]', | ||||||||||||||||||||||||||||
| 323 | 1 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 324 | 3 | ); | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | # if mapping is not found in the hash, maxBucket or minBucket is used | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 3 | has 'maxBucket' => ( | |||||||||||||||||||||||||||
| 329 | isa => 'Int', | ||||||||||||||||||||||||||||
| 330 | is => 'rw', | ||||||||||||||||||||||||||||
| 331 | default => '9', | ||||||||||||||||||||||||||||
| 332 | ); | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | # any higher distance falls into this bucket | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 3 | has 'minBucket' => ( | |||||||||||||||||||||||||||
| 337 | isa => 'Int', | ||||||||||||||||||||||||||||
| 338 | is => 'rw', | ||||||||||||||||||||||||||||
| 339 | default => '-9', | ||||||||||||||||||||||||||||
| 340 | ); | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | # any lower distance falls into this bucket, distance is signed (ORD minus ord) | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | # FIELDS | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # field names (for conversion of field index to field name) | ||||||||||||||||||||||||||||
| 347 | has 'field_names' => ( | ||||||||||||||||||||||||||||
| 348 | is => 'rw', | ||||||||||||||||||||||||||||
| 349 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 350 | 1 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 351 | 3 | trigger => \&_field_names_set, | |||||||||||||||||||||||||||
| 352 | ); | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | # checks field_names, sets field_names_hash and field_indexes | ||||||||||||||||||||||||||||
| 355 | 1 | ▶ | sub _field_names_set { | ||||||||||||||||||||||||||
|
Subroutine
_field_names_set: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||
| 356 | 1 | my ( $self, $field_names ) = @_; | |||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 1 | my %field_names_hash; | |||||||||||||||||||||||||||
| 359 | my %field_indexes; | ||||||||||||||||||||||||||||
| 360 | 1 | ▶ | for ( my $index = 0; $index < scalar( @{$field_names} ); $index++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | 10 | my $field_name = $field_names->[$index]; | |||||||||||||||||||||||||||
| 362 | 10 | ▶ | if ( $field_names_hash{$field_name} ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 363 | 0 | croak "MSTperl config file error: " . | |||||||||||||||||||||||||||
| 364 | "Duplicate field name '$field_name'!"; | ||||||||||||||||||||||||||||
| 365 | } elsif ( $field_name ne lc($field_name) ) { | ||||||||||||||||||||||||||||
| 366 | 0 | croak "MSTperl config file error: " . | |||||||||||||||||||||||||||
| 367 | "Field name '$field_name' is not lowercase!"; | ||||||||||||||||||||||||||||
| 368 | } elsif ( !$field_name =~ /a-z/ ) { | ||||||||||||||||||||||||||||
| 369 | 0 | croak "MSTperl config file error: " . | |||||||||||||||||||||||||||
| 370 | "Field name '$field_name' does not contain " . | ||||||||||||||||||||||||||||
| 371 | "any character from [a-z]!"; | ||||||||||||||||||||||||||||
| 372 | } else { | ||||||||||||||||||||||||||||
| 373 | 10 | $field_names_hash{$field_name} = 1; | |||||||||||||||||||||||||||
| 374 | 10 | $field_indexes{$field_name} = $index; | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 1 | $self->field_names_count( scalar( @{$field_names} ) ); | |||||||||||||||||||||||||||
| 379 | 1 | $self->field_names_hash( \%field_names_hash ); | |||||||||||||||||||||||||||
| 380 | 1 | $self->field_indexes( \%field_indexes ); | |||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 1 | return; | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 3 | has 'field_names_count' => ( | |||||||||||||||||||||||||||
| 386 | is => 'rw', | ||||||||||||||||||||||||||||
| 387 | isa => 'Int', | ||||||||||||||||||||||||||||
| 388 | default => '0', | ||||||||||||||||||||||||||||
| 389 | ); | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | # 1 for each field name to easily check if a field name exists | ||||||||||||||||||||||||||||
| 392 | has 'field_names_hash' => ( | ||||||||||||||||||||||||||||
| 393 | is => 'rw', | ||||||||||||||||||||||||||||
| 394 | isa => 'HashRef[Str]', | ||||||||||||||||||||||||||||
| 395 | 1 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 396 | 3 | ); | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | # index of each field name in field_names | ||||||||||||||||||||||||||||
| 399 | # (for conversion of field name to field index) | ||||||||||||||||||||||||||||
| 400 | has 'field_indexes' => ( | ||||||||||||||||||||||||||||
| 401 | is => 'rw', | ||||||||||||||||||||||||||||
| 402 | isa => 'HashRef[Str]', | ||||||||||||||||||||||||||||
| 403 | 1 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 404 | 3 | ); | |||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 3 | has lossFunction => ( is => 'rw', isa => 'Str', default => '' ); | |||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 3 | has use_pmi => ( | |||||||||||||||||||||||||||
| 409 | is => 'rw', | ||||||||||||||||||||||||||||
| 410 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 411 | default => 0 | ||||||||||||||||||||||||||||
| 412 | ); | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 3 | has pmi_model_file => ( | |||||||||||||||||||||||||||
| 415 | is => 'rw', | ||||||||||||||||||||||||||||
| 416 | isa => 'Str', | ||||||||||||||||||||||||||||
| 417 | default => '' | ||||||||||||||||||||||||||||
| 418 | ); | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 3 | has pmi_model_format => ( | |||||||||||||||||||||||||||
| 421 | is => 'rw', | ||||||||||||||||||||||||||||
| 422 | isa => 'Str', | ||||||||||||||||||||||||||||
| 423 | default => 'tsv' | ||||||||||||||||||||||||||||
| 424 | ); | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 3 | has 'pmi_buckets' => ( | |||||||||||||||||||||||||||
| 427 | is => 'rw', | ||||||||||||||||||||||||||||
| 428 | isa => 'Maybe[ArrayRef[Int]]', | ||||||||||||||||||||||||||||
| 429 | default => undef, | ||||||||||||||||||||||||||||
| 430 | ); | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 3 | has use_cprob => ( | |||||||||||||||||||||||||||
| 433 | is => 'rw', | ||||||||||||||||||||||||||||
| 434 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 435 | default => 0 | ||||||||||||||||||||||||||||
| 436 | ); | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 3 | has cprob_model_file => ( | |||||||||||||||||||||||||||
| 439 | is => 'rw', | ||||||||||||||||||||||||||||
| 440 | isa => 'Str', | ||||||||||||||||||||||||||||
| 441 | default => '' | ||||||||||||||||||||||||||||
| 442 | ); | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 3 | has cprob_model_format => ( | |||||||||||||||||||||||||||
| 445 | is => 'rw', | ||||||||||||||||||||||||||||
| 446 | isa => 'Str', | ||||||||||||||||||||||||||||
| 447 | default => 'tsv' | ||||||||||||||||||||||||||||
| 448 | ); | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | 3 | has 'cprob_buckets' => ( | |||||||||||||||||||||||||||
| 451 | is => 'rw', | ||||||||||||||||||||||||||||
| 452 | isa => 'Maybe[ArrayRef[Int]]', | ||||||||||||||||||||||||||||
| 453 | default => undef, | ||||||||||||||||||||||||||||
| 454 | ); | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | # METHODS | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 1 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=21 SCAR=43.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 459 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 1 | ▶ | if ( $self->DEBUG >= 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 462 | 0 | print "Processing config file " . $self->config_file . "...\n"; | |||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | # check if file exists | ||||||||||||||||||||||||||||
| 466 | 1 | ▶ | unless ( -e $self->config_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | 0 | my $dir; | |||||||||||||||||||||||||||
| 468 | 0 | my ( $volume, $directory, $cfile ) = | |||||||||||||||||||||||||||
| 469 | File::Spec->splitpath( $self->config_file ); | ||||||||||||||||||||||||||||
| 470 | 0 | $dir = File::Spec->catpath( $volume, $directory, '' ); | |||||||||||||||||||||||||||
| 471 | 0 | my @files = (); | |||||||||||||||||||||||||||
| 472 | 0 | ▶ | opendir( my $dirhandle, $dir ) or croak $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 473 | 0 | ▶ | while ( my $file = readdir($dirhandle) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 474 | 0 | push @files, $file; | |||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | 0 | closedir($dirhandle); | |||||||||||||||||||||||||||
| 477 | 0 | croak "The config file $cfile does not exists!\n" . | |||||||||||||||||||||||||||
| 478 | "The directory $dir contains the following files: " . | ||||||||||||||||||||||||||||
| 479 | join ', ', @files; | ||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | 3 | ▶ | use YAML::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 482 | 1 | my $config = YAML::Tiny->new; | |||||||||||||||||||||||||||
| 483 | 1 | $config = YAML::Tiny->read( $self->config_file ); | |||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 1 | ▶ | if ( !$config ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | 0 | croak "MSTperl config file error: " . YAML::Tiny->errstr; | |||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | } else { | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | # fields to set, in the order in which they are to be set | ||||||||||||||||||||||||||||
| 491 | 1 | my @fields = ( | |||||||||||||||||||||||||||
| 492 | 'field_names', | ||||||||||||||||||||||||||||
| 493 | 'root_field_values', | ||||||||||||||||||||||||||||
| 494 | 'parent_ord', | ||||||||||||||||||||||||||||
| 495 | 'distance_buckets', | ||||||||||||||||||||||||||||
| 496 | 'label', | ||||||||||||||||||||||||||||
| 497 | 'lossFunction', | ||||||||||||||||||||||||||||
| 498 | 'use_pmi', | ||||||||||||||||||||||||||||
| 499 | 'pmi_model_file', | ||||||||||||||||||||||||||||
| 500 | 'pmi_model_format', | ||||||||||||||||||||||||||||
| 501 | 'pmi_buckets', | ||||||||||||||||||||||||||||
| 502 | 'use_cprob', | ||||||||||||||||||||||||||||
| 503 | 'cprob_model_file', | ||||||||||||||||||||||||||||
| 504 | 'cprob_model_format', | ||||||||||||||||||||||||||||
| 505 | 'cprob_buckets', | ||||||||||||||||||||||||||||
| 506 | 'use_edge_features_cache', | ||||||||||||||||||||||||||||
| 507 | 'labeller_use_edge_features_cache', | ||||||||||||||||||||||||||||
| 508 | 'number_of_iterations', | ||||||||||||||||||||||||||||
| 509 | 'labeller_number_of_iterations', | ||||||||||||||||||||||||||||
| 510 | 'labeller_algorithm', | ||||||||||||||||||||||||||||
| 511 | 'DEBUG', | ||||||||||||||||||||||||||||
| 512 | 'SEQUENCE_BOUNDARY_LABEL', | ||||||||||||||||||||||||||||
| 513 | 'VITERBI_STATES_NUM_THRESHOLD', | ||||||||||||||||||||||||||||
| 514 | 'EM_EPSILON', | ||||||||||||||||||||||||||||
| 515 | 'EM_heldout_data_at', | ||||||||||||||||||||||||||||
| 516 | ); | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | # name => required? | ||||||||||||||||||||||||||||
| 519 | 1 | my %required_fields = ( | |||||||||||||||||||||||||||
| 520 | 'field_names' => 1, | ||||||||||||||||||||||||||||
| 521 | 'root_field_values' => 1, | ||||||||||||||||||||||||||||
| 522 | 'parent_ord' => 1, | ||||||||||||||||||||||||||||
| 523 | 'distance_buckets' => 1, | ||||||||||||||||||||||||||||
| 524 | ); | ||||||||||||||||||||||||||||
| 525 | 1 | foreach my $field (@fields) { | |||||||||||||||||||||||||||
| 526 | 24 | ▶ | if ( $config->[0]->{$field} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 527 | 9 | $self->$field( $config->[0]->{$field} ); | |||||||||||||||||||||||||||
| 528 | } else { | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | # if required, then croak | ||||||||||||||||||||||||||||
| 531 | 15 | ▶ | if ( $required_fields{$field} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 532 | 0 | croak "MSTperl config file error:" | |||||||||||||||||||||||||||
| 533 | . "Field $field must be set!"; | ||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | # else OK (default value will be used) | ||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | # ignore some settings if in parsing-only mode | ||||||||||||||||||||||||||||
| 541 | 1 | ▶ | if ( !$self->training ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 542 | 1 | $self->use_edge_features_cache(0); | |||||||||||||||||||||||||||
| 543 | 1 | $self->labeller_use_edge_features_cache(0); | |||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | # unlabelled features | ||||||||||||||||||||||||||||
| 547 | 1 | ▶ | if ( $config->[0]->{features} && @{ $config->[0]->{features} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$config->[0]{"features"} and @{$config->[0]{"features"};}
MC/DC0%0/2
$config->[0]{"features"} and @{$config->[0]{"features"};}
$config->[0]{"features"}
@{$config->[0]{"features"};}
Truth table33%1/3
A and B
A= $config->[0]{"features"}B= @{$config->[0]{"features"};}
| |||||||||||||||||||||||||||||
| 548 | $self->unlabelledFeaturesControl( | ||||||||||||||||||||||||||||
| 549 | Treex::Tool::Parser::MSTperl::FeaturesControl->new( | ||||||||||||||||||||||||||||
| 550 | 'config' => $self, | ||||||||||||||||||||||||||||
| 551 | 'feature_codes_from_config' => $config->[0]->{features}, | ||||||||||||||||||||||||||||
| 552 | 1 | 'use_edge_features_cache' | |||||||||||||||||||||||||||
| 553 | => $self->use_edge_features_cache, | ||||||||||||||||||||||||||||
| 554 | ) | ||||||||||||||||||||||||||||
| 555 | ); | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | 1 | ▶ | if ( $self->use_pmi ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 558 | 0 | my $pmi_model = Treex::Tool::Parser::MSTperl::ModelAdditional->new( | |||||||||||||||||||||||||||
| 559 | config => $self, | ||||||||||||||||||||||||||||
| 560 | model_file => $self->pmi_model_file, | ||||||||||||||||||||||||||||
| 561 | model_format => $self->pmi_model_format, | ||||||||||||||||||||||||||||
| 562 | buckets => $self->pmi_buckets, | ||||||||||||||||||||||||||||
| 563 | ); | ||||||||||||||||||||||||||||
| 564 | 0 | my $result = $pmi_model->load(); | |||||||||||||||||||||||||||
| 565 | 0 | ▶ | if ($result) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 566 | 0 | $self->unlabelledFeaturesControl->pmi_model($pmi_model); | |||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | 1 | ▶ | if ( $self->use_cprob ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 571 | 0 | my $cprob_model = Treex::Tool::Parser::MSTperl::ModelAdditional->new( | |||||||||||||||||||||||||||
| 572 | config => $self, | ||||||||||||||||||||||||||||
| 573 | model_file => $self->cprob_model_file, | ||||||||||||||||||||||||||||
| 574 | model_format => $self->cprob_model_format, | ||||||||||||||||||||||||||||
| 575 | buckets => $self->cprob_buckets, | ||||||||||||||||||||||||||||
| 576 | ); | ||||||||||||||||||||||||||||
| 577 | 0 | my $result = $cprob_model->load(); | |||||||||||||||||||||||||||
| 578 | 0 | ▶ | if ($result) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 579 | 0 | $self->unlabelledFeaturesControl->cprob_model($cprob_model); | |||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | # labeller features | ||||||||||||||||||||||||||||
| 585 | 1 | ▶ | if ($config->[0]->{labeller_features} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$config->[0]{"labeller_features"} and @{$config->[0]{"labeller_features"};}
MC/DC0%0/2
$config->[0]{"labeller_features"} and @{$config->[0]{"labeller_features"};}
$config->[0]{"labeller_features"}
@{$config->[0]{"labeller_features"};}
Truth table33%1/3
A and B
A= $config->[0]{"labeller_features"}B= @{$config->[0]{"labeller_features"};}
| |||||||||||||||||||||||||||||
| 586 | 1 | && @{ $config->[0]->{labeller_features} } | |||||||||||||||||||||||||||
| 587 | ) | ||||||||||||||||||||||||||||
| 588 | { | ||||||||||||||||||||||||||||
| 589 | $self->labelledFeaturesControl( | ||||||||||||||||||||||||||||
| 590 | Treex::Tool::Parser::MSTperl::FeaturesControl->new( | ||||||||||||||||||||||||||||
| 591 | 'config' => $self, | ||||||||||||||||||||||||||||
| 592 | 'feature_codes_from_config' | ||||||||||||||||||||||||||||
| 593 | => $config->[0]->{labeller_features}, | ||||||||||||||||||||||||||||
| 594 | 1 | 'use_edge_features_cache' | |||||||||||||||||||||||||||
| 595 | => $self->labeller_use_edge_features_cache, | ||||||||||||||||||||||||||||
| 596 | ) | ||||||||||||||||||||||||||||
| 597 | ); | ||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | # imlabeller features | ||||||||||||||||||||||||||||
| 601 | # if ($config->[0]->{imlabeller_features} | ||||||||||||||||||||||||||||
| 602 | # && @{ $config->[0]->{imlabeller_features} } | ||||||||||||||||||||||||||||
| 603 | # ) | ||||||||||||||||||||||||||||
| 604 | # { | ||||||||||||||||||||||||||||
| 605 | # $self->imlabelledFeaturesControl( | ||||||||||||||||||||||||||||
| 606 | # Treex::Tool::Parser::MSTperl::FeaturesControl->new( | ||||||||||||||||||||||||||||
| 607 | # 'config' => $self, | ||||||||||||||||||||||||||||
| 608 | # 'feature_codes_from_config' | ||||||||||||||||||||||||||||
| 609 | # => $config->[0]->{imlabeller_features}, | ||||||||||||||||||||||||||||
| 610 | # 'use_edge_features_cache' | ||||||||||||||||||||||||||||
| 611 | # => $self->imlabeller_use_edge_features_cache, | ||||||||||||||||||||||||||||
| 612 | # ) | ||||||||||||||||||||||||||||
| 613 | # ); | ||||||||||||||||||||||||||||
| 614 | # } | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | 1 | ▶ | if (!$self->unlabelledFeaturesControl | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->unlabelledFeaturesControl or $self->labelledFeaturesControl
MC/DC0%0/2
$self->unlabelledFeaturesControl or $self->labelledFeaturesControl
$self->unlabelledFeaturesControl
$self->labelledFeaturesControl
Truth table33%1/3
A or B
A= $self->unlabelledFeaturesControlB= $self->labelledFeaturesControl
| |||||||||||||||||||||||||||||
| 617 | && !$self->labelledFeaturesControl | ||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | # && !$self->imlabelledFeaturesControl | ||||||||||||||||||||||||||||
| 620 | ) | ||||||||||||||||||||||||||||
| 621 | { | ||||||||||||||||||||||||||||
| 622 | 0 | croak "MSTperl config file error: No features set!"; | |||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | 1 | ▶ | if ( $self->DEBUG >= 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 628 | 0 | print "Done." . "\n"; | |||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||
| 631 | 1 | return; | |||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | 56 | ▶ | sub field_name2index { | ||||||||||||||||||||||||||
|
Subroutine
field_name2index: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 635 | 56 | my ( $self, $field_name ) = @_; | |||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | 56 | ▶ | if ( ref $field_name eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||
| 639 | # multiarg feature | ||||||||||||||||||||||||||||
| 640 | 14 | my @return; | |||||||||||||||||||||||||||
| 641 | 14 | foreach my $field ( @{$field_name} ) { | |||||||||||||||||||||||||||
| 642 | 12 | push @return, $self->field_name2index($field); | |||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||
| 644 | 14 | return [@return]; | |||||||||||||||||||||||||||
| 645 | } else { | ||||||||||||||||||||||||||||
| 646 | 42 | ▶ | if ( $self->field_names_hash->{$field_name} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | # everything OK -> return the field name | ||||||||||||||||||||||||||||
| 649 | 35 | return $self->field_indexes->{$field_name}; | |||||||||||||||||||||||||||
| 650 | } elsif ( $field_name =~ /^-?[0-9]+$/ ) { | ||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | # not an actual field name but an integer argument -> keep it | ||||||||||||||||||||||||||||
| 653 | 7 | return $field_name; | |||||||||||||||||||||||||||
| 654 | } else { | ||||||||||||||||||||||||||||
| 655 | 0 | croak "Unknown field '$field_name', quiting."; | |||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | 3 | 1; | |||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||
| 662 | __END__ | ||||||||||||||||||||||||||||