forked from yanyiwu/nodejieba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
48 lines (34 loc) · 1.34 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var nodejieba = require("../index.js");
var sentence = "我是拖拉机学院手扶拖拉机专业的。不用多久,我就会升职加薪,当上CEO,走上人生巅峰。";
var result;
// 没有主动调用nodejieba.load载入词典的时候,
// 会在第一次调用cut或者其他需要词典的函数时,自动载入默认词典。
// 词典只会被加载一次。
result = nodejieba.cut(sentence);
console.log(result);
result = nodejieba.cut(sentence, true);
console.log(result);
result = nodejieba.cutHMM(sentence);
console.log(result);
result = nodejieba.cutAll(sentence);
console.log(result);
result = nodejieba.cutForSearch(sentence);
console.log(result);
result = nodejieba.tag(sentence);
console.log(result);
console.log('=======');
console.log(nodejieba.extractWithWords(nodejieba.tagWordsToStr(result), 5));
console.log(nodejieba.extract(sentence, 5));
console.log(nodejieba.textRankExtractWithWords(nodejieba.tagWordsToStr(result), 5));
console.log(nodejieba.textRankExtract(sentence, 5));
console.log('=======');
var topN = 5;
result = nodejieba.extract(sentence, topN);
console.log(result);
result = nodejieba.cut("男默女泪");
console.log(result);
nodejieba.insertWord("男默女泪");
result = nodejieba.cut("男默女泪");
console.log(result);
result = nodejieba.cutSmall("南京市长江大桥", 3);
console.log(result);