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

Function segmentJapanese

packages/node-runtime/src/nlp/segmenter.ts:134–143  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

132}
133
134function segmentJapanese(text: string): string[] {
135 const cleaned = cleanText(text)
136 if (!cleaned) return []
137 try {
138 const segmenter = new Intl.Segmenter('ja', { granularity: 'word' })
139 return [...segmenter.segment(cleaned)].filter((s) => s.isWordLike).map((s) => s.segment)
140 } catch {
141 return cleaned.split('').filter((ch) => ch.trim().length > 0)
142 }
143}
144
145/**
146 * 通用分词入口

Callers 1

segmentFunction · 0.85

Calls 1

cleanTextFunction · 0.90

Tested by

no test coverage detected