mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
add init dipose into ISegment.hpp
This commit is contained in:
parent
2728d8311e
commit
b1a71f0495
@ -31,9 +31,11 @@ namespace CppJieba
|
||||
EmitProbMap _emitProbM;
|
||||
EmitProbMap _emitProbS;
|
||||
vector<EmitProbMap* > _emitProbVec;
|
||||
private:
|
||||
const string _hmmModelPath;
|
||||
|
||||
public:
|
||||
HMMSegment()
|
||||
HMMSegment(const char * const filePath): _hmmModelPath(filePath)
|
||||
{
|
||||
memset(_startProb, 0, sizeof(_startProb));
|
||||
memset(_transProb, 0, sizeof(_transProb));
|
||||
@ -51,11 +53,11 @@ namespace CppJieba
|
||||
dispose();
|
||||
}
|
||||
public:
|
||||
bool init(const char* const modelPath)
|
||||
virtual bool init()
|
||||
{
|
||||
return _setInitFlag(_loadModel(modelPath));
|
||||
return _setInitFlag(_loadModel(_hmmModelPath.c_str()));
|
||||
}
|
||||
bool dispose()
|
||||
virtual bool dispose()
|
||||
{
|
||||
_setInitFlag(false);
|
||||
return true;
|
||||
@ -88,11 +90,8 @@ namespace CppJieba
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//bool cut(const string& str, vector<string>& res)const
|
||||
//{
|
||||
// return SegmentBase::cut(str, res);
|
||||
//}
|
||||
bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const
|
||||
public:
|
||||
virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const
|
||||
{
|
||||
if(!_getInitFlag())
|
||||
{
|
||||
|
@ -8,6 +8,9 @@ namespace CppJieba
|
||||
{
|
||||
public:
|
||||
virtual ~ISegment(){};
|
||||
public:
|
||||
virtual bool init() = 0;
|
||||
virtual bool dispose() = 0;
|
||||
public:
|
||||
virtual bool cut(Unicode::const_iterator begin , Unicode::const_iterator end, vector<string>& res) const = 0;
|
||||
virtual bool cut(const string& str, vector<string>& res) const = 0;
|
||||
|
@ -32,12 +32,14 @@ namespace CppJieba
|
||||
{
|
||||
private:
|
||||
Trie _trie;
|
||||
private:
|
||||
const string _dictPath;
|
||||
|
||||
public:
|
||||
MPSegment(){};
|
||||
MPSegment(const char * const dictPath): _dictPath(dictPath){};
|
||||
virtual ~MPSegment(){dispose();};
|
||||
public:
|
||||
bool init(const char* const filePath)
|
||||
virtual bool init()
|
||||
{
|
||||
if(_getInitFlag())
|
||||
{
|
||||
@ -49,8 +51,8 @@ namespace CppJieba
|
||||
LogError("_trie.init failed.");
|
||||
return false;
|
||||
}
|
||||
LogInfo("_trie.loadDict(%s) start...", filePath);
|
||||
if(!_trie.loadDict(filePath))
|
||||
LogInfo("_trie.loadDict(%s) start...", _dictPath.c_str());
|
||||
if(!_trie.loadDict(_dictPath.c_str()))
|
||||
{
|
||||
LogError("_trie.loadDict faield.");
|
||||
return false;
|
||||
@ -58,7 +60,7 @@ namespace CppJieba
|
||||
LogInfo("_trie.loadDict end.");
|
||||
return _setInitFlag(true);
|
||||
}
|
||||
bool dispose()
|
||||
virtual bool dispose()
|
||||
{
|
||||
if(!_getInitFlag())
|
||||
{
|
||||
@ -69,12 +71,7 @@ namespace CppJieba
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
//bool cut(const string& str, vector<TrieNodeInfo>& segWordInfos)const;
|
||||
//bool cut(const string& str, vector<string>& res)const
|
||||
//{
|
||||
// return SegmentBase::cut(str, res);
|
||||
//}
|
||||
bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const
|
||||
virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const
|
||||
{
|
||||
if(!_getInitFlag())
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ namespace CppJieba
|
||||
MPSegment _mpSeg;
|
||||
HMMSegment _hmmSeg;
|
||||
public:
|
||||
MixSegment()
|
||||
MixSegment(const char * const mpSegDict, const char * const hmmSegDict): _mpSeg(mpSegDict), _hmmSeg(hmmSegDict)
|
||||
{
|
||||
}
|
||||
virtual ~MixSegment()
|
||||
@ -21,26 +21,26 @@ namespace CppJieba
|
||||
dispose();
|
||||
}
|
||||
public:
|
||||
bool init(const char* const mpSegDict, const char* const hmmSegDict)
|
||||
virtual bool init()
|
||||
{
|
||||
if(_getInitFlag())
|
||||
{
|
||||
LogError("inited.");
|
||||
return false;
|
||||
}
|
||||
if(!_mpSeg.init(mpSegDict))
|
||||
if(!_mpSeg.init())
|
||||
{
|
||||
LogError("_mpSeg init");
|
||||
return false;
|
||||
}
|
||||
if(!_hmmSeg.init(hmmSegDict))
|
||||
if(!_hmmSeg.init())
|
||||
{
|
||||
LogError("_hmmSeg init");
|
||||
return false;
|
||||
}
|
||||
return _setInitFlag(true);
|
||||
}
|
||||
bool dispose()
|
||||
virtual bool dispose()
|
||||
{
|
||||
if(!_getInitFlag())
|
||||
{
|
||||
@ -52,13 +52,9 @@ namespace CppJieba
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
//virtual bool cut(const string& str, vector<string>& res) const;
|
||||
//bool cut(const string& str, vector<string>& res)const
|
||||
//{
|
||||
// return SegmentBase::cut(str, res);
|
||||
//}
|
||||
using SegmentBase::cut;
|
||||
bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const
|
||||
public:
|
||||
virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const
|
||||
{
|
||||
if(!_getInitFlag())
|
||||
{
|
||||
|
@ -18,6 +18,10 @@ namespace CppJieba
|
||||
bool _isInited;
|
||||
bool _getInitFlag()const{return _isInited;};
|
||||
bool _setInitFlag(bool flag){return _isInited = flag;};
|
||||
public:
|
||||
virtual bool init() = 0;
|
||||
virtual bool dispose() = 0;
|
||||
|
||||
public:
|
||||
virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const = 0;
|
||||
virtual bool cut(const string& str, vector<string>& res)const
|
||||
|
@ -53,8 +53,8 @@ int main(int argc, char ** argv)
|
||||
|
||||
if("cutHMM" == algorithm)
|
||||
{
|
||||
HMMSegment seg;
|
||||
if(!seg.init(modelPath.c_str()))
|
||||
HMMSegment seg(modelPath.c_str());
|
||||
if(!seg.init())
|
||||
{
|
||||
cout<<"seg init failed."<<endl;
|
||||
return EXIT_FAILURE;
|
||||
@ -64,8 +64,8 @@ int main(int argc, char ** argv)
|
||||
}
|
||||
else if("cutDAG" == algorithm)
|
||||
{
|
||||
MPSegment seg;
|
||||
if(!seg.init(dictPath.c_str()))
|
||||
MPSegment seg(dictPath.c_str());
|
||||
if(!seg.init())
|
||||
{
|
||||
cout<<"seg init failed."<<endl;
|
||||
return false;
|
||||
@ -75,8 +75,8 @@ int main(int argc, char ** argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
MixSegment seg;
|
||||
if(!seg.init(dictPath.c_str(), modelPath.c_str()))
|
||||
MixSegment seg(dictPath.c_str(), modelPath.c_str());
|
||||
if(!seg.init())
|
||||
{
|
||||
cout<<"seg init failed."<<endl;
|
||||
return EXIT_FAILURE;
|
||||
|
@ -14,13 +14,10 @@ using namespace CppJieba;
|
||||
|
||||
class ReqHandler: public IRequestHandler
|
||||
{
|
||||
private:
|
||||
string _dictPath;
|
||||
string _modelPath;
|
||||
public:
|
||||
ReqHandler(const string& dictPath, const string& modelPath): _dictPath(dictPath), _modelPath(modelPath){};
|
||||
ReqHandler(const string& dictPath, const string& modelPath): _segment(dictPath.c_str(), modelPath.c_str()){};
|
||||
virtual ~ReqHandler(){};
|
||||
virtual bool init(){return _segment.init(_dictPath.c_str(), _modelPath.c_str());};
|
||||
virtual bool init(){return _segment.init();};
|
||||
virtual bool dispose(){return _segment.dispose();};
|
||||
public:
|
||||
virtual bool do_GET(const HttpReqInfo& httpReq, string& strSnd)
|
||||
|
Loading…
x
Reference in New Issue
Block a user