2 Star 6 Fork 1

Yanyi Wu / nodejieba

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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

The MIT License (MIT) Copyright (c) 2013 Yanyi Wu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

"结巴"中文分词的Node.js版本 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/yanyiwu/nodejieba.git
git@gitee.com:yanyiwu/nodejieba.git
yanyiwu
nodejieba
nodejieba
master

搜索帮助