/** * 清理语料:去掉非CJK字符,写入 corpus.txt */ import * as fs from "fs"; import * as path from "path"; function main() { const input = "data/corpus_large.txt"; const output = "data/corpus.txt"; console.log(`读取: ${input}`); const raw = fs.readFileSync(input, "utf-8"); console.log(`原始字符数: ${raw.length}`); // 保留CJK汉字、中文标点、换行 const cleaned = raw.replace(/[^\u4E00-\u9FFF\u3000-\u303F\uFF00-\uFFEF\u2014\u2018-\u201D\u2026\n\r]/g, ""); console.log(`清理后字符数: ${cleaned.length}`); fs.writeFileSync(output, cleaned, "utf-8"); console.log(`已写入: ${output}`); } main();