NodeJieba"结巴"分词的Node.js版本ItroductioNodeJieba只是CppJieba简单包装而成的ode扩展,用来进行中文分词。
详见NodeJiebaBlogIstallpm istall odejieba因为pm速度很慢而且经常因为墙的原因出现莫名其妙的问题,在此强烈建议使用cpm,命令如下:pm --registry=https://r.cpmjs.org istall odejiebaUsage默认分词算法初始化var segmet = require("odejieba");segmet.loadDict("./ode_modules/odejieba/dict/jieba.dict.utf8", "./ode_modules/odejieba/dict/hmm_model.utf8");阻塞式调用var wordList = segmet.cutSyc("阻塞模式分词"); if (wordList.costructor == Array) // just for tutorial, this is always be true { wordList.forEach(fuctio(word) { cosole.log(word); });}非阻塞式调用segmet.cut("非阻塞模式分词", fuctio(wordList) { wordList.forEach(fuctio(word) { cosole.log(word); });});搜索引擎分词算法初始化var segmet = require("odejieba");segmet.queryLoadDict("./ode_modules/odejieba/dict/jieba.dict.utf8", "./ode_modules/odejieba/dict/hmm_model.utf8");阻塞式调用var wordList = segmet.queryCutSyc("阻塞模式分词"); if (wordList.costructor == Array) // just for tutorial, this is always be true { wordList.forEach(fuctio(word) { cosole.log(word); });}非阻塞式调用segmet.queryCut("非阻塞模式分词", fuctio(wordList) { wordList.forEach(fuctio(word) { cosole.log(word); });});具体用法可以参考 test/segmet.jstest/query_segmet.jsTestig在odev0.10.2下测试通过Demohttps://cppjieba-webdemo.herokuapp.com/ (chromeissuggested)ThaksJieba中文分词点击空白处退出提示
评论