Skip to content

Commit 8ed60b8

Browse files
authored
doc: [jieba] add documentation for custom dictionaries (#812)
1 parent ee3defd commit 8ed60b8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/jieba/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,26 @@ extract(
7979
// { keyword: '天气', weight: 1.0766573240983333 }
8080
// ]
8181
```
82+
83+
### Load custom dictionaries
84+
85+
```javascript
86+
const { loadDict, cut } = require('@node-rs/jieba')
87+
const customDict = [
88+
'哪行 50',
89+
'干一行 51',
90+
'行一行 52',
91+
'行行 53',
92+
]
93+
94+
const dictBuffer = Buffer.from(customDict.join('\n'), 'utf-8')
95+
// loadDict doc: https://github.com/fxsjy/jieba?tab=readme-ov-file#%E8%BD%BD%E5%85%A5%E8%AF%8D%E5%85%B8
96+
loadDict(dictBuffer)
97+
98+
const text = '人要是行干一行行一行,一行行行行行,行行行干哪行都行'
99+
const output = cut(text, false)
100+
console.log('分词结果⤵️\n', output.join('/'))
101+
// Before: 人/要是/行/干/一行行/一行/,/一行行/行/行/行/,/行/行/行/干/哪/行/都行
102+
// After: 人/要是/行/干一行/行一行/,/一行行/行行/行/,/行行/行/干/哪行/都行
103+
// Pinyin: rén yào shi xíng gàn yì háng xíng yì háng , yì háng xíng háng háng xíng , háng háng xíng gàn nǎ háng dōu xíng
104+
```

0 commit comments

Comments
 (0)