krrood.entity_query_language.verbalization.engine#
Functions#
|
Build the |
|
Verbalize node by dispatching it to its matching grammar rule and recursing — the |
Module Contents#
- krrood.entity_query_language.verbalization.engine.root_context(services: krrood.entity_query_language.verbalization.context.MicroplanningServices, rules: Sequence[krrood.entity_query_language.verbalization.grammar.framework.phrase_rule.PhraseRule], options: krrood.entity_query_language.verbalization.grammar.framework.phrase_rule.RenderOptions | None = None) krrood.entity_query_language.verbalization.grammar.framework.phrase_rule.RuleContext#
Build the
RuleContextfor one node — the single definition of the fold continuation (recurse), shared byfold()and the match assembler’s root context, so a new render flag is one field onRenderOptionsrather than two duplicated lambdas.- Parameters:
services – The pass-wide microplanning services.
rules – The grammar to dispatch over.
options – The render flags for this node (defaults to all reset).
- Returns:
The context whose
childre-entersfold().
>>> from krrood.entity_query_language.verbalization.context import MicroplanningServices >>> robot = variable(Robot, []) >>> context = root_context(MicroplanningServices.from_expression(robot), RULES) >>> type(context.child(robot)).__name__ 'NounPhrase'
- krrood.entity_query_language.verbalization.engine.fold(node: krrood.entity_query_language.verbalization.microplanning.coordination.FoldNode, services: krrood.entity_query_language.verbalization.context.MicroplanningServices, rules: Sequence[krrood.entity_query_language.verbalization.grammar.framework.phrase_rule.PhraseRule] | None = None, options: krrood.entity_query_language.verbalization.grammar.framework.phrase_rule.RenderOptions | None = None) krrood.entity_query_language.verbalization.fragments.base.VerbalizationFragment#
Verbalize node by dispatching it to its matching grammar rule and recursing — the single catamorphism (fold) over the EQL expression tree.
A node carrying a pre-built binding override is returned directly, before any dispatch. When no rule covers the node, an
UnverbalizableExpressionErroris raised rather than degrading silently to the class name.The recursion is an F-algebra fold (catamorphism) over the EQL algebra, with the grammar as the algebra — see
fold_fragment()for the catamorphism / F-algebra definition (Meijer et al. [MFP91]; Bird and de Moor [BdM97]).- Parameters:
node – Any EQL expression, or a synthetic coordination artifact produced by conjunct reduction (
RangeFold/CoindexedFold).services – The pass-wide microplanning services (and render configuration).
rules – Grammar to dispatch over; defaults to the standard rule set.
options – The render flags to build node under (defaults to all reset).
- Returns:
The fragment for node.
- Raises:
UnverbalizableExpressionError – when no grammar rule covers node.
The catamorphism is observable through
verbalize_expression(), which runs this fold and then lowers the produced tree — a two-hop chain dispatches the attribute rule, which recurses on its variable child:>>> verbalize_expression(variable(Robot, []).battery) 'the battery of a Robot'