feat: 重构话题,话题新增话题卡片

This commit is contained in:
digua
2026-04-13 00:21:59 +08:00
committed by digua
parent 6254a234ec
commit e628390111
15 changed files with 809 additions and 271 deletions
+16 -9
View File
@@ -5,7 +5,14 @@
import { openDatabase, buildTimeFilter, type TimeFilter } from '../core'
import { segment, batchSegmentWithFrequency, getPosTagDefinitions, collectPosTagStats } from '../../nlp'
import type { SupportedLocale, WordFrequencyResult, WordFrequencyParams, PosTagInfo, PosTagStat, DictType } from '../../nlp'
import type {
SupportedLocale,
WordFrequencyResult,
WordFrequencyParams,
PosTagInfo,
PosTagStat,
DictType,
} from '../../nlp'
/**
* 获取词频统计
@@ -80,7 +87,7 @@ export function getWordFrequency(params: WordFrequencyParams): WordFrequencyResu
posTagStats = [...posStatsMap.entries()].map(([tag, count]) => ({ tag, count }))
}
const wordFrequency = batchSegmentWithFrequency(texts, locale as SupportedLocale, {
const result = batchSegmentWithFrequency(texts, locale as SupportedLocale, {
minLength: minWordLength,
minCount,
topN,
@@ -91,22 +98,22 @@ export function getWordFrequency(params: WordFrequencyParams): WordFrequencyResu
excludeWords,
})
let totalWords = 0
for (const count of wordFrequency.values()) {
totalWords += count
let topNTotalWords = 0
for (const count of result.words.values()) {
topNTotalWords += count
}
const words = [...wordFrequency.entries()].map(([word, count]) => ({
const words = [...result.words.entries()].map(([word, count]) => ({
word,
count,
percentage: totalWords > 0 ? Math.round((count / totalWords) * 10000) / 100 : 0,
percentage: topNTotalWords > 0 ? Math.round((count / topNTotalWords) * 10000) / 100 : 0,
}))
return {
words,
totalWords,
totalWords: result.totalWords,
totalMessages: messages.length,
uniqueWords: wordFrequency.size,
uniqueWords: result.uniqueWords,
posTagStats,
}
}