fix: 修复nlp停用词调用顺序问题导致的报错

This commit is contained in:
digua
2026-03-15 15:13:54 +08:00
committed by digua
parent ef7ac49959
commit 3ab730baae
3 changed files with 228 additions and 31 deletions
+2 -1
View File
@@ -79,7 +79,8 @@ export function getWordFrequency(params: WordFrequencyParams): WordFrequencyResu
// 收集词性统计(用于显示每个词性有多少词,仅中文有效)
let posTagStats: PosTagStat[] | undefined
if ((locale as string).startsWith('zh')) {
// 词性统计只对中文生效,这里先做类型兜底,避免异常 locale 直接触发 startsWith 报错。
if (typeof locale === 'string' && locale.startsWith('zh')) {
const posStatsMap = collectPosTagStats(texts, minWordLength ?? 2, enableStopwords)
posTagStats = [...posStatsMap.entries()].map(([tag, count]) => ({ tag, count }))
}