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])[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)

class ahbicht.condition_node_distinction.ConditionNodeType(value)[source]

Bases: StrEnum

Possible types of condition nodes. The value is usually determined using the key of the respective condition node. For the descriptions of the different types see also the README.

FORMAT_CONSTRAINT = 'FORMAT_CONSTRAINT'

A Format Constraint (FC) is what edi@energy refers to as “Formatbedingung”. Other than requirement constraints (RC) format constraints do not refer to a data constellation in the edifact message as a whole (or at least parts of it) but to the value used at the place where the format constraint is used.

HINT = 'HINT'

A Hint is a node whose text/description starts with “Hinweis”. It’s a text that cannot be interpreted automatically.

PACKAGE = 'PACKAGE'

A package is an abbreviation for an expression.

REPEATABILITY_CONSTRAINT = 'REPEATABILITY_CONSTRAINT'

Repeatability Constraints are what edi@energy refers to as “Wiederholbarkeiten”. They describe how often you may insert segment (groups) into a message (e.g. min. 1 but max 10 times).

REQUIREMENT_CONSTRAINT = 'REQUIREMENT_CONSTRAINT'

A Requirement Constraint (RC) is what edi@energy refers to as “Voraussetzung”. It describes a data constellation that might (or might not) occur in a edifact message.

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.evaluation_results module

This module contains the classes for the evaluation results. A “result” is the outcome of an evaluation. It requires actual data to be present.

class ahbicht.evaluation_results.AhbExpressionEvaluationResult(*, requirement_indicator: PrefixOperator | ModalMark, requirement_constraint_evaluation_result: RequirementConstraintEvaluationResult, format_constraint_evaluation_result: FormatConstraintEvaluationResult)[source]

Bases: object

A class for the result of an ahb expression evaluation.

format_constraint_evaluation_result: FormatConstraintEvaluationResult
requirement_constraint_evaluation_result: RequirementConstraintEvaluationResult
requirement_indicator: PrefixOperator | ModalMark
class ahbicht.evaluation_results.AhbExpressionEvaluationResultSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool = False, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: Schema

A schema to (de-)serialize AhbExpressionEvaluationResults

deserialize(data, **kwargs) AhbExpressionEvaluationResult[source]

Converts the barely typed data dictionary into an actual AhbExpressionEvaluationResult

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>
class ahbicht.evaluation_results.FormatConstraintEvaluationResult(*, format_constraints_fulfilled: bool, error_message: str | None = None)[source]

Bases: object

A class for the result of the format constraint evaluation.

error_message: str | None

All error messages that lead to not fulfilling the format constraint expression

format_constraints_fulfilled: bool

true if data entered obey the format constraint expression

class ahbicht.evaluation_results.FormatConstraintEvaluationResultSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool = False, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: Schema

A class to (de-)serialize FormatConstraintEvaluationResult

deserialize(data, **kwargs) FormatConstraintEvaluationResult[source]

Converts the barely typed data dictionary into an actual FormatConstraintEvaluationResult :param data: :param kwargs: :return:

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>
class ahbicht.evaluation_results.RequirementConstraintEvaluationResult(*, requirement_constraints_fulfilled: bool | None, requirement_is_conditional: bool | None, format_constraints_expression: str | None = None, hints: str | None = None)[source]

Bases: object

A class for the result of the requirement constraint evaluation.

format_constraints_expression: str | None
hints: str | None

‘ID der Messlokation’”

Type:

Hint text that should be displayed in the frontend, e.g. “[501] Hinweis

requirement_constraints_fulfilled: bool | None

true if condition expression in regard to requirement constraints evaluates to true

requirement_is_conditional: bool | None

true if it is dependent on requirement constraints; None if there are unknown condition nodes left

class ahbicht.evaluation_results.RequirementConstraintEvaluationResultSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool = False, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: Schema

A schema to (de-)serialize RequirementConstraintEvaluationResult

deserialize(data, **kwargs) RequirementConstraintEvaluationResult[source]

Converts the barely typed data dictionary into an actual RequirementConstraintEvaluationResult :param data: :param kwargs: :return:

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>

ahbicht.mapping_results module

This module contains classes that are returned by mappers, meaning they contain a mapping.

class ahbicht.mapping_results.ConditionKeyConditionTextMapping(*, edifact_format: EdifactFormat, condition_key: str, condition_text: str | None = None)[source]

Bases: object

maps a condition from a specified EDIFACT format onto a text as it is found in the AHB.

condition_key: str

the key of the condition without square brackets; e.g. ‘78’

condition_text: str | None

the description of the condition as in the AHB; None if unknown; e.g. ‘Wenn SG4 STS+7++E02 (Transaktionsgrund: Einzug/Neuanlage) nicht vorhanden’.

edifact_format: EdifactFormat

the format in which the condition is used; e.g. ‘UTILMD’

class ahbicht.mapping_results.ConditionKeyConditionTextMappingSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool = False, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: Schema

A schema to (de-)serialize ConditionKeyConditionTextMapping s

deserialize(data, **kwargs) ConditionKeyConditionTextMapping[source]

Converts the barely typed data dictionary into an actual ConditionKeyConditionTextMapping

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>
class ahbicht.mapping_results.PackageKeyConditionExpressionMapping(*, edifact_format: EdifactFormat, package_key: str, package_expression: str | None = None)[source]

Bases: object

maps a package key from a specified EDIFACT format onto a (not yet parsed) condition expression as it is found in the AHB.

edifact_format: EdifactFormat

the format in which the package is used; e.g. ‘UTILMD’

has_been_resolved_successfully() bool[source]

return true iff the package has been resolved successfully

package_expression: str | None

the expression for which the package is a shortcut; None if unknown e.g. ‘[20] ∧ [244]’

package_key: str

the key of the package without square brackets but with trailing P; e.g. ‘10P’

class ahbicht.mapping_results.PackageKeyConditionExpressionMappingSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool = False, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: Schema

A schema to (de-)serialize PackageKeyConditionExpressionMapping s

deserialize(data, **kwargs) PackageKeyConditionExpressionMapping[source]

Converts the barely typed data dictionary into an actual PackageKeyConditionExpressionMapping

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>
class ahbicht.mapping_results.Repeatability(*, min_occurrences: int, max_occurrences: int)[source]

Bases: object

describes how often a segment/code must be used when a “repeatability” is provided with packages

is_optional() bool[source]

returns true if the package used together with this repeatability is optional

max_occurrences: int

how often the segment/coode may be repeated at most (upper, inclusive bound). This is inclusive meaning that [123P0..1] leads to max_occurrences==1

min_occurrences: int

how often the segment/code has to be repeated (lower, inclusive bound); may be 0 for optional packages

ahbicht.mapping_results.check_max_greater_or_equal_than_min(instance: Repeatability, attribute, value)[source]

assert that 0<=min<max and not both min and max are 0

ahbicht.mapping_results.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 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: heterogenous list of both Ts and Awaitable[T]s. :return: list of T in the same order as in the input param.

ahbicht.utility_functions.tree_copy(lru_cached_parsing_func: Callable[[str], Tree])[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)[source]

Bases: str, Enum

An enum class of which each member has a string representation. This is a workaround for Python <v3.11 because enum.StrEnum was introduced in Python 3.11.