MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / getJieba

Function getJieba

packages/node-runtime/src/nlp/segmenter.ts:60–86  ·  view source on GitHub ↗
(dictType: DictType = 'default')

Source from the content-addressed store, hash-verified

58 * 获取 Jieba 实例(支持多词库)
59 */
60export function getJieba(dictType: DictType = 'default'): JiebaInstance {
61 const effectiveType = dictType === 'default' ? 'zh-CN' : dictType
62 const cached = jiebaInstances.get(effectiveType)
63 if (cached) {
64 if (existsDictOnDisk(effectiveType)) return cached
65 jiebaInstances.delete(effectiveType)
66 console.log(`[NLP] jieba cache invalidated (dict missing): ${effectiveType}`)
67 }
68
69 try {
70 const { Jieba } = require('@node-rs/jieba')
71 let instance: JiebaInstance
72 const diskDict = tryLoadDictFromDisk(effectiveType)
73 if (diskDict) {
74 instance = Jieba.withDict(diskDict)
75 console.log(`[NLP] jieba dict loaded: ${effectiveType} (${diskDict.length} bytes)`)
76 } else {
77 instance = new Jieba()
78 console.warn(`[NLP] jieba dict missing: ${effectiveType}, fallback to built-in tokenizer`)
79 }
80 jiebaInstances.set(effectiveType, instance)
81 return instance
82 } catch (error) {
83 console.error(`[NLP] Failed to load jieba module (dict=${effectiveType}):`, error)
84 throw new Error(`jieba 模块加载失败 (${effectiveType})`)
85 }
86}
87
88/**
89 * 清除指定词库的缓存实例(词库更新后调用)

Callers 8

tagFunction · 0.90
extractFtsKeywordsFunction · 0.90
tokenizeForFtsFunction · 0.90
tokenizeQueryForFtsFunction · 0.90
tagFunction · 0.90
segmentChineseFunction · 0.85
collectPosTagStatsFunction · 0.85

Calls 7

existsDictOnDiskFunction · 0.85
tryLoadDictFromDiskFunction · 0.85
setMethod · 0.80
getMethod · 0.65
deleteMethod · 0.65
warnMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected