Classical Text Merger Skill
A skill to merge classical Chinese texts (like the Daodejing) with their modern translations, handling inconsistent numbering and chapter matching.
Overview
This skill provides a robust way to take two files—one with original classical Chinese text and another with modern translations—and merge them into a single, well-formatted document. It intelligently handles:
- •Mixed numbering formats (Chinese vs. Arabic numerals).
- •Inconsistent chapter headers.
- •Potential mislabeling or shifts in chapter numbering in source files.
Files
- •
merge_daodejing.js: The core Node.js script that performs the parsing and merging logic. - •
道德经原文.txt: Source file for original text. - •
道德经翻译.txt: Source file for translations.
Usage
To merge the files, run the following command in the terminal:
powershell
node merge_daodejing.js
The script will:
- •Parse the original text, extracting chapters based on Chinese numeral headers (e.g., 第一章).
- •Parse the translation text, extracting chapters based on bracketed or bolded headers (e.g., 第1章).
- •Convert all chapter numbers to a common Arabic format for matching.
- •Apply correction logic for any known numbering shifts in the source translation.
- •Generate
道德经-原文与翻译.txt.
Matching Logic Details
The skill uses a chineseToNumber utility to normalize chapter identifiers:
- •Handles single digits: 一 -> 1
- •Handles tens: 十一 -> 11, 二十 -> 20, 二十一 -> 21
- •Handles custom shifts (e.g., if Chapter 67 in the source is actually Chapter 80).
Output Format
The merged file follows this structure:
text
第[编号]章 ------------------------------------------------------------ 【原文】 [原文内容] 【翻译】 [翻译内容] ============================================================