From 38fd7420ff64debf38489ed447ee79a891180d15 Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 5 Sep 2025 11:03:58 +0200 Subject: [PATCH] app/core/derive_edges.py aktualisiert --- app/core/derive_edges.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/app/core/derive_edges.py b/app/core/derive_edges.py index f2fd0f9..ab9c7b6 100644 --- a/app/core/derive_edges.py +++ b/app/core/derive_edges.py @@ -4,20 +4,26 @@ Name: app/core/derive_edges.py Version: v1.1.0 (2025-09-05) -Kurzbeschreibung: - Leitet Edges aus Wikilinks ([[...]]) ab. - - Unterstützt Auflösung über note_id, Title-Slug, File-Slug. - - Erzeugt Edges: - * "references" (Note->Note) + "backlink" (inverse) - * "references_at" (Chunk->Note) mit seq = chunk_index - - **NEU**: pro Match ein Occurrence-Zähler 'occ' für eindeutige Edge-IDs. +Kurzbeschreibung + Leitet Edges aus Wikilinks ([[…]]) ab und löst Zielnoten robust auf. + Erzeugt: + - "references" (Note -> Note) mit seq="body", pro Match eine eigene Occurrence 'occ' + - "backlink" (inverse zu "references", gleiche seq/occ) + - "references_at" (Chunk -> Note) mit seq= und eigener 'occ' je Match -Kompatibilität: - - Vorherige Payload-Felder bleiben erhalten. - - Zusätzliche Felder: 'seq' für Volltext ("body"), 'occ' überall. +Aufruf + from app.core.derive_edges import build_note_index, derive_wikilink_edges -Changelog: - v1.1.0: 'occ' eingeführt; 'references' erhalten jetzt seq="body". +Parameter / Felder + - note_payload: {"note_id","title","path","fulltext": , …} + - chunks_payloads: [{"chunk_id","text",…}, …] + - note_index: build_note_index([...]) -> (by_id, by_slug, by_file_slug) + +Kompatibilität + - Rückwärtskompatible Payload-Felder, nur erweitert um 'seq' und 'occ'. + +Changelog + v1.1.0: Occurrence-Zählung ('occ') je Match; 'seq="body"' für references. """ from __future__ import annotations @@ -85,7 +91,7 @@ def derive_wikilink_edges(note_payload: dict, chunks_payloads: List[dict], note_ e.update(extra) return e - # Links im Volltext (gesamter Body) + # Volltext (Note-Ebene) fulltext = note_payload.get("fulltext") or note_payload.get("body") or "" if fulltext: for k, m in enumerate(WIKILINK_RE.finditer(fulltext), start=1): @@ -100,7 +106,7 @@ def derive_wikilink_edges(note_payload: dict, chunks_payloads: List[dict], note_ extra["target_label"] = raw_target edges.append(_make_edge("references", source_note_id, raw_target, seq="body", occ=k, extra=extra)) - # Links in Chunks (wenn übergeben) + # Chunks (Chunk-Ebene) for i, ch in enumerate(chunks_payloads, start=1): txt = ch.get("text") or ch.get("content") or "" if not txt: