(text: string)
| 132 | } |
| 133 | |
| 134 | function 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 | * 通用分词入口 |