mcpField
M
memory-literary-analysis

memory-literary-analysis

github.com/basicmachines-co生产力23532 次安装28 周前更新
代码仓库

关于 memory-literary-analysis

memory-literary-analysis 是将完整文学作品整理为结构化知识图谱的技能,适合文学研究、教学和读书讨论。它按章节处理人物、主题、地点、象征与文学手法,并提供交叉关联、验证和可视化流程。

主要功能

  1. 01设置实体模式与目录结构
  2. 02按章节批量处理作品
  3. 03记录人物、主题及文学元素
  4. 04交叉引用并撰写综合分析
  5. 05验证模式与关系一致性
  6. 06生成画布进行可视化

适用场景

  1. 01为小说或戏剧制作学习资料
  2. 02构建读书会作品参考图谱
  3. 03开展全书结构化细读研究
  4. 04检查大型文学笔记集的一致性

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/basicmachines-co/basic-memory-skills --skill memory-literary-analysis

安装后在 Claude Code 中输入/memory-literary-analysis确认已加载。

详细介绍

记忆文学分析

将一部完整的文学作品转换为结构化的知识图谱。人物、主题、章节、地点、象征和文学手法都成为相互关联的笔记——可搜索、可验证、可视化。

何时使用

  • 端到端分析一部小说、戏剧、诗歌或非虚构书籍
  • 为文学文本构建教学或学习资源
  • 创建读书会配套知识库
  • 需要结构化细读的研究项目
  • 大规模压力测试 Basic Memory(约 200+ 条笔记,1000+ 条关系)

流程概览

Phase 0: Setup         → project, schemas, directory structure
Phase 1: Seed          → stub notes for known major entities
Phase 2: Process       → chapter-by-chapter notes in batches
Phase 3: Cross-ref     → enrich arcs, add parallels, write analysis
Phase 4: Validate      → schema checks, drift detection, consistency
Phase 5: Visualize     → canvas files for character webs, timelines

阶段 0:设置

创建项目
create_memory_project(name="<work-name>", path="~/basic-memory/<work-name>")

使用作品标题的 kebab-case 短标识(例如 great-gatsby、hamlet、beloved)。

定义 Schema

将 6 个 schema 笔记写入 schema/。每个 schema 定义实体类型的字段、观察类别和关系类型。根据作品调整字段——以下 schema 是起点,而非 rigid 模板。

Character Schema
write_note(
  title="Character",
  directory="schema",
  note_type="schema",
  metadata={
    "entity": "Character",
    "version": 1,
    "schema": {
      "role(enum)": "[protagonist, antagonist, supporting, minor], character's narrative role",
      "description": "string, brief character description",
      "first_appearance?": "string, chapter or scene of first appearance",
      "status?(enum)": "[alive, dead, unknown, transformed], character status at end of work"
    },
    "settings": {"validation": "warn"}
  },
  content="""# Character

Schema for character entity notes.

## Observations
- [convention] Major characters in characters/major/, minor in characters/minor/
- [convention] Observation categories: trait, motivation, arc, quote, appearance, relationship, symbolism, fate
- [convention] Relations: appears_in, contrasts_with, allied_with, commands, symbolizes, associated_with"""
)

根据需要添加作品特有的字段——例如军事小说中的 rank、家族传奇中的 house、奇幻作品中的 species。

