feat: 汉字介绍待续
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
const fs = require('fs');
|
||||
|
||||
// Read char_common_base.json (each line is a JSON object)
|
||||
const basePath = '/Users/joey-xd/sites/pipi-learn/platform-pipi/apps/api/src/data/char_common_base.json';
|
||||
const baseText = fs.readFileSync(basePath, 'utf8').trim();
|
||||
const baseLines = baseText.split('\n').filter(l => l.trim());
|
||||
const chars = baseLines.map(l => {
|
||||
let cleaned = l.trim().replace(/,$/, '');
|
||||
return JSON.parse(cleaned);
|
||||
});
|
||||
|
||||
console.log(`总字数: ${chars.length}`);
|
||||
|
||||
const singlePinyin = chars.filter(c => c.pinyin.length === 1);
|
||||
const multiPinyin = chars.filter(c => c.pinyin.length > 1);
|
||||
|
||||
console.log(`单音字: ${singlePinyin.length}`);
|
||||
console.log(`多音字: ${multiPinyin.length}`);
|
||||
|
||||
// Count by number of pinyins
|
||||
const byCount = {};
|
||||
multiPinyin.forEach(c => {
|
||||
const n = c.pinyin.length;
|
||||
if (!byCount[n]) byCount[n] = [];
|
||||
byCount[n].push(c);
|
||||
});
|
||||
|
||||
Object.keys(byCount).sort().forEach(n => {
|
||||
console.log(`\n=== ${n} 个读音 (${byCount[n].length} 字) ===`);
|
||||
byCount[n].forEach(c => {
|
||||
console.log(` ${c.char}: [${c.pinyin.join(', ')}]`);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user