Node.js模块——nodejieba
一、环境配置(centOS)
$ yum install gcc gcc-c++ -y $ yum install wget -y $ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash $ source ./root/.bashrc $ nvm install v8.9.4 $ nvm alias default 8.9.4 $ npm install -g cnpm --registry=https://registry.npm.taobao.org
二、安装
$ cnpm i nodejieba --save
三、使用
const jieba = require('nodejieba');
/**
* 中文分词
* @param {String} str
*/
jiebaCut(str) {
return jieba.cut(str).join(',');
},
/**
* 关键词抽取
* @param {String} str
* @param {Number} topN
*/
jiebaExtract(str, topN) {
return jieba.extract(str, topN).map((v) => v.word).join(',');
},

浙公网安备 33010602011771号