# baojie/shiji-kb architecture

> Architecture diagram of the GitHub repository baojie/shiji-kb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/baojie/shiji-kb
- Repository: https://github.com/baojie/shiji-kb

## Overview

史记知识库将《史记》转化为可阅读、检索和探索的结构化历史知识：主要路径是文本标注与实体、事件、关系等知识构建，随后通过阅读器、时间线和 Wiki 呈现。图中保留 README 强调的知识工程阶段与主要应用；实验标注和 Wiki API 展示为有代码证据的内部实现。README 描述了整体能力，但部分数据构建与展示实现未采样，因此相关边仅采用其明确说明。

Main entry points: [`kg/entities`](https://github.com/baojie/shiji-kb/tree/main/kg/entities) (实体标注), [`labs/hybrid-semantic-analysis/run_experiments.py`](https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/run_experiments.py) (标注实验编排), [`kg/events`](https://github.com/baojie/shiji-kb/tree/main/kg/events) (事件构建), [`labs/hybrid-semantic-analysis/utils/base.py`](https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/utils/base.py) (标注数据工具)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_knowledge["知识构建"]
  node_annotation["实体标注"]
  node_events["事件构建"]
  node_relations["事件关系"]
  node_chronology["年代与时间线"]
  node_ontology["本体与推理"]
  node_genealogy["谱系与分类"]
  node_vocab["词汇与事实"]
end

subgraph group_reading["阅读与探索"]
  node_reader["章节阅读器"]
  node_reader_ui["阅读交互<br/>[game.js]"]
  node_metro["史记地铁图<br/>[metro.js]"]
end

subgraph group_wiki["Wiki 服务"]
  node_wiki_pages["知识 Wiki"]
  node_wiki_server["Wiki 服务端<br/>[serve.py]"]
  node_api_router["API 路由<br/>[router.js]"]
  node_api_auth["Bearer 鉴权<br/>[auth.js]"]
  node_query_handler["语义查询<br/>[query.js]"]
  node_semantic_db[("语义数据存储<br/>[db.js]")]
end

subgraph group_research["标注实验"]
  node_experiment["标注实验编排<br/>[run_experiments.py]"]
  node_local_method["本地模型标注<br/>[method_a_local.py]"]
  node_hybrid_method["混合标注<br/>[method_b_hybrid.py]"]
  node_llm_method["LLM 标注<br/>[method_c_llm.py]"]
  node_annotation_utils["标注数据工具<br/>[base.py]"]
  node_evaluator["结果评估<br/>[evaluator.py]"]
end

node_source["《史记》文本"]

node_source -->|"标注文本"| node_annotation
node_annotation -->|"构建知识"| node_events
node_events -->|"抽取关系"| node_relations
node_events -->|"校准年代"| node_chronology
node_annotation -->|"支撑推理"| node_ontology
node_annotation -->|"关联谱系"| node_genealogy
node_annotation -->|"生成索引"| node_vocab
node_annotation -->|"提供标注"| node_reader
node_reader -->|"呈现交互"| node_reader_ui
node_chronology -->|"构建时间线"| node_metro
node_annotation -->|"生成词条"| node_wiki_pages
node_events -->|"整合事件页"| node_wiki_pages
node_wiki_server -.->|"承载 API"| node_api_router
node_api_router -->|"检查鉴权"| node_api_auth
node_api_router -.->|"分发请求"| node_query_handler
node_query_handler -->|"读取实体"| node_semantic_db
node_experiment -->|"运行方案"| node_local_method
node_experiment -->|"运行方案"| node_hybrid_method
node_experiment -->|"运行方案"| node_llm_method
node_experiment -->|"评估结果"| node_evaluator
node_local_method -.->|"使用工具"| node_annotation_utils
node_hybrid_method -->|"委托标注"| node_local_method
node_hybrid_method -.->|"使用工具"| node_annotation_utils
node_llm_method -->|"解析结果"| node_annotation_utils
node_evaluator -->|"计算指标"| node_annotation_utils

click node_annotation "https://github.com/baojie/shiji-kb/tree/main/kg/entities"
click node_events "https://github.com/baojie/shiji-kb/tree/main/kg/events"
click node_relations "https://github.com/baojie/shiji-kb/tree/main/kg/relations"
click node_chronology "https://github.com/baojie/shiji-kb/tree/main/kg/chronology"
click node_ontology "https://github.com/baojie/shiji-kb/tree/main/kg/ontology"
click node_genealogy "https://github.com/baojie/shiji-kb/tree/main/kg/genealogy"
click node_vocab "https://github.com/baojie/shiji-kb/tree/main/kg/vocabularies"
click node_reader "https://github.com/baojie/shiji-kb/blob/main/render_shiji_html.py"
click node_reader_ui "https://github.com/baojie/shiji-kb/blob/main/app/game/game.js"
click node_metro "https://github.com/baojie/shiji-kb/blob/main/app/metro/metro.js"
click node_wiki_pages "https://github.com/baojie/shiji-kb/tree/main/wiki/scripts"
click node_wiki_server "https://github.com/baojie/shiji-kb/blob/main/wiki/server/serve.py"
click node_api_router "https://github.com/baojie/shiji-kb/blob/main/wiki/server/api/router.js"
click node_api_auth "https://github.com/baojie/shiji-kb/blob/main/wiki/server/api/auth.js"
click node_query_handler "https://github.com/baojie/shiji-kb/blob/main/wiki/server/api/handlers/query.js"
click node_semantic_db "https://github.com/baojie/shiji-kb/blob/main/wiki/server/api/db.js"
click node_experiment "https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/run_experiments.py"
click node_local_method "https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/methods/method_a_local.py"
click node_hybrid_method "https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/methods/method_b_hybrid.py"
click node_llm_method "https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/methods/method_c_llm.py"
click node_annotation_utils "https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/utils/base.py"
click node_evaluator "https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/utils/evaluator.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_annotation,node_events,node_relations,node_chronology,node_ontology,node_genealogy,node_vocab toneBlue
class node_reader,node_reader_ui,node_metro toneAmber
class node_wiki_pages,node_wiki_server,node_api_router,node_api_auth,node_query_handler,node_semantic_db toneMint
class node_experiment,node_local_method,node_hybrid_method,node_llm_method,node_annotation_utils,node_evaluator toneRose
class node_source toneIndigo
```

## Components

### 知识构建

- [实体标注](https://github.com/baojie/shiji-kb/tree/main/kg/entities): `kg/entities`
- [事件构建](https://github.com/baojie/shiji-kb/tree/main/kg/events): `kg/events`
- [事件关系](https://github.com/baojie/shiji-kb/tree/main/kg/relations): `kg/relations`
- [年代与时间线](https://github.com/baojie/shiji-kb/tree/main/kg/chronology): `kg/chronology`
- [本体与推理](https://github.com/baojie/shiji-kb/tree/main/kg/ontology): `kg/ontology`
- [谱系与分类](https://github.com/baojie/shiji-kb/tree/main/kg/genealogy): `kg/genealogy`
- [词汇与事实](https://github.com/baojie/shiji-kb/tree/main/kg/vocabularies): `kg/vocabularies`

### 阅读与探索

- [章节阅读器](https://github.com/baojie/shiji-kb/blob/main/render_shiji_html.py): `render_shiji_html.py`
- [阅读交互](https://github.com/baojie/shiji-kb/blob/main/app/game/game.js): `app/game/game.js`
- [史记地铁图](https://github.com/baojie/shiji-kb/blob/main/app/metro/metro.js): `app/metro/metro.js`

### Wiki 服务

- [知识 Wiki](https://github.com/baojie/shiji-kb/tree/main/wiki/scripts): `wiki/scripts`
- [Wiki 服务端](https://github.com/baojie/shiji-kb/blob/main/wiki/server/serve.py): `wiki/server/serve.py`
- [API 路由](https://github.com/baojie/shiji-kb/blob/main/wiki/server/api/router.js): `wiki/server/api/router.js`
- [Bearer 鉴权](https://github.com/baojie/shiji-kb/blob/main/wiki/server/api/auth.js): `wiki/server/api/auth.js`
- [语义查询](https://github.com/baojie/shiji-kb/blob/main/wiki/server/api/handlers/query.js): `wiki/server/api/handlers/query.js`
- [语义数据存储](https://github.com/baojie/shiji-kb/blob/main/wiki/server/api/db.js): `wiki/server/api/db.js`

### 标注实验

- [标注实验编排](https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/run_experiments.py): `labs/hybrid-semantic-analysis/run_experiments.py`
- [本地模型标注](https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/methods/method_a_local.py): `labs/hybrid-semantic-analysis/methods/method_a_local.py`
- [混合标注](https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/methods/method_b_hybrid.py): `labs/hybrid-semantic-analysis/methods/method_b_hybrid.py`
- [LLM 标注](https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/methods/method_c_llm.py): `labs/hybrid-semantic-analysis/methods/method_c_llm.py`
- [标注数据工具](https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/utils/base.py): `labs/hybrid-semantic-analysis/utils/base.py`
- [结果评估](https://github.com/baojie/shiji-kb/blob/main/labs/hybrid-semantic-analysis/utils/evaluator.py): `labs/hybrid-semantic-analysis/utils/evaluator.py`

### Other components

- **《史记》文本**

## Connections

- 《史记》文本 → 实体标注: 标注文本 (evidence: `README.md`)
- 实体标注 → 事件构建: 构建知识 (evidence: `README.md`)
- 事件构建 → 事件关系: 抽取关系 (evidence: `README.md`)
- 事件构建 → 年代与时间线: 校准年代 (evidence: `README.md`)
- 实体标注 → 本体与推理: 支撑推理 (evidence: `README.md`)
- 实体标注 → 谱系与分类: 关联谱系 (evidence: `README.md`)
- 实体标注 → 词汇与事实: 生成索引 (evidence: `README.md`)
- 实体标注 → 章节阅读器: 提供标注 (evidence: `README.md`)
- 章节阅读器 → 阅读交互: 呈现交互 (evidence: `README.md`)
- 年代与时间线 → 史记地铁图: 构建时间线 (evidence: `README.md`)
- 实体标注 → 知识 Wiki: 生成词条 (evidence: `README.md`)
- 事件构建 → 知识 Wiki: 整合事件页 (evidence: `README.md`)
- Wiki 服务端 → API 路由: 承载 API
- API 路由 → Bearer 鉴权: 检查鉴权 (evidence: `wiki/server/api/router.js`)
- API 路由 → 语义查询: 分发请求 (evidence: `wiki/server/api/handlers/query.js`)
- 语义查询 → 语义数据存储: 读取实体 (evidence: `wiki/server/api/handlers/query.js`)
- 标注实验编排 → 本地模型标注: 运行方案 (evidence: `labs/hybrid-semantic-analysis/run_experiments.py`)
- 标注实验编排 → 混合标注: 运行方案 (evidence: `labs/hybrid-semantic-analysis/run_experiments.py`)
- 标注实验编排 → LLM 标注: 运行方案 (evidence: `labs/hybrid-semantic-analysis/run_experiments.py`)
- 标注实验编排 → 结果评估: 评估结果 (evidence: `labs/hybrid-semantic-analysis/run_experiments.py`)
- 本地模型标注 → 标注数据工具: 使用工具
- 混合标注 → 本地模型标注: 委托标注 (evidence: `labs/hybrid-semantic-analysis/methods/method_b_hybrid.py`)
- 混合标注 → 标注数据工具: 使用工具
- LLM 标注 → 标注数据工具: 解析结果 (evidence: `labs/hybrid-semantic-analysis/methods/method_c_llm.py`)
- 结果评估 → 标注数据工具: 计算指标 (evidence: `labs/hybrid-semantic-analysis/utils/evaluator.py`)
