NodeJieba
只是CppJieba简单包装而成的node
扩展,用来进行中文分词。
对实现感兴趣的请看如下博文:
npm install nodejieba
因为npm
速度很慢而且经常因为墙的原因出现莫名其妙的问题,可以试试使用cnpm,命令如下:
npm --registry=http://r.cnpmjs.org install nodejieba
var nodejieba = require("nodejieba");
nodejieba.loadDict("./node_modules/nodejieba/dict/jieba.dict.utf8", "./node_modules/nodejieba/dict/hmm_model.utf8", "./node_modules/nodejieba/dict/user.dict.utf8");
var wordList = nodejieba.cutSync("阻塞模式分词");
if (wordList.constructor == Array) // just for tutorial, this is always be true
{
wordList.forEach(function(word) {
console.log(word);
});
}
nodejieba.cut("非阻塞模式分词", function(wordList) {
wordList.forEach(function(word) {
console.log(word);
});
});
var nodejieba = require("nodejieba");
nodejieba.queryLoadDict("./node_modules/nodejieba/dict/jieba.dict.utf8", "./node_modules/nodejieba/dict/hmm_model.utf8", "./node_modules/nodejieba/dict/user.dict.utf8");
var wordList = nodejieba.queryCutSync("阻塞模式分词");
if (wordList.constructor == Array) // just for tutorial, this is always be true
{
wordList.forEach(function(word) {
console.log(word);
});
}
nodejieba.queryCut("非阻塞模式分词", function(wordList) {
wordList.forEach(function(word) {
console.log(word);
});
});
具体用法可以参考 test/segment.js test/query_segment.js
具体用法可以参考 test/pos_tagger.js
具体用法可以参考 test/keyword.js
在node v0.10.2
, node v0.11.13
, node v0.12.1
, iojs v1.3.0
下测试通过。
http://cppjieba-webdemo.herokuapp.com/ (chrome is suggested)
- YanyiWu http://yanyiwu.com i@yanyiwu.com
- myl2821 https://github.com/myl2821 myl2821@gmail.com