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

Function segment

packages/node-runtime/src/nlp/segmenter.ts:148–171  ·  view source on GitHub ↗
(text: string, locale: SupportedLocale, options: SegmentOptions = {})

Source from the content-addressed store, hash-verified

146 * 通用分词入口
147 */
148export function segment(text: string, locale: SupportedLocale, options: SegmentOptions = {}): string[] {
149 const {
150 minLength,
151 posFilterMode = 'meaningful',
152 customPosTags,
153 enableStopwords = true,
154 dictType = 'default',
155 } = options
156 const isChinese = locale.startsWith('zh')
157 const isJapanese = locale === 'ja-JP'
158 const defaultMinLength = isChinese || isJapanese ? 2 : 3
159 const effectiveMinLength = minLength ?? defaultMinLength
160
161 let words: string[]
162 if (isChinese) {
163 words = segmentChinese(text, { posFilterMode, customPosTags, dictType })
164 } else if (isJapanese) {
165 words = segmentJapanese(text)
166 } else {
167 words = segmentEnglish(text)
168 }
169
170 return words.filter((word) => isValidWord(word, locale, effectiveMinLength, enableStopwords, isStopword))
171}
172
173/**
174 * 批量分词并统计词频

Callers 2

segmentTextFunction · 0.90

Calls 4

isValidWordFunction · 0.90
segmentChineseFunction · 0.85
segmentJapaneseFunction · 0.85
segmentEnglishFunction · 0.85

Tested by

no test coverage detected