Skip to content

Commit

Permalink
对MP算法的分词方式新增一个粒度参数
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyiwu committed Aug 31, 2015
1 parent 837487b commit a454563
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/nodejieba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ NAN_METHOD(cut) {
vector<string> words;

assert(gNodeJieba);
if (info.Length() == 2) {
if (info.Length() >= 2) {
string method = *(String::Utf8Value(info[1]->ToString()));
if ("MP" == method) {
gNodeJieba->cut(sentence, words, CppJieba::METHOD_MP);
if (info.Length() == 3) {
gNodeJieba->cut(sentence, words, info[2]->Int32Value());
}
} else if ("HMM" == method) {
gNodeJieba->cut(sentence, words, CppJieba::METHOD_HMM);
} else if ("MIX" == method) {
Expand Down
3 changes: 3 additions & 0 deletions test/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ console.log(result);
nodejieba.insertWord("男默女泪");
result = nodejieba.cut("男默女泪");
console.log(result);

result = nodejieba.cut("南京市长江大桥", "MP", 3);
console.log(result);
3 changes: 3 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,7 @@ describe("nodejieba", function() {
nodejieba.cut("男默女泪").should.eql([ '男默女泪' ]);
});

it('nodejieba.cut("南京市长江大桥")', function() {
nodejieba.cut("南京市长江大桥", "MP", 3).should.eql([ '南京市', '长江', '大桥' ]);
});
});

0 comments on commit a454563

Please sign in to comment.