| 1 | package Treex::Core::Run; | ||||||||||||||||||||||||||||||||
| 2 | 2 | $Treex::Core::Run::VERSION = '2.20210102'; | |||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Treex::Core::Common; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Treex::Core; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MooseX::SemiAffordanceAccessor 0.09; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 2 | with 'MooseX::Getopt'; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | # TODO some of these modules might not be needed, check this | ||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use File::Path; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use File::Temp qw(tempdir); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use File::Which; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use List::MoreUtils qw(first_index); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use IO::Interactive; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Time::HiRes; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Sys::Hostname; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use File::Glob 'bsd_glob'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 2 | our @EXPORT_OK = q(treex); | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 2 | has 'save' => ( | |||||||||||||||||||||||||||||||
| 31 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 32 | cmd_aliases => 's', | ||||||||||||||||||||||||||||||||
| 33 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 34 | isa => 'Bool', | ||||||||||||||||||||||||||||||||
| 35 | default => 0, | ||||||||||||||||||||||||||||||||
| 36 | documentation => 'save all documents', | ||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | has 'quiet' => ( | ||||||||||||||||||||||||||||||||
| 40 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 41 | cmd_aliases => 'q', | ||||||||||||||||||||||||||||||||
| 42 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 43 | isa => 'Bool', | ||||||||||||||||||||||||||||||||
| 44 | default => 0, | ||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | trigger => sub { Treex::Core::Log::log_set_error_level('FATAL'); }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 46 | 2 | documentation => q{Warning, info and debug messages are suppressed. Only fatal errors are reported.}, | |||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 2 | has 'cleanup' => ( | |||||||||||||||||||||||||||||||
| 50 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 51 | is => 'rw', isa => 'Bool', default => 0, | ||||||||||||||||||||||||||||||||
| 52 | documentation => q{Delete all temporary files.}, | ||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | has 'error_level' => ( | ||||||||||||||||||||||||||||||||
| 56 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 57 | cmd_aliases => 'e', | ||||||||||||||||||||||||||||||||
| 58 | is => 'rw', isa => 'ErrorLevel', default => 'INFO', | ||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | trigger => sub { Treex::Core::Log::log_set_error_level( $_[1] ); }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 60 | 2 | documentation => q{Possible values: ALL, DEBUG, INFO, WARN, FATAL}, | |||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 2 | has 'lang' => ( | |||||||||||||||||||||||||||||||
| 64 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 65 | cmd_aliases => [ 'language', 'L' ], | ||||||||||||||||||||||||||||||||
| 66 | is => 'rw', isa => 'Str', | ||||||||||||||||||||||||||||||||
| 67 | documentation => q{shortcut for adding "Util::SetGlobal language=xy" at the beginning of the scenario}, | ||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 2 | has 'selector' => ( | |||||||||||||||||||||||||||||||
| 71 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 72 | cmd_aliases => 'S', | ||||||||||||||||||||||||||||||||
| 73 | is => 'rw', isa => 'Str', | ||||||||||||||||||||||||||||||||
| 74 | documentation => q{shortcut for adding "Util::SetGlobal selector=xy" at the beginning of the scenario}, | ||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 2 | has 'tokenize' => ( | |||||||||||||||||||||||||||||||
| 78 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 79 | cmd_aliases => 't', | ||||||||||||||||||||||||||||||||
| 80 | is => 'rw', isa => 'Bool', | ||||||||||||||||||||||||||||||||
| 81 | documentation => q{shortcut for adding "Read::Sentences W2A::Tokenize" at the beginning of the scenario (or W2A::XY::Tokenize if used with --lang=xy)}, | ||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | # treex -h should not print "Unknown option: h" before the usage. | ||||||||||||||||||||||||||||||||
| 86 | #has 'help' => ( | ||||||||||||||||||||||||||||||||
| 87 | # traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 88 | # cmd_aliases => 'h', | ||||||||||||||||||||||||||||||||
| 89 | # is => 'ro', isa => 'Bool', default => 0, | ||||||||||||||||||||||||||||||||
| 90 | # documentation => q{Print usage info}, | ||||||||||||||||||||||||||||||||
| 91 | #); | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 2 | has 'filenames' => ( | |||||||||||||||||||||||||||||||
| 94 | traits => ['NoGetopt'], | ||||||||||||||||||||||||||||||||
| 95 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 96 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||||||
| 97 | documentation => 'treex file names', | ||||||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 2 | has 'scenario' => ( | |||||||||||||||||||||||||||||||
| 101 | traits => ['NoGetopt'], | ||||||||||||||||||||||||||||||||
| 102 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 103 | isa => 'Treex::Core::Scenario', | ||||||||||||||||||||||||||||||||
| 104 | predicate => '_has_scenario', | ||||||||||||||||||||||||||||||||
| 105 | documentation => 'scenario object', | ||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 2 | has 'watch' => ( | |||||||||||||||||||||||||||||||
| 110 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 111 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 112 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 113 | documentation => 're-run when the given file is changed TODO better doc', | ||||||||||||||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 2 | has 'dump_scenario' => ( | |||||||||||||||||||||||||||||||
| 117 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 118 | cmd_aliases => 'd', | ||||||||||||||||||||||||||||||||
| 119 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 120 | isa => 'Bool', | ||||||||||||||||||||||||||||||||
| 121 | default => 0, | ||||||||||||||||||||||||||||||||
| 122 | documentation => 'Just dump (print to STDOUT) the given scenario and exit.', | ||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 2 | has 'dump_required_files' => ( | |||||||||||||||||||||||||||||||
| 126 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 127 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 128 | isa => 'Bool', | ||||||||||||||||||||||||||||||||
| 129 | default => 0, | ||||||||||||||||||||||||||||||||
| 130 | documentation => 'Just dump (print to STDOUT) files required by the given scenario and exit.', | ||||||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 2 | has 'cache' => ( | |||||||||||||||||||||||||||||||
| 134 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 135 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 136 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 137 | default => "", | ||||||||||||||||||||||||||||||||
| 138 | documentation => 'Use cache. Required memory is specified in format memcached,loading. Numbers are in GB.', | ||||||||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | has version => ( | ||||||||||||||||||||||||||||||||
| 142 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 143 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 144 | isa => 'Bool', | ||||||||||||||||||||||||||||||||
| 145 | default => 0, | ||||||||||||||||||||||||||||||||
| 146 | cmd_aliases => 'v', | ||||||||||||||||||||||||||||||||
| 147 | documentation => q(Print treex and perl version), | ||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | trigger => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 149 | 0 | print get_version(); | |||||||||||||||||||||||||||||||
| 150 | 0 | exit(); | |||||||||||||||||||||||||||||||
| 151 | }, | ||||||||||||||||||||||||||||||||
| 152 | 2 | ); | |||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | # | ||||||||||||||||||||||||||||||||
| 155 | # Parallel head execution options | ||||||||||||||||||||||||||||||||
| 156 | # TODO move them to Treex::Core::Parallel::Head | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | 2 | has 'forward_error_level' => ( | |||||||||||||||||||||||||||||||
| 159 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 160 | cmd_aliases => 'E', | ||||||||||||||||||||||||||||||||
| 161 | is => 'rw', isa => 'ErrorLevel', default => 'WARN', | ||||||||||||||||||||||||||||||||
| 162 | documentation => q{messages with this level or higher will be forwarded from the distributed jobs to the main STDERR}, | ||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 2 | has 'parallel' => ( | |||||||||||||||||||||||||||||||
| 167 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 168 | cmd_aliases => 'p', | ||||||||||||||||||||||||||||||||
| 169 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 170 | isa => 'Bool', | ||||||||||||||||||||||||||||||||
| 171 | default => 0, | ||||||||||||||||||||||||||||||||
| 172 | documentation => 'Parallelize the task on SGE cluster (using qsub).', | ||||||||||||||||||||||||||||||||
| 173 | ); | ||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | 2 | has 'jobs' => ( | |||||||||||||||||||||||||||||||
| 176 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 177 | cmd_aliases => 'j', | ||||||||||||||||||||||||||||||||
| 178 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 179 | isa => 'Int', | ||||||||||||||||||||||||||||||||
| 180 | default => 10, | ||||||||||||||||||||||||||||||||
| 181 | documentation => 'Number of jobs for parallelization, default 10. Requires -p.', | ||||||||||||||||||||||||||||||||
| 182 | ); | ||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | 2 | has 'local' => ( | |||||||||||||||||||||||||||||||
| 186 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 187 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 188 | isa => 'Bool', | ||||||||||||||||||||||||||||||||
| 189 | documentation => 'Run jobs locally (might help with multi-core machines). Requires -p.', | ||||||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 2 | has 'priority' => ( | |||||||||||||||||||||||||||||||
| 193 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 194 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 195 | isa => 'Int', | ||||||||||||||||||||||||||||||||
| 196 | default => -100, | ||||||||||||||||||||||||||||||||
| 197 | documentation => 'Priority for qsub, an integer in the range -1023 to 0 (or 1024 for admins), default=-100. Requires -p.', | ||||||||||||||||||||||||||||||||
| 198 | ); | ||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | 2 | has 'mem' => ( | |||||||||||||||||||||||||||||||
| 201 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 202 | cmd_aliases => [ 'm', 'memory' ], | ||||||||||||||||||||||||||||||||
| 203 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 204 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 205 | default => '2G', | ||||||||||||||||||||||||||||||||
| 206 | documentation => 'How much memory should be allocated for cluster jobs, default=2G. Requires -p. ' | ||||||||||||||||||||||||||||||||
| 207 | . 'Translates to "qsub -hard -l mem_free=$mem -l h_vmem=2*$mem -l act_mem_free=$mem". ' | ||||||||||||||||||||||||||||||||
| 208 | . 'Use --mem=0 and --qsub to set your own SGE settings (e.g. if act_mem_free is not available).', | ||||||||||||||||||||||||||||||||
| 209 | ); | ||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | 2 | has 'name' => ( | |||||||||||||||||||||||||||||||
| 212 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 213 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 214 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 215 | default => '', | ||||||||||||||||||||||||||||||||
| 216 | documentation => 'Prefix of submitted jobs. Requires -p. ' | ||||||||||||||||||||||||||||||||
| 217 | . 'Translates to "qsub -N $name-jobname".', | ||||||||||||||||||||||||||||||||
| 218 | ); | ||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||
| 220 | 2 | has 'queue' => ( | |||||||||||||||||||||||||||||||
| 221 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 222 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 223 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 224 | default => '', | ||||||||||||||||||||||||||||||||
| 225 | documentation => 'SGE queue. Translates to "qsub -q $queue".', | ||||||||||||||||||||||||||||||||
| 226 | ); | ||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | 2 | has 'qsub' => ( | |||||||||||||||||||||||||||||||
| 229 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 230 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 231 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 232 | default => '', | ||||||||||||||||||||||||||||||||
| 233 | documentation => 'Additional parameters passed to qsub. Requires -p. ' | ||||||||||||||||||||||||||||||||
| 234 | . 'See --priority and --mem. You can use e.g. --qsub="-q *@p*,*@s*" to use just machines p* and s*. ' | ||||||||||||||||||||||||||||||||
| 235 | . 'Or e.g. --qsub="-q *@!(twi*|pan*)" to skip twi* and pan* machines.', | ||||||||||||||||||||||||||||||||
| 236 | ); | ||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 2 | has 'workdir' => ( | |||||||||||||||||||||||||||||||
| 239 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 240 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 241 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 242 | default => './{NNN}-cluster-run-{XXXXX}', | ||||||||||||||||||||||||||||||||
| 243 | documentation => 'working directory for temporary files in parallelized processing; ' . | ||||||||||||||||||||||||||||||||
| 244 | 'one can create automatic directories by using patterns: ' . | ||||||||||||||||||||||||||||||||
| 245 | '{NNN} is replaced by an ordinal number with so many leading zeros to have length of the number of Ns, ' . | ||||||||||||||||||||||||||||||||
| 246 | '{XXXX} is replaced by a random string, whose length is the same as the number of Xs (min. 4). ' . | ||||||||||||||||||||||||||||||||
| 247 | 'If not specified, directories such as 001-cluster-run, 002-cluster-run etc. are created', | ||||||||||||||||||||||||||||||||
| 248 | ); | ||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | has 'sge_job_numbers' => ( | ||||||||||||||||||||||||||||||||
| 251 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 252 | traits => ['NoGetopt'], | ||||||||||||||||||||||||||||||||
| 253 | documentation => 'list of numbers of jobs executed on sge', | ||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 255 | 2 | ); | |||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||
| 257 | 2 | has 'survive' => ( | |||||||||||||||||||||||||||||||
| 258 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 259 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 260 | isa => 'Bool', | ||||||||||||||||||||||||||||||||
| 261 | default => 0, | ||||||||||||||||||||||||||||||||
| 262 | documentation => 'Continue collecting jobs\' outputs even if some of them crashed (risky, use with care!).', | ||||||||||||||||||||||||||||||||
| 263 | ); | ||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||
| 266 | # | ||||||||||||||||||||||||||||||||
| 267 | # Parallel node/worker execution options | ||||||||||||||||||||||||||||||||
| 268 | # TODO move them to Treex::Core::Parallel::Node | ||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | 2 | has 'jobindex' => ( | |||||||||||||||||||||||||||||||
| 271 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 272 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 273 | isa => 'Int', | ||||||||||||||||||||||||||||||||
| 274 | documentation => 'Not to be used manually. If number of jobs is set to J and modulo set to M, only I-th files fulfilling I mod J == M are processed.', | ||||||||||||||||||||||||||||||||
| 275 | ); | ||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | 2 | has 'outdir' => ( | |||||||||||||||||||||||||||||||
| 278 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 279 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 280 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 281 | documentation => 'Not to be used manually. Dictory for collecting standard and error outputs in parallelized processing.', | ||||||||||||||||||||||||||||||||
| 282 | ); | ||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 2 | has 'server' => ( | |||||||||||||||||||||||||||||||
| 285 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||
| 286 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 287 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 288 | default => '', | ||||||||||||||||||||||||||||||||
| 289 | documentation => 'Not to be used manually. Used to point parallel jobs to the head.', | ||||||||||||||||||||||||||||||||
| 290 | ); | ||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | # | ||||||||||||||||||||||||||||||||
| 293 | # | ||||||||||||||||||||||||||||||||
| 294 | # | ||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub _usage_format { | ||||||||||||||||||||||||||||||
|
Subroutine
_usage_format: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 297 | 0 | return "usage: %c %o scenario [-- treex_files]\nscenario is a sequence of blocks or *.scen files\noptions:"; | |||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | #gets info about version of treex and perl | ||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | sub get_version { | ||||||||||||||||||||||||||||||
|
Subroutine
get_version: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 302 | 0 | my $perl_v = $^V; | |||||||||||||||||||||||||||||||
| 303 | 0 | my $perl_x = $^X; | |||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | my $treex_v = $Treex::Core::Run::VERSION || 'DEV'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$Treex::Core::Run::VERSION || 'DEV'
MC/DC0%0/1
$Treex::Core::Run::VERSION || 'DEV'
$Treex::Core::Run::VERSION
Truth table0%0/2
A
A= $Treex::Core::Run::VERSION
| |||||||||||||||||||||||||||||||||
| 305 | 0 | my $treex_x = which('treex'); | |||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||
| 307 | # File::Which::which sometimes fails to found treex. | ||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | if ( !defined $treex_x ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 309 | 0 | chomp( $treex_x = `which treex 2> /dev/null` ); | |||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | $treex_x ||= '<treex not found in $PATH>'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$treex_x ||= "<treex not found in \$PATH>"
MC/DC0%0/1
$treex_x ||= "<treex not found in \$PATH>"
$treex_x
Truth table0%0/2
A
A= $treex_x
| |||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||
| 312 | 0 | my $version_string = <<"VERSIONS"; | |||||||||||||||||||||||||||||||
| 313 | Treex version: $treex_v from $treex_x | ||||||||||||||||||||||||||||||||
| 314 | Perl version: $perl_v from $perl_x | ||||||||||||||||||||||||||||||||
| 315 | VERSIONS | ||||||||||||||||||||||||||||||||
| 316 | 0 | return $version_string; | |||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||
| 321 | # more complicated tests on consistency of options will be place here | ||||||||||||||||||||||||||||||||
| 322 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||
| 324 | 0 | return; | |||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | sub _execute { | ||||||||||||||||||||||||||||||
|
Subroutine
_execute: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||
| 329 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ( $self->dump_scenario || $self->dump_required_files ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->dump_scenario or $self->dump_required_files
MC/DC0%0/2
$self->dump_scenario or $self->dump_required_files
$self->dump_scenario
$self->dump_required_files
Truth table0%0/3
A or B
A= $self->dump_scenarioB= $self->dump_required_files
| |||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | # If someone wants to run treex -d My::Block my_scen.scen | ||||||||||||||||||||||||||||||||
| 334 | 0 | my $scen_str = $self->_construct_scenario_string_with_quoted_whitespace(); | |||||||||||||||||||||||||||||||
| 335 | 0 | $self->set_scenario( Treex::Core::Scenario->new( scenario_string => $scen_str, runner => $self ) ); | |||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||
| 337 | # TODO: Do it properly - perhaps, add a Scenario option to not load all the blocks. | ||||||||||||||||||||||||||||||||
| 338 | # We cannot create the real scenario instance without loading all the blocks | ||||||||||||||||||||||||||||||||
| 339 | # However, since r6307 some Scenario's functions were changed to methods, so we must create a dummy instance. | ||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||
| 341 | #my @block_items = Treex::Core::Scenario::parse_scenario_string($scen_str); | ||||||||||||||||||||||||||||||||
| 342 | #my @block_items = $dummy_scenario->parse_scenario_string($scen_str); | ||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if ( $self->dump_scenario ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 345 | 0 | print "# Full Scenario generated by 'treex --dump_scenario' on " . localtime() . "\n"; | |||||||||||||||||||||||||||||||
| 346 | 0 | print $self->scenario->construct_scenario_string( multiline => 1 ), "\n"; | |||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if ( $self->dump_required_files ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 350 | 0 | print "# Required files generated by 'treex --dump_required_files' on " . localtime() . "\n"; | |||||||||||||||||||||||||||||||
| 351 | 0 | print join "\n", $self->scenario->get_required_files(), "\n"; | |||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||
| 353 | 0 | exit; | |||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if ( $self->dump_required_files ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||
| 358 | 0 | my $scen_str = join ' ', @{ $self->extra_argv }; | |||||||||||||||||||||||||||||||
| 359 | 0 | $self->set_scenario( Treex::Core::Scenario->new( scenario_string => $scen_str, runner => $self ) ); | |||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||
| 361 | 0 | print "# Required files generated by 'treex --dump_required_files' on " . localtime() . "\n"; | |||||||||||||||||||||||||||||||
| 362 | 0 | print join "\n", $self->scenario->get_required_files(), "\n"; | |||||||||||||||||||||||||||||||
| 363 | 0 | exit; | |||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||
| 365 | 0 | my $done = 0; | |||||||||||||||||||||||||||||||
| 366 | 0 | my $time; | |||||||||||||||||||||||||||||||
| 367 | 0 | my $watch = $self->watch; | |||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if ( defined $watch ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | log_fatal "Watch file '$watch' does not exists" if !-f $watch; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 371 | 0 | $time = ( stat $watch )[9]; | |||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | while ( !$done ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||
| 376 | 0 | $self->_execute_scenario(); | |||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||
| 378 | 0 | $done = 1; | |||||||||||||||||||||||||||||||
| 379 | 0 | my $info_written = 0; | |||||||||||||||||||||||||||||||
| 380 | WATCH_CHANGE: | ||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | while ( defined $watch && -f $watch ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $watch and -f $watch
MC/DC0%0/2
defined $watch and -f $watch
defined $watch
-f $watch
Truth table0%0/3
A and B
A= defined $watchB= -f $watch
| |||||||||||||||||||||||||||||||||
| 382 | 0 | my $new_time = ( stat $watch )[9]; | |||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if ( $new_time > $time ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 384 | 0 | $time = $new_time; | |||||||||||||||||||||||||||||||
| 385 | 0 | $done = 0; | |||||||||||||||||||||||||||||||
| 386 | 0 | last WATCH_CHANGE; | |||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if ( !$info_written ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 389 | 0 | log_info "Watching '$watch' file. Touch it to re-run, delete to quit."; | |||||||||||||||||||||||||||||||
| 390 | 0 | $info_written = 1; | |||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||
| 392 | 0 | sleep 1; | |||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||
| 395 | 0 | return; | |||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||
| 398 | 2 | my %READER_FOR = ( | |||||||||||||||||||||||||||||||
| 399 | 'treex' => 'Treex', | ||||||||||||||||||||||||||||||||
| 400 | 'treex.gz' => 'Treex', | ||||||||||||||||||||||||||||||||
| 401 | 'txt' => 'Text', | ||||||||||||||||||||||||||||||||
| 402 | 'txt.gz' => 'Text', | ||||||||||||||||||||||||||||||||
| 403 | 'streex' => 'Treex', | ||||||||||||||||||||||||||||||||
| 404 | 'mrg' => 'PennMrg', | ||||||||||||||||||||||||||||||||
| 405 | 'mrg.gz' => 'PennMrg', | ||||||||||||||||||||||||||||||||
| 406 | 'tag' => 'CdtTag', | ||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||
| 408 | # TODO: | ||||||||||||||||||||||||||||||||
| 409 | # conll => 'Conll', | ||||||||||||||||||||||||||||||||
| 410 | # plsgz => 'Plsgz', | ||||||||||||||||||||||||||||||||
| 411 | # tmt | ||||||||||||||||||||||||||||||||
| 412 | ); | ||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | 13 | ▶ | sub _get_reader_name_for { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_reader_name_for: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 415 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||
| 416 | 13 | my @names = @_; | |||||||||||||||||||||||||||||||
| 417 | 13 | my $base_re = join( '|', keys %READER_FOR ); | |||||||||||||||||||||||||||||||
| 418 | 13 | my $re = qr{\.($base_re)$}; | |||||||||||||||||||||||||||||||
| 419 | 13 | my @extensions; | |||||||||||||||||||||||||||||||
| 420 | my $first; | ||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||
| 422 | 13 | foreach my $name (@names) { | |||||||||||||||||||||||||||||||
| 423 | 21 | ▶ | if ( $name =~ /$re/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 424 | 17 | my $current = $1; | |||||||||||||||||||||||||||||||
| 425 | 17 | $current =~ s/\.gz$//; | |||||||||||||||||||||||||||||||
| 426 | 17 | ▶ | if ( !defined $first ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 427 | 9 | $first = $current; | |||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||
| 429 | 17 | ▶ | if ( $current ne $first ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 430 | 1 | log_fatal 'All files (' . join( ',', @names ) . ') must have the same extension' . "\n" . | |||||||||||||||||||||||||||||||
| 431 | " current = $current\n" . | ||||||||||||||||||||||||||||||||
| 432 | " first = $first\n" . | ||||||||||||||||||||||||||||||||
| 433 | " curname = $name"; | ||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||
| 435 | 16 | push @extensions, $current; | |||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||
| 437 | else { | ||||||||||||||||||||||||||||||||
| 438 | 4 | log_fatal 'Files (' . join( ',', @names ) . ') must have extensions'; | |||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||
| 441 | 8 | my $r = $READER_FOR{$first}; | |||||||||||||||||||||||||||||||
| 442 | 8 | ▶ | log_fatal "There is no DocumentReader implemented for extension '$first'" if !$r; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 443 | 7 | return "Read::$r"; | |||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||
| 446 | # This is where the main work is done. It is overridden in parallel execution. | ||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | sub _execute_scenario { | ||||||||||||||||||||||||||||||
|
Subroutine
_execute_scenario: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 448 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||
| 450 | 0 | log_info "Local (single-process) execution."; | |||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||
| 452 | 0 | $self->_init_scenario(); | |||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||
| 454 | 0 | my $scenario = $self->scenario; | |||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||
| 456 | 0 | my $runnin_started = time; | |||||||||||||||||||||||||||||||
| 457 | 0 | $scenario->run(); | |||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||
| 459 | 0 | log_info "Running the scenario took " . ( time - $runnin_started ) . " seconds"; | |||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||
| 461 | 0 | return; | |||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||
| 464 | # Parameters can contain whitespaces that should be preserved | ||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | sub _construct_scenario_string_with_quoted_whitespace { | ||||||||||||||||||||||||||||||
|
Subroutine
_construct_scenario_string_with_quoted_whitespace: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 466 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 467 | 0 | my @arguments; | |||||||||||||||||||||||||||||||
| 468 | 0 | foreach my $arg ( @{ $self->extra_argv } ) { | |||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | if ( $arg =~ /([^=\s]+)=(.*\s.*)$/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 470 | 0 | my ( $name, $value ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||
| 471 | 0 | $value =~ s/'/\\'/g; | |||||||||||||||||||||||||||||||
| 472 | 0 | push @arguments, qq($name='$value'); | |||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||
| 474 | else { | ||||||||||||||||||||||||||||||||
| 475 | 0 | push @arguments, $arg; | |||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||
| 478 | 0 | return join ' ', @arguments; | |||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | sub _init_scenario { | ||||||||||||||||||||||||||||||
|
Subroutine
_init_scenario: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||
| 482 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||
| 484 | 0 | my $scen_str = $self->_construct_scenario_string_with_quoted_whitespace(); | |||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | # some command line options are just shortcuts for blocks; the blocks are added to the scenario now | ||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | if ( $self->filenames ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 488 | 0 | my $reader = $self->_get_reader_name_for( @{ $self->filenames } ); | |||||||||||||||||||||||||||||||
| 489 | 0 | log_info "Block $reader added to the beginning of the scenario."; | |||||||||||||||||||||||||||||||
| 490 | 0 | $scen_str = "$reader from=" . join( ',', @{ $self->filenames } ) . " $scen_str"; | |||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | if ( $self->save ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 494 | 0 | log_info "Block Write::Treex added to the end of the scenario."; | |||||||||||||||||||||||||||||||
| 495 | 0 | $scen_str .= ' Write::Treex'; | |||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | if ( $self->tokenize ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 499 | 0 | my $tokenizer = 'W2A::Tokenize'; | |||||||||||||||||||||||||||||||
| 500 | 0 | my $lang = $self->lang; | |||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | if ($lang && $lang ne 'all'){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$lang and $lang ne "all"
MC/DC0%0/2
$lang and $lang ne "all"
$lang
$lang ne "all"
Truth table0%0/3
A and B
A= $langB= $lang ne "all"
| |||||||||||||||||||||||||||||||||
| 502 | 0 | my $module = 'Treex::Block::W2A::' . uc($lang) . '::Tokenize'; | |||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | if (eval "use $module;1"){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 504 | 0 | $tokenizer = 'W2A::' . uc($lang) . '::Tokenize'; | |||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||
| 507 | 0 | $scen_str = "Read::Sentences $tokenizer $scen_str"; | |||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | if ( $self->lang ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 511 | 0 | $scen_str = 'Util::SetGlobal language=' . $self->lang . " $scen_str"; | |||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | if ( $self->selector ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 515 | 0 | $scen_str = 'Util::SetGlobal selector=' . $self->selector . " $scen_str"; | |||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||
| 518 | 0 | my $loading_started = time; | |||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | if ( $self->_has_scenario ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 520 | 0 | $self->scenario->restart(); | |||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||
| 522 | else { | ||||||||||||||||||||||||||||||||
| 523 | 0 | $self->set_scenario( Treex::Core::Scenario->new( from_string => $scen_str, runner => $self ) ); | |||||||||||||||||||||||||||||||
| 524 | 0 | $self->scenario->load_blocks; | |||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||
| 527 | 0 | my $loading_ended = time; | |||||||||||||||||||||||||||||||
| 528 | 0 | log_info "Loading the scenario took " . ( $loading_ended - $loading_started ) . " seconds"; | |||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||
| 530 | 0 | return; | |||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||
| 534 | # A factory subroutine, creating the right Treex object for the job. | ||||||||||||||||||||||||||||||||
| 535 | # (local single-process: Treex::Core::Run, parallel processing head: Treex::Parallel::Head, | ||||||||||||||||||||||||||||||||
| 536 | # parallel processing worker node: Treex::Parallel::Node) | ||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | sub treex { | ||||||||||||||||||||||||||||||
|
Subroutine
treex: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||
| 539 | # ref to array of arguments, or a string containing all arguments as on the command line | ||||||||||||||||||||||||||||||||
| 540 | 0 | my $arguments = shift; | |||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | if ( ref($arguments) eq 'ARRAY' && scalar @$arguments > 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $arguments eq "ARRAY" and scalar @$arguments > 0
MC/DC0%0/2
ref $arguments eq "ARRAY" and scalar @$arguments > 0
ref $arguments eq "ARRAY"
scalar @$arguments > 0
Truth table0%0/3
A and B
A= ref $arguments eq "ARRAY"B= scalar @$arguments > 0
| |||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | my $idx = first_index { $_ eq '--' } @$arguments; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 544 | 0 | my %args = ( argv => $arguments ); | |||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | if ( $idx != -1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 546 | 0 | $args{filenames} = [ splice @$arguments, $idx + 1 ]; | |||||||||||||||||||||||||||||||
| 547 | 0 | pop @$arguments; # delete "--" | |||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||
| 549 | 0 | my $runner; | |||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | if (any { $_ =~ /^--jobindex/ } @$arguments){ | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 552 | 0 | require Treex::Core::Parallel::Node; | |||||||||||||||||||||||||||||||
| 553 | 0 | $runner = Treex::Core::Parallel::Node->new_with_options( \%args ); | |||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | elsif (any { $_ =~ /^(--parallel|-p|-pj\d+)$/ } @$arguments){ | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 556 | 0 | require Treex::Core::Parallel::Head; | |||||||||||||||||||||||||||||||
| 557 | 0 | $runner = Treex::Core::Parallel::Head->new_with_options( \%args ); | |||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||
| 559 | else { | ||||||||||||||||||||||||||||||||
| 560 | 0 | $runner = Treex::Core::Run->new_with_options( \%args ); | |||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||
| 562 | 0 | $runner->_execute(); | |||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||
| 566 | ▶ | elsif ( defined $arguments && ref($arguments) ne 'ARRAY' ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $arguments and ref $arguments ne "ARRAY"
MC/DC0%0/2
defined $arguments and ref $arguments ne "ARRAY"
defined $arguments
ref $arguments ne "ARRAY"
Truth table0%0/3
A and B
A= defined $argumentsB= ref $arguments ne "ARRAY"
| |||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | treex( [ grep { defined $_ && $_ ne '' } split( /\s/, $arguments ) ] ); | ||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $_ && $_ ne ''
MC/DC0%0/2
defined $_ && $_ ne ''
defined $_
$_ ne ''
Truth table0%0/3
A && B
A= defined $_B= $_ ne ''
| |||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||
| 570 | else { | ||||||||||||||||||||||||||||||||
| 571 | 0 | treex('--help'); | |||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||
| 573 | #log_fatal 'Unspecified arguments for running treex.'; | ||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||
| 575 | 0 | return; | |||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||
| 578 | 2 | 1; | |||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||
| 580 | __END__ | ||||||||||||||||||||||||||||||||