Question Bank Formatter (题库格式化)
Convert raw question text (from textbooks, PDFs, or pasted content) into a strict JSON question bank format.
When to Use
- User provides question text and asks to "转换成题库" or "生成题库"
- User says "题库格式转换" or references the specific JSON output format
- User attaches a document with exam questions to be structured
Output JSON Format
{
"questions": [
{
"id": "subject.ch1.001",
"content": "题目内容(去掉末尾的括号或空格)",
"options": ["选项A文本", "选项B文本", "选项C文本", "选项D文本"],
"answer": "正确答案字母(单选如A,多选如BCD)",
"explanation": "解析(可为空字符串)",
"type": "single_choice",
"difficulty": 3,
"source": "来源书名或课程名",
"nodes": ["subject.ch1"],
"formulas": [],
"siblings": []
}
]
}
Type Rules
| JSON type field | CryptoForge DB type |
options | answer | Notes |
|---|---|---|---|---|
single_choice → |
choice |
各选项文本数组 | 单个字母如 "A" | 单选 |
multi_choice → |
choice |
各选项文本数组 | 字母组合如 "BCD" | 多选,字母必须按顺序排列 |
true_false → |
choice |
固定为 ["对", "错"] | "对" 或 "错" | 判断题 |
fill → |
fill |
单项数组如 ["响应"] | 填空答案文本 | 填空题 |
CRITICAL for CryptoForge import: The type field stored in the DB must be choice or fill, NOT single_choice/multi_choice/true_false. The import script handles this remapping automatically.
ID Format Rules
Pattern: subject.chapter.number
- Subject: lowercase abbreviation must match CryptoForge
nameMap(see Integration section). Verify before creating new subjects. - Chapter:
ch0(绪论),ch1-ch8+, or type suffix (tf,sc,mc,fill) for generic question banks - Number: three-digit zero-padded (
001,015,123)
Examples: marxism.ch1.001, cisa.ch3.015, computer_org.ch1.003, computer_org.ch9.fill.001
Chapter Mapping
Infer the chapter from question content:
- 绪论/导论 →
ch0 - 第一章 →
ch1 - 第二章 →
ch2 - 第三章 →
ch3 - 第四章 →
ch4 - 第五章 →
ch5 - 判断题无法判断 →
tf
If the source material uses domain-based structure (like CISA), map domains to chapters:
- Domain 1 → ch1
- Domain 2 → ch2
- etc.
Difficulty Rules
| Level | Value | Criteria |
|---|---|---|
| 简单 | 2 | Basic definition recall, straightforward fact questions |
| 中等 | 3 | Understanding and application, requires some reasoning |
| 较难 | 4 | Comprehensive analysis, multi-step reasoning, scenario-based |
Cleaning Rules
- Strip option prefixes: Remove leading letter labels like "A. ", "B、", "A)", "B."
- Trim whitespace: Remove leading/trailing spaces from options and content
- Sort multi-choice answers: "BD" not "DB", "ACD" not "CDA"
- Split true/false inline: If question text contains "对/错" at the end, separate it
- Remove trailing markers: Strip trailing parentheses, brackets, or spaces from content
- Skip invalid questions: If content or answer is missing, skip the question
Workflow
Step 1: Parse Source
- If from PDF/EPUB: use
pdf-deep-readingor EPUB extraction first - If pasted text: parse directly
Step 2: Identify Question Type
Look for:
A. ... B. ... C. ... D. ...with one correct →single_choiceA. ... B. ... C. ... D. ...with multiple correct →multi_choice- Statements ending with
对/错or√/×→true_false
Step 3: Determine Subject and Chapter
- Infer subject from the source (e.g., Marxism →
marxism, CISA →cisa) - Map question content to chapter using the chapter mapping rules
Step 4: Clean and Format
Apply all cleaning rules. Ensure:
- JSON is valid (no trailing commas, proper escaping)
- All required fields present: id, content, options, answer, explanation, type, difficulty, source, nodes, formulas, siblings
Step 5: Output
- Output raw JSON, NOT wrapped in markdown code blocks (```json)
- Save to file if user requests:
C:Users13657Desktop{name}_题库.json
Integration
| User Intent | Skill Chain |
|---|---|
| Feed book → generate questions | textbook-learning → question-bank-formatter |
| Pasted exam questions → format | question-bank-formatter directly |
| PDF of exam → format questions | pdf-deep-reading → question-bank-formatter |
| Translate English bank → Chinese | question-bank-formatter + model translation |
| Import into CryptoForge DB | question-bank-formatter → direct SQLite script (see below) |
CryptoForge DB Direct Import
For "导入到X科目" requests, use the direct SQLite import script not the HTTP API (which requires a file upload + confirm two-step). Full operational guide: references/cryptoforge-import.md. Template script: scripts/import_questions.js.
Mandatory rules:
- Subject prefix MUST match
nameMapinserver/index.js(e.g.,computer_orgnotcomp_org) — verify the map first - DB
typefield: usechoiceorfill(NOTsingle_choice/multi_choice/true_false) - sql.js is in-memory — direct
.dbfile writes are invisible to running server. You MUST restart the server after every import - After restart, verify with API:
curl http://localhost:8967/api/questions?subject=XXX&chapter=N - Before starting, check existing chapter count:
curl http://localhost:8967/api/questions?subject=XXX&limit=200to avoid duplicates
Server restart procedure:
# 1. Find PID
netstat -ano | grep 8967 | grep LISTENING
# 2. Kill
taskkill //F //PID <PID>
# 3. Start (use foreground timeout trick — background=true causes "stdin is not a tty")
cd C:/Users/13657/Desktop/cryptoforge && node start_server.js
# 4. Wait, then verify
sleep 3 && curl http://localhost:8967/api/health
Fill-in-the-blank (填空题) format for CryptoForge:
type:filloptions: single-element array with the answer, e.g.,["响应"]or multi-blank array["WCR", "MAR", "DAR", "0"]answer: comma-joined answer text, e.g.,"响应"or"WCR,MAR,DAR,0"- Short answer (简答题) also uses
type: fill
HTTP API fallback (only if import script unavailable): POST /api/import/upload (multipart file) → POST /api/import/confirm with {filePath, subject, chapter, overwrite}
Pitfalls
- Don't wrap in markdown code blocks — output raw JSON unless saving to file
- Multi-choice answer sorting — "BD" not "DB", use alphabetical order
- True/false must use Chinese — options are ["对", "错"], answer is "对" or "错"
- Don't change the chapter mapping mid-batch — use the same subject.chapter scheme throughout
- When book has domain structure (like CISA) — map Domain 1→ch1, Domain 2→ch2, etc., and note the mapping
- Don't lose the explanation — even if from the source material, carry it through
- Difficulty should be consistent within a batch — basic recall=2, applied=3, scenario/analysis=4
- EPUB HTML class variants — McGraw-Hill practice exam books use BOTH
class="ques"ANDclass="ques1"for question blocks in the answer section. Always search for both:<p class="ques[^"]*". Similarly, answer sections may usetick(correct) +check(incorrect explanation) instead of explicit answer letter markers. Seereferences/mcgraw-hill-epub-patterns.mdfor the full HTML structure. - Parse answers from the ANSWER section, not the Q section — for practice exam books, the answer section contains the most reliable correct-answer data (via
tickmarkers). The question section alone lacks answer data. - CTF/domain-heavy books can be imported as layered knowledge — map broad book parts to coarse chapter nodes first, then add finer subnodes from section headings so the database stays navigable without exploding node count.
- Keep source names user-facing — if the book title is long or noisy, use the concise display title in
source, but keep the full title in the generated file name when saving the bank. - For large EPUBs, extract a concise knowledge index first — chapter titles + key subtopics are often enough to drive question generation and node mapping without fully mirroring every paragraph.
- When importing into CryptoForge, preserve importable fields exactly —
optionsshould stay JSON-encoded text,nodes/formulas/siblingsarrays should be present, and novel node ids are created automatically fromnodesduring import. - Subject prefix must match existing nameMap — check
server/index.jsnameMapbefore inventing a new subject ID. Wrong prefix = questions land under an invisible subject (e.g.,comp_orgvscomputer_org). - Server restart is mandatory after direct DB writes — sql.js loads the
.dbfile into memory at startup. Writing the file from an external script while the server runs has zero effect until restart. Usenetstat -ano | grep 8967 | grep LISTENINGto find PID, thentaskkill //F //PID <PID>, thennode start_server.js. - Background mode fails for server startup — Hermes TUI
terminal(background=true)causes "stdin is not a tty" error with the CryptoForge Node.js server. Instead, use the foreground timeout trick: runnode start_server.jsas a foreground command with a short timeout. The server continues running in the background after the terminal call times out. - Deduplicate before import — Check existing questions via API (
curl http://localhost:8967/api/questions?subject=XXX&chapter=N&limit=200) before bulk-inserting. If the same chapter already has questions from a prior batch (e.g., old ID formatch9.q01vs newch9.sc.001), delete the old batch first to avoid duplicates showing up in the UI. - Fill-in-the-blank (填空题) import format — For CryptoForge:
typemust befill(notfill_blank),optionsshould be a single-element array or multi-blank array with the answer text,answeris the answer text (comma-joined for multi-blank). Short answer / 简答题 also usestype: fill. The import script does NOT shuffle fill question options (only shuffleschoicetype).




