quast_decisiontree.core.query
quast_decisiontree.core.query
logger
module-attribute
logger = logging.getLogger('dt_logger')
standard_abort_message
module-attribute
standard_abort_message = (
"Do you want to exit the decisiontree?"
)
Query
Bases: ABC
parent class for all user inputs
Source code in src/quast_decisiontree/core/query.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
input
input(mode=None)
checks whether the query should be executed and collects input if that is the case
Source code in src/quast_decisiontree/core/query.py
39 40 41 42 43 | |
input_raw
abstractmethod
input_raw()
gets correct user input and returns it
Source code in src/quast_decisiontree/core/query.py
45 46 47 | |
set_default
set_default(default)
sets the default value for the query. For convenience, it doesn't change anything if None is passed as default argument
Source code in src/quast_decisiontree/core/query.py
57 58 59 60 61 62 63 64 | |
input_or_def
input_or_def(mode=None, prefix_text_if_def='')
Source code in src/quast_decisiontree/core/query.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
print_def
print_def()
prints the default value if there is one
Source code in src/quast_decisiontree/core/query.py
85 86 87 88 89 90 91 | |
replace_with_def
replace_with_def(user_val)
returns the input if it's not the empty string or no default is set, and the default value otherwise
Source code in src/quast_decisiontree/core/query.py
93 94 95 96 97 98 99 100 101 102 | |
input_w_def
input_w_def(replace_default=True)
Requests input while distinguishing whether a default value exists or not. The behavior is as follows:
if a default value exists and is not None
- empty input string: return default value if replace_default is True, and the empty string otherwise
- input "exit": raise a QueryAbortError
- any other input is directly returned
if no default value exists or default value is None
- input "exit": raise a QueryAbortError
- any other input is directly returned
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
replace_default
|
bool
|
If a default value exists, determines whether or not the default value or the empty string will be returned. This is useful if you need to distinguish from outside the function whether the user provided default input (empty string) or manually typed the same value as default. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
the input by the user, or default value |
Source code in src/quast_decisiontree/core/query.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
input_or_finish
input_or_finish()
raises an InputFinishedTrigger if an empty string is entered
Source code in src/quast_decisiontree/core/query.py
144 145 146 147 148 149 150 151 | |
MultiChoiceQuery
Bases: Query
multiple choice question / menu selection
Source code in src/quast_decisiontree/core/query.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
name
instance-attribute
name = name
options
instance-attribute
options = answers
question
instance-attribute
question = question
__init__
__init__(question, answers, name='', default='')
creates a multiple choice query. The user will select one of more options from the dictionary provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
The question to be asked to the user. |
required |
answers
|
dict
|
The possible answers as a dictionary {key : description} where key is a short dictionary key the user is expected to type, and description a description of the associated option. |
required |
name
|
str
|
The name of the query. Defaults to "". |
''
|
default
|
Optional[str]
|
a possible default value, must be contained in answers.keys(). If the user hits enter without typing other input, it will be replaced with the default key. Defaults to "". |
''
|
Source code in src/quast_decisiontree/core/query.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
input_raw
input_raw()
presents the user with the options and requests a key while also allowing to abort the script
Source code in src/quast_decisiontree/core/query.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
StringQuery
Bases: Query
string input
Source code in src/quast_decisiontree/core/query.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
name
instance-attribute
name = name
question
instance-attribute
question = question
__init__
__init__(question, name='', default='')
creates a query asking for input with a possible default value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
the question to print to the user |
required |
name
|
str
|
A possible name of the query. Defaults to "". |
''
|
default
|
str
|
the default string provided if the user hits enter. |
''
|
Source code in src/quast_decisiontree/core/query.py
227 228 229 230 231 232 233 234 235 236 237 238 | |
append_to_question
append_to_question(text, sep='\n')
Source code in src/quast_decisiontree/core/query.py
240 241 | |
input_raw
input_raw()
Source code in src/quast_decisiontree/core/query.py
243 244 245 246 247 248 249 250 | |
PathQuery
Bases: StringQuery
input of a file or directory path
Source code in src/quast_decisiontree/core/query.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
must_exist
instance-attribute
must_exist = must_exist
__init__
__init__(question, must_exist=True, name='', default='')
Creates a special StringQuery asking for a path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
the question to print to the user |
required |
must_exist
|
bool
|
whether the path needs to exists, other paths will be rejected. Defaults to True. |
True
|
name
|
str
|
A possible name of the query. Defaults to "". |
''
|
default
|
str
|
A possible default path provided if the user hits enter. Defaults to "". |
''
|
Source code in src/quast_decisiontree/core/query.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
input_raw
input_raw()
Source code in src/quast_decisiontree/core/query.py
273 274 275 276 277 278 279 280 281 282 283 | |
IntQuery
Bases: StringQuery
int input
Source code in src/quast_decisiontree/core/query.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
input_raw
input_raw()
Source code in src/quast_decisiontree/core/query.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
FloatQuery
Bases: StringQuery
int input
Source code in src/quast_decisiontree/core/query.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
input_raw
input_raw()
Source code in src/quast_decisiontree/core/query.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
QueryTree
tree structure for queries to allow branching and conditional execution
Source code in src/quast_decisiontree/core/query.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
queries
instance-attribute
queries = queries
answers
instance-attribute
answers = dict(
zip(
[(query.name) for query in (self.queries)],
[None] * len(queries),
strict=False,
)
)
title
instance-attribute
title = title
__init__
__init__(queries, conditions=None, title=None)
constructs a query tree
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queries
|
list
|
a list of queries (subclass instances of Query) |
required |
conditions
|
list
|
a list of conditions of the same length. Each condition is a callable condition(answers) where answers is the dict of responses collected so far, keyed by query name (unanswered/skipped entries are None); None means always-true. |
None
|
title
|
(optional, str)
|
The title of the full tree |
None
|
Source code in src/quast_decisiontree/core/query.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
set_conditions
set_conditions(conditions)
Sets the per-query conditions.
Accepted forms (robust to list vs. tuple): - None: reset every condition to always-true. - a sequence with one entry per query, each callable or None. - a targeted (index, condition) pair, identified by an integer first element, replacing a single query's condition.
Source code in src/quast_decisiontree/core/query.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
input
input()
executes the queries in the tree and returns the collected answers.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
answers keyed by query name. Queries whose condition evaluates
falsy are skipped and keep their pre-seeded |
Source code in src/quast_decisiontree/core/query.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
HyperParamQuery
Bases: Query
asks for a hyperparameter value
Source code in src/quast_decisiontree/core/query.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
hyperparameter
instance-attribute
hyperparameter = hyperparameter
name
instance-attribute
name = hyperparameter.name
has_default
instance-attribute
has_default = self.hyperparameter.has_default
default
instance-attribute
default = self.hyperparameter.default
check_input
instance-attribute
check_input = self.hyperparameter._check_single_value
__init__
__init__(hyperparameter)
Source code in src/quast_decisiontree/core/query.py
434 435 436 437 438 439 440 | |
input_raw
input_raw()
collects input for the hyperparameter
Source code in src/quast_decisiontree/core/query.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
print_sep
print_sep(width=SEPARATOR_WIDTH)
Source code in src/quast_decisiontree/core/query.py
32 33 | |
print_query_line
print_query_line(
key, val, key_len=QUERY_KEY_WIDTH, ind=None
)
prints the line of a multiple-choice query
Source code in src/quast_decisiontree/core/query.py
154 155 156 157 158 159 | |
check_exit
check_exit(user_value)
Source code in src/quast_decisiontree/core/query.py
162 163 164 | |
always_true_if_none
always_true_if_none(element)
Source code in src/quast_decisiontree/core/query.py
327 328 329 330 331 | |