Theme Schema
write_note(
  title="Theme",
  directory="schema",
  note_type="schema",
  metadata={
    "entity": "Theme",
    "version": 1,
    "schema": {
      "description": "string, what this theme explores",
      "prevalence(enum)": "[major, minor], how central to the work",
      "first_introduced?": "string, where theme first appears"
    },
    "settings": {"validation": "warn"}
  },
  content="""# Theme

Schema for thematic analysis notes.

## Observations
- [convention] Observation categories: definition, manifestation, evolution, counterpoint, quote, interpretation
- [convention] Relations: embodied_by, contrasts_with, reinforced_by, explored_in, expressed_through"""
)
Chapter Schema
write_note(
  title="Chapter",
  directory="schema",
  note_type="schema",
  metadata={
    "entity": "Chapter",
    "version": 1,
    "schema": {
      "chapter_number": "integer, sequential chapter number",
      "pov?": "string, point-of-view character or narrator mode",
      "setting?": "string, primary location",
      "narrative_mode?(enum)": "[dramatic, expository, reflective, epistolary, mixed], chapter's primary mode"
    },
    "settings": {"validation": "warn"}
  },
  content="""# Chapter

Schema for chapter-level analysis notes.

## Observations
- [convention] Chapters stored in chapters/ directory
- [convention] Observation categories: summary, event, tone, technique, quote, significance, foreshadowing
- [convention] Relations: features, set_in, explores, contains, employs, follows, precedes, parallels"""
)
Location Schema
write_note(
  title="Location",
  directory="schema",
  note_type="schema",
  metadata={
    "entity": "Location",
    "version": 1,
    "schema": {
      "description": "string, what this place is",
      "location_type(enum)": "[city, building, landscape, body_of_water, region, fictional, vehicle], type of place",
      "real_or_fictional(enum)": "[real, fictional, both], whether the place exists"
    },
    "settings": {"validation": "warn"}
  },
  content="""# Location

Schema for location and setting notes.

## Observations
- [convention] Observation categories: description, atmosphere, symbolism, significance, geography
- [convention] Relations: setting_for, associated_with, symbolizes, contains, part_of"""
)
Symbol Schema
write_note(
  title="Symbol",
  directory="schema",
  note_type="schema",
  metadata={
    "entity": "Symbol",
    "version": 1,
    "schema": {
      "description": "string, what the symbol is literally",
      "symbol_type(enum)": "[object, animal, color, action, natural_phenomenon, body_part], category of symbol",
      "primary_meaning": "string, most common interpretation"
    },
    "settings": {"validation": "warn"}
  },
  content="""# Symbol

Schema for symbolic element notes.

## Observations
- [convention] Observation categories: meaning, appearance, ambiguity, interpretation, quote, evolution
- [convention] Relations: represents, associated_with, appears_in, contrasts_with, located_at"""
)
LiteraryDevice Schema
write_note(
  title="LiteraryDevice",
  directory="schema",
  note_type="schema",
  metadata={
    "entity": "LiteraryDevice",
    "version": 1,
    "schema": {
      "description": "string, what the device is",
      "device_type(enum)": "[rhetorical, structural, figurative, narrative, dramatic], category",
      "frequency(enum)": "[pervasive, frequent, occasional, rare], how often used"
    },
    "settings": {"validation": "warn"}
  },
  content="""# LiteraryDevice

Schema for literary technique and device notes.

## Observations
- [convention] Observation categories: definition, usage, effect, example, significance
- [convention] Relations: used_in, characterizes, expresses, related_to"""
)
目录结构
<project>/
  schema/            # 6 schema definitions
  chapters/          # one note per chapter/section + prologue/epilogue
  characters/
    major/           # protagonist, antagonist, key supporting
    minor/           # named characters with limited roles
  themes/            # thematic analysis notes
  locations/         # settings and places
  symbols/           # symbolic elements
  literary-devices/  # techniques and devices
  analysis/          # cross-cutting synthesis
  tasks/             # processing tracker

阶段 1:种子实体

在处理章节之前,为主要实体创建存根笔记,以便 [[wiki-links]] 从一开始就能解析。

人物(主要)

为每个主要人物创建一个包含已知元数据的存根:

write_note(
  title="<Character Name>",
  directory="characters/major",
  note_type="Character",
  tags=["character", "major", "<role>"],
  metadata={"role": "<role>", "description": "<brief description>"},
  content="""# <Character Name>

## Observations
- [role] <Character's role in the work>
- [appearance] <Key physical description>

## Relations
- associated_with [[<Related Character>]]
- appears_in [[<Key Location>]]"""
)
种子清单

在开始阅读之前,先确定作品的主要实体。一个不错的初始清单:

类型典型数量应包含的内容
人物(主要)8-20主角、反派、关键配角
主题5-12作品探讨的核心关切
地点4-10主要场景、具有象征意义的地方
象征4-10具有多层含义的反复出现的物体、意象或母题

存根不必完整——它们提供 [[wiki-link]] 目标,并会在章节处理过程中得到充实。

阶段 2:章节处理

源文本准备

获取全文并确定章节/段落边界。对于公有领域作品,Project Gutenberg 是一个不错的来源。对于受版权保护的作品,请使用纸质或授权数字副本。

分批策略

