krrood.entity_query_language.verbalization.engine

krrood.entity_query_language.verbalization.engine#

Functions#

root_context(...)

Build the RuleContext for one node — the single definition of the fold

fold(...)

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 RuleContext for one node — the single definition of the fold continuation (recurse), shared by fold() and the match assembler’s root context, so a new render flag is one field on RenderOptions rather 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 child re-enters fold().

>>> 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 UnverbalizableExpressionError is 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'