From 70f12f2c97eaf011cae89fb1fbe4df11381dffbe Mon Sep 17 00:00:00 2001 From: wyy Date: Mon, 9 Sep 2013 00:40:01 +0800 Subject: [PATCH] init mixSegment.cpp/h --- src/HMMSegment.cpp | 2 +- src/Makefile | 2 ++ src/MixSegment.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++ src/MixSegment.h | 26 ++++++++++++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/MixSegment.cpp create mode 100644 src/MixSegment.h diff --git a/src/HMMSegment.cpp b/src/HMMSegment.cpp index 7fda28c..12690ce 100644 --- a/src/HMMSegment.cpp +++ b/src/HMMSegment.cpp @@ -256,7 +256,7 @@ namespace CppJieba return false; } vector tmp, tmp2; - uint16_t unico; + uint16_t unico = 0; splitStr(line, tmp, ","); for(uint i = 0; i < tmp.size(); i++) { diff --git a/src/Makefile b/src/Makefile index a6b92c3..fbfaafe 100644 --- a/src/Makefile +++ b/src/Makefile @@ -63,6 +63,8 @@ TransCode.ut: TransCode.cpp TransCode.h globals.h $(CMLIB) $(CXX) -o $@ $(CXXFLAGS) TransCode.cpp -DCPPJIEBA_TRANSCODE_UT $(CMLIB) HMMSegment.ut: HMMSegment.cpp TransCode.cpp TransCode.h HMMSegment.h $(CMLIB) $(CXX) -o $@ $(CXXFLAGS) TransCode.cpp HMMSegment.cpp -DHMMSEGMENT_UT $(CMLIB) +MixSegment.ut: MixSegment.cpp MixSegment.h HMMSegment.cpp MPSegment.cpp Trie.cpp MPSegment.h Trie.h globals.h $(CMLIB) + $(CXX) -o $@ $(CXXFLAGS) MixSegment.cpp HMMSegment.cpp MPSegment.cpp Trie.cpp TransCode.cpp -DMIXSEGMENT_UT $(CMLIB) clean: rm -f *.o *.d *.ut $(LIBA) diff --git a/src/MixSegment.cpp b/src/MixSegment.cpp new file mode 100644 index 0000000..4b592d0 --- /dev/null +++ b/src/MixSegment.cpp @@ -0,0 +1,59 @@ +#include "MixSegment.h" + +namespace CppJieba +{ + MixSegment::MixSegment() + { + } + + MixSegment::~MixSegment() + { + } + + bool MixSegment::init(const char* const mpSegDict, const char* const hmmSegDict) + { + if(!_mpSeg.init(mpSegDict)) + { + LogError("_mpSeg init"); + return false; + } + if(!_hmmSeg.init(hmmSegDict)) + { + LogError("_hmmSeg init"); + return false; + } + return true; + } + + bool MixSegment::dispose() + { + _mpSeg.dispose(); + _hmmSeg.dispose(); + return true; + } + + bool MixSegment::cut(const string& str, vector& res) + { + vector infos; + if(!_mpSeg.cutDAG(str, infos)) + { + LogError("_mpSeg cutDAG failed."); + return false; + } + for(uint = 0; i < infos.size(); i++) + { + + } + return true; + } +} + +#ifdef MIXSEGMENT_UT +using namespace CppJieba; + +int main() +{ + return 0; +} + +#endif diff --git a/src/MixSegment.h b/src/MixSegment.h new file mode 100644 index 0000000..f2843d5 --- /dev/null +++ b/src/MixSegment.h @@ -0,0 +1,26 @@ +#ifndef CPPJIEBA_MIXSEGMENT_H +#define CPPJIEBA_MIXSEGMENT_H + +#include "MPSegment.h" +#include "HMMSegment.h" +#include "cppcommon/headers.h" + +namespace CppJieba +{ + class MixSegment + { + private: + MPSegment _mpSeg; + HMMSegment _hmmSeg; + public: + MixSegment(); + ~MixSegment(); + public: + bool init(const char* const _mpSegDict, const char* const _hmmSegDict); + bool dispose(); + public: + bool cut(const string& str, vector& res); + }; +} + +#endif