每批处理约 10 章,以在深度与进度之间取得平衡。按叙事弧线或主题重点分组:

批次典型内容
1开篇:背景设定、人物介绍、世界观构建
2-3上升动作:冲突确立、关系发展
4-6中段:复杂化、转折点、主题深化
7-8高潮临近:升级、揭示、危机
最终高潮、结局、尾声

根据章节长度和密度调整批次大小。简短、动作密集的章节可以更大批量处理;冗长、哲理密集的章节可能需要更小的批次。

逐章工作流

对于每一章:

1. 仔细阅读该章。 如果使用源文本文件,请阅读相关部分。

2. 创建章节笔记:

write_note(
  title="Chapter <N> - <Title>",
  directory="chapters",
  note_type="Chapter",
  tags=["chapter", "<arc-phase>"],
  metadata={
    "chapter_number": <N>,
    "pov": "<narrator or POV character>",
    "setting": "<primary location>",
    "narrative_mode": "<mode>"
  },
  content="""# Chapter <N> - <Title>

## Observations
- [summary] <1-2 sentence synopsis>
- [event] <Key plot events>
- [tone] <Emotional and stylistic atmosphere>
- [technique] <Notable narrative techniques>
- [quote] "<Significant passage>"
- [significance] <Why this chapter matters to the whole>
- [foreshadowing] <Hints at future events>

## Relations
- features [[<Character>]]
- set_in [[<Location>]]
- explores [[<Theme>]]
- contains [[<Symbol>]]
- employs [[<Literary Device>]]
- follows [[Chapter <N-1> - <Previous Title>]]
- precedes [[Chapter <N+1> - <Next Title>]]"""
)

3. 充实相关实体:

edit_note(
  identifier="characters/major/<character-slug>",
  operation="append",
  heading="Observations",
  content="""- [arc] Ch.<N>: <What happens to this character>
- [quote] "<Attributed quote>" (Ch.<N>)"""
)

4. 跟踪进度,使用 memory-tasks 技能创建一个能在上下文压缩后存活的处理任务。

每章应捕获的内容
类别应寻找的内容
[summary]1-2 句话的章节梗概
[event]关键情节事件(行动、揭示、到来)
[tone]情感和风格氛围
[technique]叙事创新(视角转换、结构实验、类型融合)
[quote]令人难忘或具有主题意义的段落
[significance]这一章对整体的意义
[foreshadowing]对未来事件的暗示
逐章实体扩充

每处理完一章,就将观察结果追加到相关实体上:

  • 人物:[arc] 时刻、新的 [trait] 揭示、[quote] 归属
  • 主题:本章中的 [manifestation]、[evolution] 变化
  • 象征:带语境的 [appearance]、新的 [interpretation] 角度
  • 地点:所述及的 [atmosphere]、场景中的 [significance]
  • 文学手法:本章中的 [example]
添加散文与解读

结构化观察就位后,考虑为主要实体笔记添加解读性散文。使用 edit_note(operation="prepend") 在 Observations 部分之前插入 2-4 段评论性文章。这些散文应当:

  • 主张对人物、主题或象征的一种解读——而不只是描述它
  • 将实体与作品更宏大的关切以及文学传统联系起来
  • 包含明确标注为主观的意见("In my reading..."、"I find...")
  • 将有根据的主张建立在按章号引用的文本证据上

散文增添了结构化观察本身无法捕捉的解读质感。

阶段 3:交叉引用

所有章节处理完毕后:

人物弧光

为每个主要人物写一条完整的 [arc] 总结观察,涵盖其在整部作品中的轨迹。

主题演变

为每个主题添加 [evolution] 观察,追踪它从引入到解决的发展过程。

章节对照

在结构相似的章节之间添加 parallels 和 contrasts_with 关系(例如镜像场景、重复出现的场景设定、主题回响)。

分析笔记

在 analysis/ 中创建综合笔记:

write_note(
  title="Narrative Structure",
  directory="analysis",
  note_type="note",
  tags=["analysis", "structure"],
  content="""# Narrative Structure

Analysis of the work's narrative architecture.

## Observations
- [structure] <Overall arc description>
- [technique] <Key narrative strategies>
...

## Relations
- analyzes [[<Protagonist>]]
- analyzes [[<Key Character>]]
- explores [[<Central Theme>]]
..."""
)

