ncm_delta_parser

NCM Delta Parser: resolves compact delta strings to full NCM vectors.

Parses the shorthand delta notation from reality_marble_recursion_index.yaml:

“KOR+0.4 D1-0.3 OXT-0.2 5HT1A-0.2 ENT1↑ ACC↑ SERT.reversed”

Into a proper chemical vector dict:

{“KAPPA_OPIOID_KOR”: 0.4, “DOPAMINE_D1”: -0.3, …}

ncm_delta_parser.resolve_node_name(abbrev)[source]

Resolve a compact abbreviation to its canonical NCM node name.

Looks the abbreviation up in the module-level ABBREV_TO_NODE table, which maps shorthand tokens from the recursion index (for example "KOR" or "5HT1A") to full neurochemical-model node names such as "KAPPA_OPIOID_KOR". If there is no mapping the input is returned unchanged, on the assumption it is already a full node name. This is a pure dictionary lookup with no side effects.

Called by parse_delta_string in this module for every parsed token, and by flavor_engine.py (via a guarded import) when expanding flavor abbreviations.

Parameters:

abbrev (str) – The shorthand token or candidate node name to resolve.

Returns:

The canonical node name, or abbrev unchanged if unmapped.

Return type:

str

ncm_delta_parser.parse_delta_string(delta_str)[source]

Parse a compact NCM delta string into a resolved chemical vector.

Examples:

>>> parse_delta_string("KOR+0.4 D1-0.3 OXT-0.2 ENT1↑ ACC↑")
{'KAPPA_OPIOID_KOR': 0.4, 'DOPAMINE_D1': -0.3,
 'OXYTOCIN_NEUROMIRROR': -0.2, 'ENT1_ACTIVITY': 0.15,
 'ACC_SAL': 0.15}

>>> parse_delta_string("SERT.reversed DAT.reversed")
{'SERT_ACTIVITY': -0.35, 'SEROTONERGIC_WARMTH': 0.3,
 'DAT_ACTIVITY': -0.35, 'DOPAMINERGIC_CRAVE': 0.35}

A reversed transporter applies _REVERSAL_MAGNITUDE (clearance disrupted) and, for transporters in _REVERSAL_NT_BOOST, also boosts the parent neurotransmitter to model the resulting synaptic flood.

Return type:

Dict[str, float]

Parameters:

delta_str (str)

ncm_delta_parser.get_emotion_delta(emotion_name)[source]

Return the parsed NCM delta vector for a named emotion.

Normalizes emotion_name (uppercase, spaces to underscores) and looks it up in the cached emotion index from _load_emotion_index, returning a copy of that emotion’s resolved delta_vector so callers cannot mutate the shared cache. An unknown emotion yields an empty dict rather than raising.

Called by ncm_semantic_triggers.py after semantic matching, to turn each top-scoring emotion name into a concrete chemical delta.

Parameters:

emotion_name (str) – Emotion name in any spacing/casing (e.g. "warm glow").

Returns:

A fresh copy of the emotion’s node-to-magnitude delta vector, or an empty dict if the emotion is not in the index.

Return type:

Dict[str, float]

ncm_delta_parser.get_all_emotions()[source]

Return the full emotion index, loading and caching it on first use.

Thin public accessor that delegates to _load_emotion_index and exposes the complete mapping of emotion name to its parsed record (id, cart, affect, raw and parsed deltas, and optional narrative fields). The returned dict is the live cached object, so callers should treat it as read-only.

Called by limbic_system/engine.py, ncm_semantic_triggers.py, and the trigger-pregeneration scripts under scripts/ to enumerate every known emotion and its delta vector.

Returns:

The cached emotion index keyed by normalized emotion name; empty if the recursion YAML is missing or unreadable.

Return type:

Dict[str, Dict[str, Any]]

ncm_delta_parser.scan_text_for_triggers(text, trigger_lexicon=None)[source]

Scan text for emotional trigger words and return matched deltas.

Parameters:
  • text (str) – The text to scan (user message or bot response).

  • trigger_lexicon (Optional[List[str]]) – Optional explicit list of trigger words. If None, uses all emotion names from the recursion index.

Return type:

List[Tuple[str, Dict[str, float]]]

ncm_delta_parser.combine_deltas(delta_list, scale=1.0)[source]

Combine multiple delta vectors into one, optionally scaled.

When multiple emotions fire simultaneously, their deltas stack but are scaled down to prevent runaway:

combined = scale * Σ(delta_i) / sqrt(N)

Return type:

Dict[str, float]

Parameters: