NodeJieba"结巴"分词的Node.js版本IntroductionNodeJieba只是CppJieba简单包装而成的node扩展,用来进行中文分词。详见NodeJiebaBlogInstallnpm install nodejieba因为npm速度很慢而且经常因为墙的原因出现莫名其妙的问题,在此强烈建议使用cnpm,命令如下:npm --registry=https://r.cnpmjs.org install nodejiebaUsage默认分词算法初始化var segment = require("nodejieba");segment.loadDict("./node_modules/nodejieba/dict/jieba.dict.utf8", "./node_modules/nodejieba/dict/hmm_model.utf8");阻塞式调用var wordList = segment.cutSync("阻塞模式分词"); if (wordList.constructor == Array) // just for tutorial, this is always be true { wordList.forEach(function(word) { console.log(word); });}非阻塞式调用segment.cut("非阻塞模式分词", function(wordList) { wordList.forEach(function(word) { console.log(word); });});搜索引擎分词算法初始化var segment = require("nodejieba");segment.queryLoadDict("./node_modules/nodejieba/dict/jieba.dict.utf8", "./node_modules/nodejieba/dict/hmm_model.utf8");阻塞式调用var wordList = segment.queryCutSync("阻塞模式分词"); if (wordList.constructor == Array) // just for tutorial, this is always be true { wordList.forEach(function(word) { console.log(word); });}非阻塞式调用segment.queryCut("非阻塞模式分词", function(wordList) { wordList.forEach(function(word) { console.log(word); });});具体用法可以参考 test/segment.jstest/query_segment.jsTesting在nodev0.10.2下测试通过Demohttps://cppjieba-webdemo.herokuapp.com/ (chromeissuggested)ThanksJieba中文分词声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态
评论