add user_dict_path for server

This commit is contained in:
wyy 2014-06-13 00:26:37 +08:00
parent c9c1ff5ac6
commit fc621ce856
5 changed files with 17 additions and 5 deletions

View File

@ -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`
没有使用自定义用户词典时的结果:

View File

@ -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

View File

@ -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)

2
dict/user.dict.utf8 Normal file
View File

@ -0,0 +1,2 @@
云计算
韩玉鉴赏

View File

@ -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();
}