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(',');
},

 

posted @ 2018-02-02 10:56  yudis  阅读(1180)  评论(0编辑  收藏  举报