File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -79,3 +79,26 @@ extract(
79
79
// { keyword: '天气', weight: 1.0766573240983333 }
80
80
// ]
81
81
```
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
+ ```
You can’t perform that action at this time.
0 commit comments