ssg.boolean_expression module
Common functions for Boolean Expressions
- class ssg.boolean_expression.Algebra(symbol_cls, function_cls)[source]
Bases:
BooleanAlgebraBase class for boolean algebra.
The Algebra class parses and evaluates boolean expressions, where operators can be any combination of “~, &, |, !, *, +, not, and, or” and variable symbols can contain version specifiers as described in PEP440 and PEP508. - No white space is allowed inside specifier expressions. - The ~= specifier operator is not supported.
Limitations: - no white space is allowed inside specifier expressions; - ~= specifier operator is not supported.
Example
“(oranges>=2.0.8,<=5 | fried[banana]) and !pie[apple]”
- symbol_cls
The class used for symbols in the boolean expressions.
- Type:
class
- function_cls
The class used for functions in the boolean expressions.
- Type:
class
- class ssg.boolean_expression.Function(*args)[source]
Bases:
FunctionBase class for boolean functions.
This class should be subclassed and passed to the Algebra as function_cls to enrich expression elements with domain-specific methods.
- as_id()[source]
Generate a string representation of the boolean expression.
This method constructs a unique identifier for the boolean expression by recursively calling as_id on its arguments and combining them with the appropriate boolean operator.
- Returns:
- A string representing the boolean expression. If the expression is a negation, it
returns ‘not_’ followed by the identifier of the negated argument. If the expression is a conjunction or disjunction, it returns the identifiers of the arguments joined by ‘_and_’ or ‘_or_’.
- Return type:
str
- class ssg.boolean_expression.Symbol(obj)[source]
Bases:
SymbolSymbol class represents a boolean symbol with domain-specific methods.
This class should be subclassed and passed to the Algebra as symbol_cls to enrich expression elements with domain-specific methods.
- requirement
The requirement object associated with the symbol.
- obj
Alias for the requirement attribute.
- property arg
- property name