"""JSON entities โ†’ Markdown entity detail panel.""" from __future__ import annotations _MOOD_EMOJI = { "mysterious": "๐ŸŒ™", "joyful": "โ˜€๏ธ", "anxious": "โšก", "surreal": "๐ŸŒ€", "peaceful": "๐ŸŒฟ", } def format_panel_entitas(entities: dict) -> str: """Return a Markdown string summarising extracted dream entities.""" title = str(entities.get("title") or "Untitled Dream").strip() mood = str(entities.get("mood") or "mysterious") theme = str(entities.get("core_theme") or "").strip() characters = [c for c in (entities.get("characters") or []) if isinstance(c, dict)] places = [p for p in (entities.get("places") or []) if isinstance(p, dict)] symbols = [s for s in (entities.get("symbols") or []) if isinstance(s, dict)] emoji = _MOOD_EMOJI.get(mood, "โœฆ") lines: list[str] = [f"## {title}"] mood_line = f"{emoji} **{mood.capitalize()}**" if theme: mood_line += f" ยท _{theme}_" lines += [mood_line, ""] if characters: lines.append("**People**") for c in characters: name = str(c.get("name", "?")).strip() role = str(c.get("role", "")).strip() emo = str(c.get("emotion", "")).strip() detail_parts = [x for x in [role, emo] if x] detail = " ยท ".join(detail_parts) lines.append(f"- **{name}**" + (f" โ€” {detail}" if detail else "")) lines.append("") if places: lines.append("**Places**") for p in places: name = str(p.get("name", "?")).strip() ptype = str(p.get("type", "")).strip() feeling = str(p.get("feeling", "")).strip() detail_parts = [x for x in [ptype, feeling] if x] detail = " ยท ".join(detail_parts) lines.append(f"- **{name}**" + (f" โ€” {detail}" if detail else "")) lines.append("") if symbols: lines.append("**Images & symbols**") for s in symbols: name = str(s.get("name", "?")).strip() appearance = str(s.get("appearance", "")).strip() significance = str(s.get("significance", "")).strip() detail_parts = [p for p in [appearance, significance] if p] detail = " ยท ".join(detail_parts) lines.append(f"- **{name}**" + (f" โ€” {detail}" if detail else "")) lines.append("") return "\n".join(lines).rstrip()