34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
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(', ')}]`);
|
|
});
|
|
});
|