From 8ab93da5363822d0ee219a0d416fe5179791b6bb Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 3 Sep 2025 07:15:29 +0200 Subject: [PATCH] =?UTF-8?q?app/core/chunk=5Fpayload.py=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/chunk_payload.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/core/chunk_payload.py diff --git a/app/core/chunk_payload.py b/app/core/chunk_payload.py new file mode 100644 index 0000000..dec7c2b --- /dev/null +++ b/app/core/chunk_payload.py @@ -0,0 +1,37 @@ +from __future__ import annotations +from typing import Dict, List +from .chunker import Chunk +from .parser import extract_wikilinks + +def make_chunk_payloads(note_meta: Dict, path: str, chunks: List[Chunk]) -> List[Dict]: + res = [] + for ch in chunks: + wikilinks = extract_wikilinks(ch.text) + payload = { + "id": ch.id, + "note_id": note_meta["id"], + "note_title": note_meta["title"], + "chunk_index": ch.index, + "char_start": ch.char_start, + "char_end": ch.char_end, + "token_count": ch.token_count, + "type": note_meta.get("type"), + "area": note_meta.get("area"), + "project": note_meta.get("project"), + "tags": note_meta.get("tags", []), + "section_title": ch.section_title, + "section_path": ch.section_path, + "lang": note_meta.get("lang"), + "wikilinks": wikilinks, + "external_links": [], # (optional später ergänzen) + "references": [{"target_id": w, "kind": "wikilink"} for w in wikilinks], + "neighbors": { + "prev": ch.neighbors_prev, + "next": ch.neighbors_next + }, + "path": path, + } + # None/Leere bereinigen + payload = {k: v for k, v in payload.items() if v not in (None, [], {})} + res.append(payload) + return res