edge regsitry debug
This commit is contained in:
parent
f7ab32ebf4
commit
f5bfb0cfb4
|
|
@ -2,8 +2,8 @@
|
|||
FILE: app/services/edge_registry.py
|
||||
DESCRIPTION: Single Source of Truth für Kanten-Typen.
|
||||
WP-22 Teil B: Registry & Validation.
|
||||
HARD-LOGGING: Nutzt print() und logger für maximale Sichtbarkeit beim Systemstart.
|
||||
VERSION: 0.6.6 (Diagnostic Update)
|
||||
FIX: Erzwingt sofortige Log-Ausgabe beim Laden des Moduls.
|
||||
VERSION: 0.6.8 (Emergency Debug)
|
||||
"""
|
||||
import re
|
||||
import os
|
||||
|
|
@ -11,6 +11,9 @@ import json
|
|||
import logging
|
||||
from typing import Dict, Optional, Set
|
||||
|
||||
# Sofortiger Print beim Laden des Moduls (erscheint garantiert in journalctl)
|
||||
print(">>> MODULE_LOAD: edge_registry.py is being read by Python <<<", flush=True)
|
||||
|
||||
from app.config import get_settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -20,6 +23,7 @@ class EdgeRegistry:
|
|||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls._instance is None:
|
||||
print(">>> SINGLETON: Creating new EdgeRegistry instance <<<", flush=True)
|
||||
cls._instance = super(EdgeRegistry, cls).__new__(cls)
|
||||
cls._instance.initialized = False
|
||||
return cls._instance
|
||||
|
|
@ -28,15 +32,13 @@ class EdgeRegistry:
|
|||
if self.initialized:
|
||||
return
|
||||
|
||||
# Sofortige Ausgabe beim Start (erscheint in journalctl)
|
||||
print("--- [DICT-INIT] EdgeRegistry startup sequence initiated ---")
|
||||
print(">>> INIT: EdgeRegistry.__init__ started <<<", flush=True)
|
||||
|
||||
# Pfad-Ermittlung
|
||||
settings = get_settings()
|
||||
# Prio: MINDNET_VOCAB_PATH > MINDNET_VAULT_ROOT > Default
|
||||
env_vocab_path = os.getenv("MINDNET_VOCAB_PATH")
|
||||
env_vault_root = os.getenv("MINDNET_VAULT_ROOT") or getattr(settings, "MINDNET_VAULT_ROOT", "./vault_master")
|
||||
|
||||
# Absolute Pfad-Konstruktion
|
||||
if env_vocab_path:
|
||||
self.full_vocab_path = os.path.abspath(env_vocab_path)
|
||||
else:
|
||||
|
|
@ -53,20 +55,20 @@ class EdgeRegistry:
|
|||
|
||||
def _load_vocabulary(self):
|
||||
"""Parst die Markdown-Tabelle im Vault."""
|
||||
print(f"--- [DICT-CHECK] Attempting to load: {self.full_vocab_path}")
|
||||
print(f">>> CHECK: Searching for Vocabulary at {self.full_vocab_path}", flush=True)
|
||||
|
||||
if not os.path.exists(self.full_vocab_path):
|
||||
msg = f"!!! [DICT-ERROR] Edge Vocabulary NOT found at: {self.full_vocab_path} !!!"
|
||||
print(msg)
|
||||
print(msg, flush=True)
|
||||
logger.warning(msg)
|
||||
return
|
||||
|
||||
# Regex für Markdown Tabellen
|
||||
pattern = re.compile(r"\|\s*\*\*([a-z_]+)\*\*\s*\|\s*([^|]+)\|")
|
||||
|
||||
try:
|
||||
with open(self.full_vocab_path, "r", encoding="utf-8") as f:
|
||||
count_types = 0
|
||||
count_aliases = 0
|
||||
c_types, c_aliases = 0, 0
|
||||
for line in f:
|
||||
match = pattern.search(line)
|
||||
if match:
|
||||
|
|
@ -75,32 +77,29 @@ class EdgeRegistry:
|
|||
|
||||
self.valid_types.add(canonical)
|
||||
self.canonical_map[canonical] = canonical
|
||||
count_types += 1
|
||||
c_types += 1
|
||||
|
||||
if aliases_str and "Kein Alias" not in aliases_str:
|
||||
aliases = [a.strip() for a in aliases_str.split(",") if a.strip()]
|
||||
for alias in aliases:
|
||||
clean_alias = alias.replace("`", "").lower().strip()
|
||||
self.canonical_map[clean_alias] = canonical
|
||||
count_aliases += 1
|
||||
c_aliases += 1
|
||||
|
||||
success_msg = f"=== [DICT-SUCCESS] Loaded {count_types} Types and {count_aliases} Aliases ==="
|
||||
print(success_msg)
|
||||
success_msg = f"=== [DICT-SUCCESS] Loaded {c_types} Types and {c_aliases} Aliases ==="
|
||||
print(success_msg, flush=True)
|
||||
logger.info(success_msg)
|
||||
|
||||
except Exception as e:
|
||||
err_msg = f"!!! [DICT-FATAL] Failed to parse Vocabulary: {e} !!!"
|
||||
print(err_msg)
|
||||
err_msg = f"!!! [DICT-FATAL] Failed to parse: {e} !!!"
|
||||
print(err_msg, flush=True)
|
||||
logger.error(err_msg)
|
||||
|
||||
def resolve(self, edge_type: str) -> str:
|
||||
"""Normalisiert Kanten-Typen via Registry oder loggt Unbekannte."""
|
||||
if not edge_type: return "related_to"
|
||||
clean_type = edge_type.lower().strip().replace(" ", "_")
|
||||
|
||||
if clean_type in self.canonical_map:
|
||||
return self.canonical_map[clean_type]
|
||||
|
||||
self._log_unknown(clean_type)
|
||||
return clean_type
|
||||
|
||||
|
|
@ -112,5 +111,6 @@ class EdgeRegistry:
|
|||
f.write(json.dumps(entry) + "\n")
|
||||
except Exception: pass
|
||||
|
||||
# Singleton Instanz
|
||||
# Singleton Instanz - Dies triggert beim Import die Initialisierung
|
||||
print(">>> INSTANTIATING REGISTRY SINGLETON <<<", flush=True)
|
||||
registry = EdgeRegistry()
|
||||
Loading…
Reference in New Issue
Block a user