58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { SentenceGenerator } from '../src/module/sentence-generator.ts';
|
|
import { writeFileSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const outputPath = join(__dirname, '../data/sentence-01.json');
|
|
|
|
console.log('🚀 开始生成1000条哲理句...\n');
|
|
|
|
const generator = new SentenceGenerator({
|
|
count: 1000,
|
|
outputFormat: 'json',
|
|
withTags: true,
|
|
templateTypes: ['对比', '因果', '隐喻', '判断']
|
|
});
|
|
|
|
const results = generator.generateAndOutput() as any[];
|
|
|
|
// 添加元信息
|
|
const outputData = {
|
|
meta: {
|
|
total: results.length,
|
|
generatedAt: new Date().toISOString(),
|
|
generator: 'sentence-generator.ts',
|
|
version: '1.0'
|
|
},
|
|
sentences: results
|
|
};
|
|
|
|
// 写入文件
|
|
writeFileSync(outputPath, JSON.stringify(outputData, null, 2), 'utf-8');
|
|
|
|
console.log(`✅ 成功生成 ${results.length} 条句子`);
|
|
console.log(`📁 输出到: ${outputPath}\n`);
|
|
|
|
// 打印统计信息
|
|
console.log('📊 主题分布统计:');
|
|
const stats = generator.getStats();
|
|
const sortedStats = Object.entries(stats)
|
|
.sort(([, a], [, b]) => b - a)
|
|
.slice(0, 10);
|
|
|
|
sortedStats.forEach(([theme, count]) => {
|
|
const bar = '█'.repeat(Math.floor(count / 10));
|
|
console.log(` ${theme.padEnd(6)}: ${count.toString().padStart(4)} ${bar}`);
|
|
});
|
|
|
|
console.log(`\n📋 模板类型分布:`);
|
|
const templateCount: Record<string, number> = {};
|
|
results.forEach((s: any) => {
|
|
const type = s.template.split(/[\d]/)[0] || s.template;
|
|
templateCount[type] = (templateCount[type] || 0) + 1;
|
|
});
|
|
Object.entries(templateCount).forEach(([type, count]) => {
|
|
console.log(` ${type}: ${count} 条`);
|
|
});
|