Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nodejieba

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejieba

chinese segment for node

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
decreased by-16.4%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Dependency Status devDependency Status NpmDownload Status


NodeJieba "结巴"分词的Node.js版本

Introduction

NodeJieba只是CppJieba简单包装而成的node扩展,用来进行中文分词。

详见NodeJiebaBlog

Install

npm install nodejieba

因为npm速度很慢而且经常因为墙的原因出现莫名其妙的问题,在此强烈建议使用cnpm,命令如下:

npm --registry=http://r.cnpmjs.org install nodejieba

Usage

默认分词算法

初始化
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.js test/query_segment.js

Testing

node v0.10.2下测试通过

Demo

http://cppjieba-webdemo.herokuapp.com/ (chrome is suggested)

Thanks

Jieba中文分词

Author

Keywords

FAQs

Package last updated on 26 Jul 2014

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc