dialogue-graph
Build, validate, serialize, and visualize a dialogue graph parsed from a bracketed-section script into `{"nodes":[...],"edges":[...]}` plus a `.dot` graph.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- dialogue-graph
- description
- Build, validate, serialize, and visualize a dialogue graph parsed from a bracketed-section script into `{"nodes":[...],"edges":[...]}` plus a `.dot` graph.
02 资源文件 1
- 脚本scripts/dialogue_graph.py5.7 KB
03 SKILL.md 正文
Steps
- Inspect the script structure as sections starting with headers like
[SectionId], collecting each section’s non-empty lines until the next header. - Confirm each section is one of:
- a single speaker line:
Speaker: text. -> TargetId - a choice hub: multiple numbered lines like
1. Choice text -> TargetId
(No mixing speaker+choices in the same section; no “nonconforming” lines.)
- a single speaker line:
- Parse sections into nodes:
- For a speaker line section, create a node
{id: SectionId, type:"line", speaker:<Speaker>, text:<text>}. - For a choice section, create a node
{id: SectionId, type:"choice", speaker:"", text:""}(or a minimal placeholder text if needed).
- For a speaker line section, create a node
- Parse transitions into edges:
- From a speaker line section: add one edge
{"from": SectionId, "to": TargetId, "text": ""}. - From a choice section: for each choice, add
{"from": SectionId, "to": TargetId, "text": <full choice label/text>}.
- From a speaker line section: add one edge
- Ensure all edge targets exist by creating missing target nodes when needed; if the script references
Endwithout defining[End], add an implicitEndnode (commonly{id:"End", type:"line", speaker:"", text:""}). - Validate graph constraints:
- Determine the start node as the first section encountered in the file.
- Run reachability (BFS/DFS) from the start node; error if any node is unreachable.
- Error on missing edge targets other than the allowed implicit end case (or create the missing nodes as in Step 5).
- Serialize outputs:
- Write JSON as
{"nodes":[{"id","text","speaker","type"}...],"edges":[{"from","to","text"}...]}. - Write a
.dotfile with nodes and directed edges for visualization (choice nodes can beshape=diamond, line nodesshape=box).
- Write JSON as
- When searching the script from the shell for patterns starting with
-(e.g.,-> End), usegrepwith--to stop option parsing:
grep -n -- '-> End' /app/script.txt - When using a terminal tool that only accepts one command at a time, run commands in separate calls, or chain within a single command using
&&(not as two separate lines).
Expected Result
A parsed dialogue graph where every node is reachable from the first section, all referenced targets exist (with an implicit End node if needed), and the graph is exported to valid dialogue.json plus a readable dialogue.dot.
04 同仓库更多 Skills
video-frame-extraction
Extract frames from video files and save them as images using OpenCV
openai-vision
Analyze images and multi-frame sequences using OpenAI GPT vision models
image-ocr
Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms
video-frame-extraction
Extract frames from video files and save them as images using OpenCV
openai-vision
Analyze images and multi-frame sequences using OpenAI GPT vision models
image-ocr
Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms