From 789ea7c1dacbd1f84311363439cfc9583fc74e6b Mon Sep 17 00:00:00 2001 From: gwdwyy Date: Sun, 8 Sep 2013 22:20:18 +0800 Subject: [PATCH] modify some function name and structs's contruct fucntion --- demo/segment_demo.cpp | 21 +++++++++++++++------ src/structs.h | 32 ++++++++------------------------ 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/demo/segment_demo.cpp b/demo/segment_demo.cpp index 76ce038..4f7754d 100644 --- a/demo/segment_demo.cpp +++ b/demo/segment_demo.cpp @@ -23,14 +23,13 @@ bool init(const char * const dictPath, const char * const modelPath) return true; } -void run(const char * const filePath) +void cut(const char * const filePath) { ifstream ifile(filePath); vector res; string line; while(getline(ifile, line)) { - res.clear(); if(!line.empty()) { seg.cutDAG(line, res); @@ -39,14 +38,13 @@ void run(const char * const filePath) } } -void hmmrun(const char * const filePath) +void cutHMM(const char * const filePath) { ifstream ifile(filePath); vector res; string line; while(getline(ifile, line)) { - res.clear(); if(!line.empty()) { hmmseg.cut(line, res); @@ -55,6 +53,17 @@ void hmmrun(const char * const filePath) } } +void cutAll(const char* const filePath) +{ + ifstream ifs(filePath); + vector res; + string line; + while(getline(ifs, line)) + { + seg.cutDAG(line, res); + } +} + bool dispose() { if(!seg.dispose()) @@ -120,11 +129,11 @@ int main(int argc, char ** argv) } if("cutHMM" == algorithm) { - hmmrun(arg[1].c_str()); + cutHMM(arg[1].c_str()); } else { - run(arg[1].c_str()); + cut(arg[1].c_str()); } dispose(); return 0; diff --git a/src/structs.h b/src/structs.h index 4793348..30045af 100644 --- a/src/structs.h +++ b/src/structs.h @@ -15,28 +15,23 @@ namespace CppJieba size_t freq; string tag; double logFreq; //logFreq = log(freq/sum(freq)); - TrieNodeInfo() + TrieNodeInfo():wLen(0),freq(0),logFreq(0.0) { - wLen = 0; - freq = 0; - logFreq = 0.0; } - TrieNodeInfo(const string& _word) + TrieNodeInfo(const TrieNodeInfo& nodeInfo):word(nodeInfo.word), wLen(nodeInfo.wLen), freq(nodeInfo.freq), tag(nodeInfo.tag), logFreq(nodeInfo.logFreq) + { + } + TrieNodeInfo(const string& _word):word(_word),freq(0),logFreq(MIN_DOUBLE) { - word = _word; wLen = TransCode::getWordLength(_word); - freq = 0; - logFreq = MIN_DOUBLE; } }; - struct SegmentContext//: public TrieNodeInfo { vector uintVec; vector< vector > > dag; vector< pair > dp; - //vector words; }; /* @@ -50,25 +45,14 @@ namespace CppJieba { double idf; double weight;// log(wLen+1)*logFreq; - KeyWordInfo() + KeyWordInfo():idf(0.0),weight(0.0) { - idf = 0.0; - weight = 0.0; } - KeyWordInfo(const string& _word):TrieNodeInfo(_word) + KeyWordInfo(const string& _word):TrieNodeInfo(_word),idf(0.0),weight(0.0) { - idf = 0.0; - weight = 0.0; } - KeyWordInfo(const TrieNodeInfo& trieNodeInfo) + KeyWordInfo(const TrieNodeInfo& trieNodeInfo):TrieNodeInfo(trieNodeInfo) { - word = trieNodeInfo.word; - freq = trieNodeInfo.freq; - wLen = trieNodeInfo.wLen; - tag = trieNodeInfo.tag; - logFreq = trieNodeInfo.logFreq; - idf = 0.0; - weight = 0.0; } string toString() const {