nodejieba-plus 3.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/.github/FUNDING.yml +12 -0
  2. package/.github/workflows/github_release.yml +61 -0
  3. package/.github/workflows/npm_publish.yml +24 -0
  4. package/.github/workflows/stale-issues.yml +24 -0
  5. package/.github/workflows/test.yml +42 -0
  6. package/.gitmodules +3 -0
  7. package/.npmignore +15 -0
  8. package/CHANGELOG.md +360 -0
  9. package/CONTRIBUTING.md +78 -0
  10. package/LICENSE +21 -0
  11. package/README.md +349 -0
  12. package/binding.gyp +63 -0
  13. package/index.js +77 -0
  14. package/lib/index.cpp +3 -0
  15. package/lib/nodejieba.cpp +218 -0
  16. package/lib/nodejieba.h +28 -0
  17. package/lib/utils.h +47 -0
  18. package/package.json +48 -0
  19. package/submodules/cppjieba/.github/workflows/cmake.yml +51 -0
  20. package/submodules/cppjieba/.github/workflows/stale-issues.yml +24 -0
  21. package/submodules/cppjieba/.gitmodules +3 -0
  22. package/submodules/cppjieba/CHANGELOG.md +305 -0
  23. package/submodules/cppjieba/CMakeLists.txt +42 -0
  24. package/submodules/cppjieba/LICENSE +20 -0
  25. package/submodules/cppjieba/README.md +280 -0
  26. package/submodules/cppjieba/deps/limonp/.github/workflows/cmake.yml +43 -0
  27. package/submodules/cppjieba/deps/limonp/.gitmodules +0 -0
  28. package/submodules/cppjieba/deps/limonp/CHANGELOG.md +160 -0
  29. package/submodules/cppjieba/deps/limonp/CMakeLists.txt +61 -0
  30. package/submodules/cppjieba/deps/limonp/LICENSE +20 -0
  31. package/submodules/cppjieba/deps/limonp/README.md +38 -0
  32. package/submodules/cppjieba/deps/limonp/include/limonp/ArgvContext.hpp +70 -0
  33. package/submodules/cppjieba/deps/limonp/include/limonp/Closure.hpp +206 -0
  34. package/submodules/cppjieba/deps/limonp/include/limonp/Colors.hpp +31 -0
  35. package/submodules/cppjieba/deps/limonp/include/limonp/Condition.hpp +38 -0
  36. package/submodules/cppjieba/deps/limonp/include/limonp/Config.hpp +103 -0
  37. package/submodules/cppjieba/deps/limonp/include/limonp/ForcePublic.hpp +7 -0
  38. package/submodules/cppjieba/deps/limonp/include/limonp/LocalVector.hpp +139 -0
  39. package/submodules/cppjieba/deps/limonp/include/limonp/Logging.hpp +90 -0
  40. package/submodules/cppjieba/deps/limonp/include/limonp/NonCopyable.hpp +21 -0
  41. package/submodules/cppjieba/deps/limonp/include/limonp/StdExtension.hpp +157 -0
  42. package/submodules/cppjieba/deps/limonp/include/limonp/StringUtil.hpp +386 -0
  43. package/submodules/cppjieba/deps/limonp/test/CMakeLists.txt +8 -0
  44. package/submodules/cppjieba/deps/limonp/test/demo.cpp +40 -0
  45. package/submodules/cppjieba/deps/limonp/test/testdata/1.conf +5 -0
  46. package/submodules/cppjieba/deps/limonp/test/testdata/StdExtension.data +3 -0
  47. package/submodules/cppjieba/deps/limonp/test/testdata/dict.gbk +50 -0
  48. package/submodules/cppjieba/deps/limonp/test/testdata/dict.utf8 +50 -0
  49. package/submodules/cppjieba/deps/limonp/test/testdata/io_testfile +2 -0
  50. package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.0.1.utf8 +93 -0
  51. package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.0.utf8 +93 -0
  52. package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.1.utf8 +67 -0
  53. package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.2.utf8 +64 -0
  54. package/submodules/cppjieba/deps/limonp/test/unittest/CMakeLists.txt +30 -0
  55. package/submodules/cppjieba/deps/limonp/test/unittest/TArgvContext.cpp +16 -0
  56. package/submodules/cppjieba/deps/limonp/test/unittest/TCastFloat.cpp +19 -0
  57. package/submodules/cppjieba/deps/limonp/test/unittest/TClosure.cpp +85 -0
  58. package/submodules/cppjieba/deps/limonp/test/unittest/TColorPrint.cpp +20 -0
  59. package/submodules/cppjieba/deps/limonp/test/unittest/TConfig.cpp +17 -0
  60. package/submodules/cppjieba/deps/limonp/test/unittest/TLocalVector.cpp +41 -0
  61. package/submodules/cppjieba/deps/limonp/test/unittest/TLogging.cpp +12 -0
  62. package/submodules/cppjieba/deps/limonp/test/unittest/TStdExtension.cpp +95 -0
  63. package/submodules/cppjieba/deps/limonp/test/unittest/TStringUtil.cpp +183 -0
  64. package/submodules/cppjieba/deps/limonp/test/unittest/gtest_main.cpp +39 -0
  65. package/submodules/cppjieba/dict/README.md +31 -0
  66. package/submodules/cppjieba/dict/hmm_model.utf8 +34 -0
  67. package/submodules/cppjieba/dict/idf.utf8 +258826 -0
  68. package/submodules/cppjieba/dict/jieba.dict.utf8 +348982 -0
  69. package/submodules/cppjieba/dict/pos_dict/char_state_tab.utf8 +6653 -0
  70. package/submodules/cppjieba/dict/pos_dict/prob_emit.utf8 +166 -0
  71. package/submodules/cppjieba/dict/pos_dict/prob_start.utf8 +259 -0
  72. package/submodules/cppjieba/dict/pos_dict/prob_trans.utf8 +5222 -0
  73. package/submodules/cppjieba/dict/stop_words.utf8 +1534 -0
  74. package/submodules/cppjieba/dict/user.dict.utf8 +4 -0
  75. package/submodules/cppjieba/include/cppjieba/DictTrie.hpp +381 -0
  76. package/submodules/cppjieba/include/cppjieba/FullSegment.hpp +93 -0
  77. package/submodules/cppjieba/include/cppjieba/HMMModel.hpp +129 -0
  78. package/submodules/cppjieba/include/cppjieba/HMMSegment.hpp +190 -0
  79. package/submodules/cppjieba/include/cppjieba/Jieba.hpp +169 -0
  80. package/submodules/cppjieba/include/cppjieba/KeywordExtractor.hpp +153 -0
  81. package/submodules/cppjieba/include/cppjieba/MPSegment.hpp +137 -0
  82. package/submodules/cppjieba/include/cppjieba/MixSegment.hpp +109 -0
  83. package/submodules/cppjieba/include/cppjieba/PosTagger.hpp +77 -0
  84. package/submodules/cppjieba/include/cppjieba/PreFilter.hpp +54 -0
  85. package/submodules/cppjieba/include/cppjieba/QuerySegment.hpp +89 -0
  86. package/submodules/cppjieba/include/cppjieba/SegmentBase.hpp +48 -0
  87. package/submodules/cppjieba/include/cppjieba/SegmentTagged.hpp +23 -0
  88. package/submodules/cppjieba/include/cppjieba/TextRankExtractor.hpp +190 -0
  89. package/submodules/cppjieba/include/cppjieba/Trie.hpp +200 -0
  90. package/submodules/cppjieba/include/cppjieba/Unicode.hpp +231 -0
  91. package/submodules/cppjieba/test/CMakeLists.txt +4 -0
  92. package/submodules/cppjieba/test/load_test.cpp +54 -0
  93. package/submodules/cppjieba/test/testdata/curl.res +1 -0
  94. package/submodules/cppjieba/test/testdata/extra_dict/jieba.dict.small.utf8 +109750 -0
  95. package/submodules/cppjieba/test/testdata/gbk_dict/hmm_model.gbk +34 -0
  96. package/submodules/cppjieba/test/testdata/gbk_dict/jieba.dict.gbk +348982 -0
  97. package/submodules/cppjieba/test/testdata/jieba.dict.0.1.utf8 +93 -0
  98. package/submodules/cppjieba/test/testdata/jieba.dict.0.utf8 +93 -0
  99. package/submodules/cppjieba/test/testdata/jieba.dict.1.utf8 +67 -0
  100. package/submodules/cppjieba/test/testdata/jieba.dict.2.utf8 +64 -0
  101. package/submodules/cppjieba/test/testdata/load_test.urls +2 -0
  102. package/submodules/cppjieba/test/testdata/review.100 +100 -0
  103. package/submodules/cppjieba/test/testdata/review.100.res +200 -0
  104. package/submodules/cppjieba/test/testdata/server.conf +19 -0
  105. package/submodules/cppjieba/test/testdata/testlines.gbk +9 -0
  106. package/submodules/cppjieba/test/testdata/testlines.utf8 +8 -0
  107. package/submodules/cppjieba/test/testdata/userdict.2.utf8 +1 -0
  108. package/submodules/cppjieba/test/testdata/userdict.english +2 -0
  109. package/submodules/cppjieba/test/testdata/userdict.utf8 +8 -0
  110. package/submodules/cppjieba/test/testdata/weicheng.utf8 +247 -0
  111. package/submodules/cppjieba/test/unittest/CMakeLists.txt +33 -0
  112. package/submodules/cppjieba/test/unittest/gtest_main.cpp +39 -0
  113. package/submodules/cppjieba/test/unittest/jieba_test.cpp +166 -0
  114. package/submodules/cppjieba/test/unittest/keyword_extractor_test.cpp +79 -0
  115. package/submodules/cppjieba/test/unittest/pos_tagger_test.cpp +41 -0
  116. package/submodules/cppjieba/test/unittest/pre_filter_test.cpp +43 -0
  117. package/submodules/cppjieba/test/unittest/segments_test.cpp +256 -0
  118. package/submodules/cppjieba/test/unittest/textrank_test.cpp +86 -0
  119. package/submodules/cppjieba/test/unittest/trie_test.cpp +177 -0
  120. package/submodules/cppjieba/test/unittest/unicode_test.cpp +43 -0
  121. package/test/debug_split +0 -0
  122. package/test/debug_split2 +0 -0
  123. package/test/debug_split3 +0 -0
  124. package/test/load_dict_test.js +14 -0
  125. package/test/missing_binding_test.js +42 -0
  126. package/test/test.js +366 -0
  127. package/test/testdata/userdict.utf8 +1 -0
  128. package/tsconfig.json +59 -0
  129. package/types/index.d.ts +30 -0
  130. package/typescript_demo.ts +38 -0
