expressions

Tools for working with Boolean expressions.

expressions.bexpr module

Tools for interacting with Boolean expressions.

class tt.expressions.bexpr.BooleanExpression(raw_expr)

Bases: object

A class for parsing and holding information about a Boolean expression.

raw_expr

str

The raw string expression, to be parsed upon initialization.

symbols

List[str]

The list of unique symbols present in this expression, in the order of their first appearance in the expression.

tokens

List[str]

A list of strings, each element indicating a different token of the parsed expression.

postfix_tokens

List[str]

A list of strings, representing the tokens list converted to postfix form.

tree

tt.trees.BooleanExpressionTree

The expression tree representing the expression wrapped in this class, derived from the tokens parsed by this class.

evaluate(**kwargs)

Evaluate the Boolean expression for the passed keyword arguments.

This is a checked wrapper around the evaluate_unchecked function.

Parameters:

kwargs – Keys are names of symbols in this expression; the specified value for each of these keys will be substituted into the expression for evaluation.

Returns:

The Boolean result of evaluating the expression.

Return type:

bool

Raises:
  • ExtraSymbolError
  • InvalidBooleanValueError
  • MissingSymbolError

Note

See tt.utils.assertions.assert_all_valid_keys and tt.utils.assertions.assert_iterable_contains_all_expr_symbols for more information about the exceptions raised by this method.

evaluate_unchecked(**kwargs)

Evaluate the Boolean expression without checking the input.

Parameters:kwargs – Keys are names of symbols in this expression; the specified value for each of these keys will be substituted into the expression for evaluation.
Returns:The Boolean result of evaluating the expression.
Return type:bool