From 679179859e7784760d595e35c425fe2d7350c1a6 Mon Sep 17 00:00:00 2001 From: wyy Date: Sat, 21 Dec 2013 21:47:01 -0800 Subject: [PATCH] add some log debug & info --- src/HMMSegment.hpp | 13 ++++++++++--- src/MPSegment.hpp | 1 + src/MixSegment.hpp | 5 +++-- src/TrieManager.hpp | 7 ++----- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/HMMSegment.hpp b/src/HMMSegment.hpp index 3ef0097..c2782af 100644 --- a/src/HMMSegment.hpp +++ b/src/HMMSegment.hpp @@ -46,6 +46,7 @@ namespace CppJieba { if(_getInitFlag()) { + LogError("inited already."); return false; } memset(_startProb, 0, sizeof(_startProb)); @@ -58,7 +59,13 @@ namespace CppJieba _emitProbVec.push_back(&_emitProbE); _emitProbVec.push_back(&_emitProbM); _emitProbVec.push_back(&_emitProbS); - return _setInitFlag(_loadModel(filePath.c_str())); + if(!_setInitFlag(_loadModel(filePath.c_str()))) + { + LogError("_loadModel(%s) failed.", filePath.c_str()); + return false; + } + LogInfo("HMMSegment init(%s) ok.", filePath.c_str()); + return true; } public: using SegmentBase::cut; @@ -198,7 +205,7 @@ namespace CppJieba } bool _loadModel(const char* const filePath) { - LogInfo("loadModel [%s] start ...", filePath); + LogDebug("loadModel [%s] start ...", filePath); ifstream ifile(filePath); string line; vector tmp; @@ -264,7 +271,7 @@ namespace CppJieba return false; } - LogInfo("loadModel [%s] end.", filePath); + LogDebug("loadModel [%s] end.", filePath); return true; } diff --git a/src/MPSegment.hpp b/src/MPSegment.hpp index 0b85137..9b0353a 100644 --- a/src/MPSegment.hpp +++ b/src/MPSegment.hpp @@ -56,6 +56,7 @@ namespace CppJieba LogError("get a NULL pointor form getTrie(\"%s\").", dictPath.c_str()); return false; } + LogInfo("MPSegment init(%s) ok", dictPath.c_str()); return _setInitFlag(true); } public: diff --git a/src/MixSegment.hpp b/src/MixSegment.hpp index 6e9abed..9218056 100644 --- a/src/MixSegment.hpp +++ b/src/MixSegment.hpp @@ -15,9 +15,9 @@ namespace CppJieba HMMSegment _hmmSeg; public: MixSegment(){_setInitFlag(false);}; - explicit MixSegment(const string& mpSegDict, const string& hmmSegDict): _mpSeg(mpSegDict), _hmmSeg(hmmSegDict) + explicit MixSegment(const string& mpSegDict, const string& hmmSegDict) { - _setInitFlag(_mpSeg && _hmmSeg); + _setInitFlag(init(mpSegDict, hmmSegDict)); } virtual ~MixSegment(){} public: @@ -38,6 +38,7 @@ namespace CppJieba LogError("_hmmSeg init"); return false; } + LogInfo("MixSegment init(%s, %s)", mpSegDict.c_str(), hmmSegDict.c_str()); return _setInitFlag(true); } public: diff --git a/src/TrieManager.hpp b/src/TrieManager.hpp index d011ccb..aabdb05 100644 --- a/src/TrieManager.hpp +++ b/src/TrieManager.hpp @@ -23,15 +23,13 @@ namespace CppJieba LogError("error when getting md5 for file '%s'", dictpath); return NULL; } - LogInfo("md5 for file '%s': %s", dictpath, md5.c_str()); if (_tries.find(md5) != _tries.end()) { - LogInfo("find a exits trie for md5: '%s'", md5.c_str()); return _tries[md5.c_str()]; } - LogInfo("create a new trie for md5: '%s'", md5.c_str()); + //LogDebug("create a new trie for md5: '%s'", md5.c_str()); Trie* trie = NULL; try { @@ -54,15 +52,14 @@ namespace CppJieba return NULL; } - LogInfo("trie->loadDict(%s) start...", dictpath); if (!trie->loadDict(dictpath)) { LogError("trie->loadDict(%s) failed...", dictpath); return NULL; } - LogInfo("trie->loadDict end..."); _tries[md5.c_str()] = trie; + LogDebug("trie->loadDict(%s)", dictpath); return trie; }