ahbicht package

Subpackages

Submodules

ahbicht.condition_node_builder module

Module for taking all the condition keys of a condition expression and building their respective ConditionNodes. If necessary it evaluates the needed attributes.

class ahbicht.condition_node_builder.ConditionNodeBuilder(condition_keys: list[str], ahb_context: AhbContext)[source]

Bases: object

Builds ConditionNodes for the given condition_keys by separating them into their respective types and evaluating the necessary attributes. It distinguishes between requirement constraint evaluation and format constraint evaluation.

async requirement_content_evaluation_for_all_condition_keys() dict[str, RequirementConstraint | UnevaluatedFormatConstraint | Hint][source]

Gets input nodes for all condition keys.

ahbicht.condition_node_distinction module

A module to allow easy distinction between different types of condition nodes (by mapping their integer key)

ahbicht.condition_node_distinction.PACKAGE_1P_HINT_KEY: str = '9999'

A special, hardcoded condition key that is used when resolving the package ‘1P’.

Background: Package ‘1P’ is defined to always resolve to a hint node, regardless of any PackageResolver configuration. Unlike other packages (e.g. ‘2P’, ‘3P’, …) which are resolved dynamically via a PackageResolver that maps package keys to condition expressions, ‘1P’ is treated as a special case and directly converted to a hint.

Why we chose this approach:

  1. Hint condition keys are normally in the range 500-900 (as defined by EDI@Energy “Allgemeine Festlegungen”).

  2. We cannot use any key in the 500-900 range because those keys may already be taken by actual hints defined in the AHB documents. Using an existing key would cause conflicts.

  3. By using 9999 (a number well outside all defined ranges), we ensure no collision with any existing condition keys while still being able to leverage the existing hint infrastructure.

  4. This constant is used in multiple places: in derive_condition_node_type() to recognize 9999 as a HINT type, in PackageExpansionTransformer to resolve ‘1P’ to this key, and in HintsProvider implementations to provide a hardcoded hint text for this key.

The hint text for this key is hardcoded as “Hinweis: Das ist das Standardpaket, wenn keine Bedingung zum Tragen kommt, z.B. im COM-Segment.” in the HintsProvider base class.

ahbicht.condition_node_distinction.derive_condition_node_type(condition_key: str) ConditionNodeType[source]

Returns the corresponding type of condition node for a given condition key

ahbicht.utility_functions module

Functions that are not clearly related to another module

async ahbicht.utility_functions.gather_if_necessary(results_and_awaitable_results: list[Result | Awaitable[Result]]) list[Result][source]

Await the awaitables, pass the un-awaitable results :param results_and_awaitable_results: heterogeneous list of both Ts and Awaitable[T]s. :return: list of T in the same order as in the input param.

ahbicht.utility_functions.parse_repeatability(repeatability_string: str) Repeatability[source]

parses the given string as repeatability; e.g. 17..23 is parsed as min=17, max=23

ahbicht.utility_functions.tree_copy(lru_cached_parsing_func: Callable[[str], Tree[Token]]) Callable[[str], Tree[Token]][source]

A decorator that returns copy of the cached result from the lru_cached_parsing_func. Rationale: We want to cache the tree for various expressions because this is definitely faster than re-parsing it. But we don’t want the same instance of the tree to be returned over and over again, because the calling code might modify the tree and (if we always returned the same instance) might also modify the cache entry. We don’t want this. The tree_copy decorator is used together shall be used with a @lru_cached function. It returns a copy of the cached value instead of the same instance. :param lru_cached_parsing_func: A function that parses a string to a tree which is decorated with @lru_cache. :return: the decorated function that always returns a copy of the cached result instead of the same instance

Module contents

AHBicht is a lark based parser and evaluation framework for conditions that occur in Anwendungshandbüchern (AHB).

class ahbicht.StrEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, ReprEnum

Enum where members are also (and must be) strings