From 1babe57ebc7f80aa68f2dbe5599177dcb95d5e9d Mon Sep 17 00:00:00 2001 From: yanyiwu Date: Sun, 30 Aug 2015 16:35:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E7=B2=92=E5=BA=A6=E5=88=86=E8=AF=8D?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Application.hpp | 4 ++++ test/unittest/TApplication.cpp | 3 +++ test/unittest/TSegments.cpp | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/Application.hpp b/src/Application.hpp index 97001b1..e48e931 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -67,6 +67,10 @@ class Application { vector >& words) const { levelSeg_.cut(sentence, words); } + void cut(const string& sentence, + vector& words, size_t max_word_len) const { + mpSeg_.cut(sentence, words, max_word_len); + } bool insertUserWord(const string& word, const string& tag = UNKNOWN_TAG) { return dictTrie_.insertUserWord(word, tag); } diff --git a/test/unittest/TApplication.cpp b/test/unittest/TApplication.cpp index 4a66540..2f03449 100644 --- a/test/unittest/TApplication.cpp +++ b/test/unittest/TApplication.cpp @@ -20,6 +20,9 @@ TEST(ApplicationTest, Test1) { result << words; ASSERT_EQ("[\"我\", \"来自\", \"北京邮电大学\", \"。\"]", result); + app.cut("南京市长江大桥", words, 3); + ASSERT_EQ("[\"南京市\", \"长江\", \"大桥\"]", result << words); + app.cut("我来自北京邮电大学。。。学号123456", words, METHOD_HMM); result << words; ASSERT_EQ("[\"我来\", \"自北京\", \"邮电大学\", \"。\", \"。\", \"。\", \"学号\", \"123456\"]", result); diff --git a/test/unittest/TSegments.cpp b/test/unittest/TSegments.cpp index 8871dbb..1d4f6bd 100644 --- a/test/unittest/TSegments.cpp +++ b/test/unittest/TSegments.cpp @@ -101,6 +101,9 @@ TEST(MPSegmentTest, Test1) { // MaxWordLen ASSERT_TRUE(segment.cut("南京市长江大桥", words, 3)); ASSERT_EQ("[\"南京市\", \"长江\", \"大桥\"]", s << words); + + ASSERT_TRUE(segment.cut("南京市长江大桥", words, 0)); + ASSERT_EQ("[\"南\", \"京\", \"市\", \"长\", \"江\", \"大\", \"桥\"]", s << words); } //TEST(MPSegmentTest, Test2) {