mindnet/app/core/chunking/chunking_propagation.py

25 lines
1.0 KiB
Python

"""
FILE: app/core/chunking/chunking_propagation.py
DESCRIPTION: Vererbung von Kanten (Inheritance) über Sektions-Pfade.
"""
from typing import List, Dict, Set
from .chunking_models import Chunk, RawBlock
from .chunking_parser import parse_edges_robust
def propagate_section_edges(chunks: List[Chunk], blocks: List[RawBlock]) -> List[Chunk]:
"""WP-15b: Kanten aus Headings werden an Sub-Chunks vererbt."""
section_inheritance: Dict[str, Set[str]] = {}
for b in blocks:
if b.kind == "heading":
edges = parse_edges_robust(b.text)
if edges:
if b.section_path not in section_inheritance:
section_inheritance[b.section_path] = set()
section_inheritance[b.section_path].update(edges)
for ch in chunks:
inherited = section_inheritance.get(ch.section_path, set())
for e_str in inherited:
kind, target = e_str.split(':', 1)
ch.candidate_pool.append({"kind": kind, "to": target, "provenance": "inherited"})
return chunks