refactor: migrate translate engine to GRACE-Poly v2.6 semantic protocol
- Convert all 84 contracts from legacy [DEF:] to #region/#endregion syntax - Fix complexity tiers: 14 modules re-tiered (6 C4 route modules, 7 C4→C5 plugin services) - Remove forbidden tags: @RATIONALE/@REJECTED stripped from C1–C4 contracts - Add required tags: @PRE/@POST/@SIDE_EFFECT on C4, @RELATION on C3, @DATA_CONTRACT/@INVARIANT on C5 - Add belief runtime markers (reason/reflect/explore) to 7 service.py functions - Fix @LAYER: route files → UI, plugins → Domain, superset_executor → Infra - Fix pre-existing test mock_service fixture in test_orchestrator.py - 196/196 translation tests pass, zero regressions
This commit is contained in:
@@ -1,30 +1,22 @@
|
||||
# [DEF:DictionaryUtils:Module]
|
||||
# @COMPLEXITY: 1
|
||||
# @SEMANTICS: dictionary, utils, normalize, delimiter
|
||||
# @PURPOSE: Utility helpers for dictionary management (term normalization and delimiter detection).
|
||||
# @LAYER: Domain
|
||||
# #region DictionaryUtils [C:1] [TYPE Module]
|
||||
# #endregion DictionaryUtils
|
||||
|
||||
import re
|
||||
import unicodedata
|
||||
|
||||
|
||||
# [DEF:_normalize_term:Function]
|
||||
# @PURPOSE: Normalize a term for case-insensitive unique constraint lookup.
|
||||
# @RATIONALE: NFC normalization is applied before lowercasing to ensure consistent
|
||||
# comparison of Unicode characters (e.g. precomposed vs decomposed forms).
|
||||
# @REJECTED: Lowercasing without NFC normalization — would cause duplicate entries
|
||||
# for semantically identical Unicode strings in different normalization forms.
|
||||
# #region _normalize_term [C:2] [TYPE Function] [SEMANTICS dictionary,normalize]
|
||||
# @BRIEF Normalize a term for case-insensitive unique constraint lookup using NFC normalization.
|
||||
def _normalize_term(term: str) -> str:
|
||||
"""Normalize a term by NFC, lowercasing, and removing extra whitespace."""
|
||||
if not term:
|
||||
return ""
|
||||
term = unicodedata.normalize('NFC', term)
|
||||
return " ".join(term.lower().split())
|
||||
# [/DEF:_normalize_term:Function]
|
||||
# #endregion _normalize_term
|
||||
|
||||
|
||||
# [DEF:_detect_delimiter:Function]
|
||||
# @PURPOSE: Detect the delimiter used in a CSV/TSV header line.
|
||||
# #region _detect_delimiter [C:1] [TYPE Function] [SEMANTICS dictionary,delimiter]
|
||||
def _detect_delimiter(header_line: str) -> str:
|
||||
"""Detect delimiter by counting tabs vs commas in the first line."""
|
||||
if not header_line:
|
||||
@@ -32,4 +24,4 @@ def _detect_delimiter(header_line: str) -> str:
|
||||
tab_count = header_line.count("\t")
|
||||
comma_count = header_line.count(",")
|
||||
return "\t" if tab_count > comma_count else ","
|
||||
# [/DEF:_detect_delimiter:Function]
|
||||
# #endregion _detect_delimiter
|
||||
|
||||
Reference in New Issue
Block a user