diff --git a/README.md b/README.md index 3401963..d6b879f 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ cmake .. # cmake .. -DENC=GBK # 需要注意的是,单元测试都是针对utf8的测试,如果是使用gbk选项的话,此测试不通过。 make +# 如果你需要服务支持用户自定义词典的话, +# 可以在 ./conf/server.conf 里面的这行 "#user_dict_path=/usr/share/CppJieba/dict/user.dict.utf8" 前面的#号去掉。 sudo make install ``` @@ -48,7 +50,6 @@ make test ### server start & stop ``` -#Usage: /etc/init.d/cjserver {start|stop|restart|force-reload} /etc/init.d/cjserver.start >> /dev/null 2>&1 /etc/init.d/cjserver.stop ``` @@ -203,7 +204,7 @@ Query方法先使用Mix方法切词,对于切出来的较长的词再使用Ful 自定义词典示例请看`test/testdata/userdict.utf8`。 -载入自定义词典示例请看`test/segment.cpp`。 +载入自定义词典示例请看`test/segment.cpp`,产生的可执行文件示例请见 `build/segment.demo` 没有使用自定义用户词典时的结果: diff --git a/conf/server.conf b/conf/server.conf index c47e80e..28ded12 100644 --- a/conf/server.conf +++ b/conf/server.conf @@ -9,3 +9,6 @@ dict_path=/usr/share/CppJieba/dict/jieba.dict.utf8 #model path model_path=/usr/share/CppJieba/dict/hmm_model.utf8 + +#user_dict_path +#user_dict_path=/usr/share/CppJieba/dict/user.dict.utf8 diff --git a/dict/CMakeLists.txt b/dict/CMakeLists.txt index 9076eb8..88eb2fb 100644 --- a/dict/CMakeLists.txt +++ b/dict/CMakeLists.txt @@ -1 +1 @@ -INSTALL(FILES hmm_model.utf8 jieba.dict.utf8 DESTINATION share/CppJieba/dict) +INSTALL(FILES hmm_model.utf8 jieba.dict.utf8 user.dict.utf8 DESTINATION share/CppJieba/dict) diff --git a/dict/user.dict.utf8 b/dict/user.dict.utf8 new file mode 100644 index 0000000..0e77ef4 --- /dev/null +++ b/dict/user.dict.utf8 @@ -0,0 +1,2 @@ +云计算 +韩玉鉴赏 diff --git a/server/server.cpp b/server/server.cpp index 70a0941..92945f6 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -15,7 +15,7 @@ using namespace CppJieba; class ReqHandler: public IRequestHandler { public: - ReqHandler(const string& dictPath, const string& modelPath): _segment(dictPath, modelPath){}; + ReqHandler(const string& dictPath, const string& modelPath, const string& userDictPath): _segment(dictPath, modelPath, userDictPath){}; virtual ~ReqHandler(){}; public: virtual bool do_GET(const HttpReqInfo& httpReq, string& strSnd) const @@ -58,6 +58,7 @@ bool run(int argc, char** argv) size_t port = 0; string dictPath; string modelPath; + string userDictPath; string val; if(!conf.get("port", val)) { @@ -77,7 +78,12 @@ bool run(int argc, char** argv) return false; } - ReqHandler reqHandler(dictPath, modelPath); + if(!conf.get("user_dict_path", userDictPath)) //optional + { + userDictPath = ""; + } + + ReqHandler reqHandler(dictPath, modelPath, userDictPath); EpollServer sf(port, reqHandler); return sf.start(); }