Security News
Python Overtakes JavaScript as Top Programming Language on GitHub
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
NodeJieba
是"结巴"中文分词的 Node.js 版本实现,
由CppJieba提供底层分词算法实现,
是兼具高性能和易用性两者的 Node.js 中文分词组件。
对实现细节感兴趣的请看如下博文:
npm install nodejieba
因为npm
速度很慢而且经常因为墙的原因出现莫名其妙的问题,可以试试使用cnpm,命令如下:
npm --registry=http://r.cnpmjs.org install nodejieba
var nodejieba = require("nodejieba");
var result = nodejieba.cut("南京市长江大桥");
console.log(result);
//["南京市","长江大桥"]
更详细的其他用法请看 test/demo.js
如果没有主动调用词典函数时, 则会在第一次调用cut等功能函数时,自动载入默认词典。
如果要主动触发词典载入,则使用以下函数主动触发。
nodejieba.load();
以上用法会自动载入所有默认词典, 如果需要载入自己的词典,而不是默认词典。 比如想要载入自己的用户词典,则使用以下函数:
nodejieba.load({
userDict: './test/testdata/userdict.utf8',
});
字典载入函数load的参数项都是可选的, 如果没有对应的项则自动填充默认参数。 所以上面这段代码和下面这代代码是等价的。
nodejieba.load({
dict: nodejieba.DEFAULT_DICT,
hmmDict: nodejieba.DEFAULT_HMM_DICT,
userDict: './test/testdata/userdict.utf8',
idfDict: nodejieba.DEFAULT_IDF_DICT,
stopWordDict: nodejieba.DEFAULT_STOP_WORD_DICT,
});
【词典说明】
var nodejieba = require("nodejieba");
console.log(nodejieba.tag("红掌拨清波"));
//[ { word: '红掌', tag: 'n' },
// { word: '拨', tag: 'v' },
// { word: '清波', tag: 'n' } ]
更详细的其他用法请看 test/demo.js
var nodejieba = require("nodejieba");
var topN = 4;
console.log(nodejieba.extract("升职加薪,当上CEO,走上人生巅峰。", topN));
//[ { word: 'CEO', weight: 11.739204307083542 },
// { word: '升职', weight: 10.8561552143 },
// { word: '加薪', weight: 10.642581114 },
// { word: '巅峰', weight: 9.49395840471 } ]
更详细的其他用法请看 test/demo.js
以下版本中测试通过:
node v0.10.2
node v0.12.1
iojs v1.3.0
iojs v2.2.1
node v4.0.0
node v5.7.0
性能杠杠的,应该是目前性能最好的 Node.js 中文分词库,没有之一。 详见: Jieba中文分词系列性能评测
http://cppjieba-webdemo.herokuapp.com/ (chrome is suggested)
Email: i@yanyiwu.com
This project exists thanks to all the people who contribute. [Contribute].
Become a financial contributor and help us sustain our community. [Contribute]
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]
FAQs
chinese word segmentation for node
The npm package nodejieba receives a total of 9,818 weekly downloads. As such, nodejieba popularity was classified as popular.
We found that nodejieba demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
Security News
Dutch National Police and FBI dismantle Redline and Meta infostealer malware-as-a-service operations in Operation Magnus, seizing servers and source code.
Research
Security News
Socket is tracking a new trend where malicious actors are now exploiting the popularity of LLM research to spread malware through seemingly useful open source packages.