krrood.entity_query_language.verbalization.rendering.realization

krrood.entity_query_language.verbalization.rendering.realization#

Functions#

realize_tree(...)

Run the ordered realisation passes over fragment — the one place the lowering passes and

realize_subtree(→ str)

Fully realise a sub-tree to plain text — the realisation passes, then flatten.

Module Contents#

krrood.entity_query_language.verbalization.rendering.realization.realize_tree(fragment: krrood.entity_query_language.verbalization.fragments.base.VerbalizationFragment, previously_introduced_referents: Iterable[uuid.UUID] | None = None, discourse: krrood.entity_query_language.verbalization.rendering.discourse.DiscourseView = EMPTY_DISCOURSE, numbered_labels: Mapping[uuid.UUID, str] | None = None) krrood.entity_query_language.verbalization.fragments.base.VerbalizationFragment#

Run the ordered realisation passes over fragment — the one place the lowering passes and their order are defined: coreference resolution → determiner lowering → morphology → orthography (punctuation spacing). Both the whole-expression build and the local realisation of an opaque template need this same ordered sequence.

Reference: Gatt and Reiter [GR09] — the ordered realisation stages.

Parameters:
  • fragment – Root of the fragment tree.

  • previously_introduced_referents – Referents introduced by prior builds on a shared context.

  • discourse – The focus-per-scope view the coreference pass consults (empty for a local sub-tree, which has no query scope of its own).

  • numbered_labels – Disambiguation numbers for referents the rules cannot label themselves (relational referents) — applied by the coreference pass.

Returns:

The fully realised fragment tree.

This is the pass-running step: it returns a lowered fragment tree, so the example wraps it in flatten_fragment_to_plain_text() to read the text out; realize_subtree() runs the same passes and returns that plain string directly.

>>> from krrood.entity_query_language.verbalization.verbalizer import EQLVerbalizer
>>> tree = EQLVerbalizer().build(a(entity(variable(Robot, []))))
>>> flatten_fragment_to_plain_text(realize_tree(tree))
'Find a Robot'
krrood.entity_query_language.verbalization.rendering.realization.realize_subtree(fragment: krrood.entity_query_language.verbalization.fragments.base.VerbalizationFragment) str#

Fully realise a sub-tree to plain text — the realisation passes, then flatten.

For an opaque leaf (a user template that string-formats its children), the children must be realised here, locally, rather than deferred to the global passes.

Parameters:

fragment – Root of the sub-tree.

Returns:

The realised plain-text string.

Its contribution over realize_tree() is the final flatten: it returns the plain string Find a Robot, not a fragment tree — the form an opaque template needs for its locally realised children.

>>> from krrood.entity_query_language.verbalization.verbalizer import EQLVerbalizer
>>> realize_subtree(EQLVerbalizer().build(a(entity(variable(Robot, [])))))
'Find a Robot'