推荐的分析笔记:

  • 叙事结构 —— 整体架构与节奏
  • 作品概览 —— 对完整作品的综合(摘要、论点、影响)
  • 批评接受 —— 历史与当代的解读
发现涌现实体

在章节处理过程中,会涌现新的次要人物、地点和象征。为任何出现在 3 章及以上或承载主题分量的实体创建笔记。

阶段 4:验证

Schema 验证
# Validate each entity type
schema_validate(noteType="Character")
schema_validate(noteType="Theme")
schema_validate(noteType="Chapter")
schema_validate(noteType="Location")
schema_validate(noteType="Symbol")
schema_validate(noteType="LiteraryDevice")
漂移检测
schema_diff(noteType="Character")
# ... for each type

修复发现的问题——常见修复:

  • 缺少必需的观察类别 → 通过 edit_note 添加它们
  • 枚举值超出允许集 → 更正元数据
  • 笔记中有但 schema 中没有的字段 → 若合理,则作为可选字段添加到 schema
关系一致性

抽查双向关系:若 Chapter X features [[Character]],那么 Character 是否有引用 Chapter X 的观察?修复缺口。

阶段 5:可视化

生成用于可视化探索的 canvas 文件:

# Character relationship web
canvas(query="type:Character AND role:protagonist OR role:antagonist OR role:supporting")

# Theme connections
canvas(query="type:Theme")

# Chapter timeline with key events
canvas(query="type:Chapter", layout="timeline")

适配其他体裁

此管线适用于任何文学文本。按体裁调整 schema:

体裁Schema 调整
小说基础 schema 原样可用;按需添加体裁专属的 Character 字段
戏剧添加 Act 和 Scene schema;Character 获得 speaking_lines 字段
诗集将 Chapter 替换为 Poem;添加 form、meter、rhyme_scheme 字段
非虚构将 Chapter 替换为 Section;添加 Argument、Evidence schema
短篇小说集添加带 narrator、setting、word_count 的 Story schema
史诗/神话添加 Deity、Prophecy schema;Location 获得 mythological_significance
回忆录Character schema 获得 relationship_to_narrator;添加 Memory schema
规模指导
作品长度批大小预估笔记数
中篇小说(约 40K 词)5-10 章约 50-80
长篇小说(约 80K 词)8-12 章约 100-150
长篇小说(约 200K+ 词)10-15 章约 200-300
系列(多卷)一次一卷每卷约 200+

相关技能

  • memory-schema — Schema 创建、验证和漂移检测
  • memory-tasks — 跨上下文压缩跟踪章节处理进度
  • memory-notes — 笔记编写模式、观察类别、wiki-links
  • memory-ingest — 将外部输入处理为结构化实体
  • memory-metadata-search — 通过 frontmatter 字段查询笔记
  • memory-lifecycle — 归档已完成的分析阶段

指南

  • 处理前先播种。 先创建实体存根,以便在章节处理期间 wiki-links 能立即解析。
  • 分批以保持理智。 一次处理约 10 章,兼顾深度与推进速度。用 Task 笔记跟踪进度。
  • 阅读源文本。 不要依赖记忆或摘要。在创建笔记前,阅读(或重新阅读)每一批次的实际文本。文本证据就是一切。
  • 观察是你的索引。 知识图谱的价值来自分类观察。类别要丰富,内容要具体。
  • 关系是你的网络。 每一章都应链接到角色、主题、地点和手法。每个实体都应链接回其出现的章节。
  • 迭代丰富。 实体笔记会随着每一章变得更加丰富。不要试图一开始就写出完美的角色笔记——边写边追加。
  • 添加散文以增加深度。 在结构化数据就位后,为主要笔记添加阐释性文章。散文能捕捉观察无法表达的内容:论点、细微差别、观点和声音。
  • 定期验证。 每批之后都运行 schema_validate,而不是只在最后运行。尽早发现漂移。
  • 慷慨引用。 文学分析依赖文本证据。将重要引文作为 [quote] 观察包含进来,并注明章节归属。
  • 审查并修订。 完成所有章节后,从外部视角审查整个图谱。寻找单薄的笔记、缺失的连接和覆盖空白。第一遍永远不是最后一遍。
  • 分析放在最后。 analysis/ 中的综合笔记应在处理完所有章节、掌握全貌后再写。

评论

支持 Markdown