package/test/test.js ADDED
@@ -0,0 +1,366 @@
1
+ var should = require("should");
2
+ var nodejieba = require("../index.js");
3
+
4
+ describe("nodejieba", function() {
5
+
6
+ var sentence = "我是拖拉机学院手扶拖拉机专业的。不用多久,我就会升职加薪,当上CEO,走上人生巅峰。";
7
+
8
+ it("nodejieba.cut(sentence, true)", function() {
9
+ nodejieba.cut(sentence, true).should.eql([ '我',
10
+ '是',
11
+ '拖拉机',
12
+ '学院',
13
+ '手扶拖拉机',
14
+ '专业',
15
+ '的',
16
+ '。',
17
+ '不用',
18
+ '多久',
19
+ ',',
20
+ '我',
21
+ '就',
22
+ '会',
23
+ '升职',
24
+ '加薪',
25
+ ',',
26
+ '当上',
27
+ 'CEO',
28
+ ',',
29
+ '走上',
30
+ '人生',
31
+ '巅峰',
32
+ '。' ]);
33
+ });
34
+
35
+ it("nodejieba.cut('南京市长江大桥')", function() {
36
+ nodejieba.cut('南京市长江大桥').should.eql([ '南京市', '长江大桥' ]);
37
+ });
38
+
39
+ it("nodejieba.cut('南京市长江大桥')", function() {
40
+ nodejieba.cut('南京市长江大桥').should.eql([ '南京市', '长江大桥' ]);
41
+ });
42
+
43
+ it("nodejieba.cutHMM('南京市长江大桥')", function() {
44
+ nodejieba.cutHMM('南京市长江大桥').should.eql([ '南京市', '长江大桥' ]);
45
+ });
46
+
47
+ it("nodejieba.cut('南京市长江大桥', true)", function() {
48
+ nodejieba.cut('南京市长江大桥', true).should.eql([ '南京市', '长江大桥' ]);
49
+ });
50
+
51
+ it("nodejieba.cut('南京长江大桥')", function() {
52
+ nodejieba.cut('南京长江大桥').should.eql([ '南京长江大桥' ]);
53
+ });
54
+
55
+ it("nodejieba.cut('南京长江大桥')", function() {
56
+ nodejieba.cut('南京长江大桥').should.eql([ '南京长江大桥' ]);
57
+ });
58
+
59
+ it("nodejieba.cutHMM('南京长江大桥')", function() {
60
+ nodejieba.cutHMM('南京长江大桥').should.eql([ '南京长', '江大桥' ]);
61
+ });
62
+
63
+ it("nodejieba.cut('南京长江大桥', true)", function() {
64
+ nodejieba.cut('南京长江大桥', true).should.eql([ '南京长江大桥' ]);
65
+ });
66
+
67
+ it('nodejieba.cut(sentence)', function() {
68
+ nodejieba.cut(sentence).should.eql([ '我',
69
+ '是',
70
+ '拖拉机',
71
+ '学院',
72
+ '手扶拖拉机',
73
+ '专业',
74
+ '的',
75
+ '。',
76
+ '不用',
77
+ '多久',
78
+ ',',
79
+ '我',
80
+ '就',
81
+ '会',
82
+ '升职',
83
+ '加薪',
84
+ ',',
85
+ '当',
86
+ '上',
87
+ 'C',
88
+ 'E',
89
+ 'O',
90
+ ',',
91
+ '走上',
92
+ '人生',
93
+ '巅峰',
94
+ '。' ]);
95
+ })
96
+
97
+ it('nodejieba.cutHMM(sentence)', function() {
98
+ nodejieba.cutHMM(sentence).should.eql([ '我',
99
+ '是',
100
+ '拖拉机',
101
+ '学院',
102
+ '手',
103
+ '扶',
104
+ '拖拉机',
105
+ '专业',
106
+ '的',
107
+ '。',
108
+ '不用',
109
+ '多久',
110
+ ',',
111
+ '我',
112
+ '就',
113
+ '会升',
114
+ '职加薪',
115
+ ',',
116
+ '当上',
117
+ 'CEO',
118
+ ',',
119
+ '走上',
120
+ '人生',
121
+ '巅峰',
122
+ '。' ]);
123
+ });
124
+
125
+ it('nodejieba.cut(sentence, true)', function() {
126
+ nodejieba.cut(sentence, true).should.eql([ '我',
127
+ '是',
128
+ '拖拉机',
129
+ '学院',
130
+ '手扶拖拉机',
131
+ '专业',
132
+ '的',
133
+ '。',
134
+ '不用',
135
+ '多久',
136
+ ',',
137
+ '我',
138
+ '就',
139
+ '会',
140
+ '升职',
141
+ '加薪',
142
+ ',',
143
+ '当上',
144
+ 'CEO',
145
+ ',',
146
+ '走上',
147
+ '人生',
148
+ '巅峰',
149
+ '。' ]);
150
+ });
151
+
152
+ it('nodejieba.cutAll(sentence)', function() {
153
+ nodejieba.cutAll(sentence).should.eql([ '我',
154
+ '是',
155
+ '拖拉',
156
+ '拖拉机',
157
+ '学院',
158
+ '手扶',
159
+ '手扶拖拉机',
160
+ '拖拉',
161
+ '拖拉机',
162
+ '专业',
163
+ '的',
164
+ '。',
165
+ '不用',
166
+ '多久',
167
+ ',',
168
+ '我',
169
+ '就',
170
+ '会升',
171
+ '升职',
172
+ '加薪',
173
+ ',',
174
+ '当上',
175
+ 'C',
176
+ 'E',
177
+ 'O',
178
+ ',',
179
+ '走上',
180
+ '人生',
181
+ '巅峰',
182
+ '。' ]);
183
+ });
184
+
185
+ it('nodejieba.cutForSearch(sentence)', function() {
186
+ nodejieba.cutForSearch(sentence).should.eql([ '我',
187
+ '是',
188
+ '拖拉',
189
+ '拖拉机',
190
+ '学院',
191
+ '手扶',
192
+ '拖拉',
193
+ '拖拉机',
194
+ '手扶拖拉机',
195
+ '专业',
196
+ '的',
197
+ '。',
198
+ '不用',
199
+ '多久',
200
+ ',',
201
+ '我',
202
+ '就',
203
+ '会',
204
+ '升职',
205
+ '加薪',
206
+ ',',
207
+ '当',
208
+ '上',
209
+ 'C',
210
+ 'E',
211
+ 'O',
212
+ ',',
213
+ '走上',
214
+ '人生',
215
+ '巅峰',
216
+ '。' ]);
217
+ });
218
+
219
+ it('nodejieba.cutForSearch(sentence, true)', function() {
220
+ nodejieba.cutForSearch(sentence, true).should.eql([ '我',
221
+ '是',
222
+ '拖拉',
223
+ '拖拉机',
224
+ '学院',
225
+ '手扶',
226
+ '拖拉',
227
+ '拖拉机',
228
+ '手扶拖拉机',
229
+ '专业',
230
+ '的',
231
+ '。',
232
+ '不用',
233
+ '多久',
234
+ ',',
235
+ '我',
236
+ '就',
237
+ '会',
238
+ '升职',
239
+ '加薪',
240
+ ',',
241
+ '当上',
242
+ 'CEO',
243
+ ',',
244
+ '走上',
245
+ '人生',
246
+ '巅峰',
247
+ '。' ]);
248
+ });
249
+
250
+ it('nodejieba.tag(sentence)', function() {
251
+ nodejieba.tag(sentence).should.eql([ { word: '我', tag: 'r' },
252
+ { word: '是', tag: 'v' },
253
+ { word: '拖拉机', tag: 'n' },
254
+ { word: '学院', tag: 'n' },
255
+ { word: '手扶拖拉机', tag: 'n' },
256
+ { word: '专业', tag: 'n' },
257
+ { word: '的', tag: 'uj' },
258
+ { word: '。', tag: 'x' },
259
+ { word: '不用', tag: 'v' },
260
+ { word: '多久', tag: 'm' },
261
+ { word: ',', tag: 'x' },
262
+ { word: '我', tag: 'r' },
263
+ { word: '就', tag: 'd' },
264
+ { word: '会', tag: 'v' },
265
+ { word: '升职', tag: 'v' },
266
+ { word: '加薪', tag: 'nr' },
267
+ { word: ',', tag: 'x' },
268
+ { word: '当上', tag: 't' },
269
+ { word: 'CEO', tag: 'eng' },
270
+ { word: ',', tag: 'x' },
271
+ { word: '走上', tag: 'v' },
272
+ { word: '人生', tag: 'n' },
273
+ { word: '巅峰', tag: 'n' },
274
+ { word: '。', tag: 'x' } ]);
275
+ });
276
+
277
+ // float compare error in multi platform (macos, windows)
278
+ //it('nodejieba.extract(sentence, 5)', function() {
279
+ // nodejieba.extract(sentence, 5).should.eql([
280
+ // {
281
+ // "weight": 11.739204307083542,
282
+ // "word": "CEO"
283
+ // },
284
+ // {
285
+ // "weight": 10.8561552143,
286
+ // "word": "升职"
287
+ // },
288
+ // {
289
+ // "weight": 10.642581114,
290
+ // "word": "加薪"
291
+ // },
292
+ // {
293
+ // "weight": 10.0088573539,
294
+ // "word": "手扶拖拉机"
295
+ // },
296
+ // {
297
+ // "weight": 9.49395840471,
298
+ // "word": "巅峰"
299
+ // }]);
300
+ //});
301
+
302
+ //it('nodejieba.textRankExtract(sentence, 5)', function() {
303
+ // nodejieba.textRankExtract(sentence, 5).should.eql([
304
+ // {
305
+ // "weight": 1,
306
+ // "word": "当上"
307
+ // },
308
+ // {
309
+ // "weight": 0.9898479330698993,
310
+ // "word": "不用"
311
+ // },
312
+ // {
313
+ // "weight": 0.9851260595435759,
314
+ // "word": "多久"
315
+ // },
316
+ // {
317
+ // "weight": 0.9830464899847804,
318
+ // "word": "加薪"
319
+ // },
320
+ // {
321
+ // "weight": 0.9802777682279076,
322
+ // "word": "升职"
323
+ // }]);
324
+ //});
325
+
326
+ it('nodejieba.cut("红掌拨清波")', function() {
327
+ nodejieba.cut("红掌拨清波").should.eql([
328
+ '红掌',
329
+ '拨',
330
+ '清波',
331
+ ]);
332
+ });
333
+
334
+ it('nodejieba.cut("男默女泪")', function() {
335
+ nodejieba.cut("男默女泪").should.eql([ '男', '默',
336
+ '女', '泪' ]);
337
+ });
338
+ it('nodejieba.insertWord("男默女泪")', function() {
339
+ nodejieba.insertWord("男默女泪").should.eql(true);
340
+ });
341
+ it('nodejieba.cut("男默女泪")', function() {
342
+ nodejieba.cut("男默女泪").should.eql([ '男默女泪' ]);
343
+ });
344
+
345
+ it('nodejieba.cut("今天天气很好,🙋 我们去郊游。")', function() {
346
+ nodejieba.cut("今天天气很好,🙋 我们去郊游。").should.eql([ '今天天气', '很', '好', ',', '🙋', ' ', '我们', '去', '郊游', '。' ]);
347
+ });
348
+
349
+ it('nodejieba.cutSmall("南京市长江大桥", 3)', function() {
350
+ nodejieba.cutSmall("南京市长江大桥", 3).should.eql([ '南京市',
351
+ '长江',
352
+ '大桥']);
353
+ });
354
+
355
+ it('nodejieba.cut("区块链")', function() {
356
+ nodejieba.cut("区块链").should.eql(['区块链']);
357
+ });
358
+ it('nodejieba.tag("区块链")', function() {
359
+ nodejieba.tag("区块链").should.eql([ { word: '区块链', tag: 'nz' }]);
360
+ });
361
+ it('nodejieba.cut("访问www.baidu.com进行搜索")',function(){
362
+ nodejieba.cut("访问www.baidu.com进行搜索", true).should.eql([
363
+ '访问', 'www', '.', 'baidu', '.', 'com', '进行', '搜索',
364
+ ]);
365
+ });
366
+ });
@@ -0,0 +1 @@
1
+ 红掌拨清波
package/tsconfig.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Basic Options */
4
+ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
5
+ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6
+ // "lib": [], /* Specify library files to be included in the compilation. */
7
+ // "allowJs": true, /* Allow javascript files to be compiled. */
8
+ // "checkJs": true, /* Report errors in .js files. */
9
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
10
+ // "declaration": true, /* Generates corresponding '.d.ts' file. */
11
+ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
12
+ // "sourceMap": true, /* Generates corresponding '.map' file. */
13
+ // "outFile": "./", /* Concatenate and emit output to single file. */
14
+ // "outDir": "./", /* Redirect output structure to the directory. */
15
+ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16
+ // "composite": true, /* Enable project compilation */
17
+ // "removeComments": true, /* Do not emit comments to output. */
18
+ // "noEmit": true, /* Do not emit outputs. */
19
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
20
+ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
21
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
22
+
23
+ /* Strict Type-Checking Options */
24
+ "strict": true, /* Enable all strict type-checking options. */
25
+ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
26
+ // "strictNullChecks": true, /* Enable strict null checks. */
27
+ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
28
+ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
29
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
30
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
31
+
32
+ /* Additional Checks */
33
+ // "noUnusedLocals": true, /* Report errors on unused locals. */
34
+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
35
+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
36
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
37
+
38
+ /* Module Resolution Options */
39
+ // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
40
+ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
41
+ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
42
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
43
+ // "typeRoots": [], /* List of folders to include type definitions from. */
44
+ // "types": [], /* Type declaration files to be included in compilation. */
45
+ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
46
+ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
47
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
48
+
49
+ /* Source Map Options */
50
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
51
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
52
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
53
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
54
+
55
+ /* Experimental Options */
56
+ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
57
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
58
+ }
59
+ }
@@ -0,0 +1,30 @@
1
+ declare module "nodejieba" {
2
+ export interface LoadOptions {
3
+ dict?: string;
4
+ hmmDict?: string;
5
+ userDict?: string;
6
+ idfDict?: string;
7
+ stopWordDict?: string;
8
+ }
9
+
10
+ export interface TagResult {
11
+ word: string;
12
+ tag: string;
13
+ }
14
+
15
+ export interface ExtractResult {
16
+ word: string;
17
+ weight: number;
18
+ }
19
+
20
+ export function load(dict?: LoadOptions): void;
21
+ export function cut(sentence: string, strict?: boolean): string[];
22
+ export function cutHMM(sentence: string): string[];
23
+ export function cutAll(sentence: string): string[];
24
+ export function cutForSearch(sentence: string, strict?: boolean): string[];
25
+ export function tag(sentence: string): TagResult[];
26
+ export function extract(sentence: string, threshold: number): ExtractResult[];
27
+ export function textRankExtract(sentence: string, threshold: number): ExtractResult[];
28
+ export function insertWord(word: string, tag?: string): boolean;
29
+ export function cutSmall(sentence: string, small: number): string[];
30
+ }
@@ -0,0 +1,38 @@
1
+ import nodejieba from "nodejieba";
2
+
3
+ const sentence = "我是拖拉机学院手扶拖拉机专业的。不用多久,我就会升职加薪,当上CEO,走上人生巅峰。";
4
+ let result: any;
5
+
6
+ result = nodejieba.cut(sentence);
7
+ console.log(result);
8
+
9
+ result = nodejieba.cut(sentence, true);
10
+ console.log(result);
11
+
12
+ result = nodejieba.cutHMM(sentence);
13
+ console.log(result);
14
+
15
+ result = nodejieba.cutAll(sentence);
16
+ console.log(result);
17
+
18
+ result = nodejieba.cutForSearch(sentence);
19
+ console.log(result);
20
+
21
+ result = nodejieba.tag(sentence);
22
+ console.log(result);
23
+
24
+ const topN = 5;
25
+ result = nodejieba.extract(sentence, topN);
26
+ console.log(result);
27
+
28
+ result = nodejieba.textRankExtract(sentence, topN);
29
+ console.log(result);
30
+
31
+ result = nodejieba.cut("男默女泪");
32
+ console.log(result);
33
+ nodejieba.insertWord("男默女泪");
34
+ result = nodejieba.cut("男默女泪");
35
+ console.log(result);
36
+
37
+ result = nodejieba.cutSmall("南京市长江大桥", 3);
38
+ console.log(result);