do some rename

This commit is contained in:
wyy 2014-04-16 19:12:24 +08:00
parent 76d640b26e
commit d61d694ac7

View File

@ -23,11 +23,10 @@ namespace CppJieba
DagType dag; DagType dag;
const DictUnit * pInfo; const DictUnit * pInfo;
double weight; double weight;
size_t nextPos;
SegmentChar():uniCh(0), pInfo(NULL), weight(0.0) SegmentChar():uniCh(0), pInfo(NULL), weight(0.0), nextPos(0)
{} {}
}; };
typedef vector<SegmentChar> SegmentContext;
class MPSegment: public SegmentBase class MPSegment: public SegmentBase
{ {
@ -91,21 +90,21 @@ namespace CppJieba
LogError("not inited."); LogError("not inited.");
return false; return false;
} }
SegmentContext segContext; vector<SegmentChar> SegmentChars;
//calc DAG //calc DAG
if(!_calcDAG(begin, end, segContext)) if(!_calcDAG(begin, end, SegmentChars))
{ {
LogError("_calcDAG failed."); LogError("_calcDAG failed.");
return false; return false;
} }
if(!_calcDP(segContext)) if(!_calcDP(SegmentChars))
{ {
LogError("_calcDP failed."); LogError("_calcDP failed.");
return false; return false;
} }
if(!_cut(segContext, res)) if(!_cut(SegmentChars, res))
{ {
LogError("_cut failed."); LogError("_cut failed.");
return false; return false;
@ -115,7 +114,7 @@ namespace CppJieba
} }
private: private:
bool _calcDAG(Unicode::const_iterator begin, Unicode::const_iterator end, SegmentContext& segContext) const bool _calcDAG(Unicode::const_iterator begin, Unicode::const_iterator end, vector<SegmentChar>& SegmentChars) const
{ {
SegmentChar schar; SegmentChar schar;
size_t offset; size_t offset;
@ -129,15 +128,15 @@ namespace CppJieba
{ {
schar.dag[offset] = NULL; schar.dag[offset] = NULL;
} }
segContext.push_back(schar); SegmentChars.push_back(schar);
} }
return true; return true;
} }
bool _calcDP(SegmentContext& segContext)const bool _calcDP(vector<SegmentChar>& SegmentChars)const
{ {
if(segContext.empty()) if(SegmentChars.empty())
{ {
LogError("segContext empty"); LogError("SegmentChars empty");
return false; return false;
} }
@ -145,18 +144,18 @@ namespace CppJieba
const DictUnit* p; const DictUnit* p;
double val; double val;
for(int i = segContext.size() - 1; i >= 0; i--) for(int i = SegmentChars.size() - 1; i >= 0; i--)
{ {
segContext[i].pInfo = NULL; SegmentChars[i].pInfo = NULL;
segContext[i].weight = MIN_DOUBLE; SegmentChars[i].weight = MIN_DOUBLE;
for(DagType::const_iterator it = segContext[i].dag.begin(); it != segContext[i].dag.end(); it++) for(DagType::const_iterator it = SegmentChars[i].dag.begin(); it != SegmentChars[i].dag.end(); it++)
{ {
nextPos = it->first; nextPos = it->first;
p = it->second; p = it->second;
val = 0.0; val = 0.0;
if(nextPos + 1 < segContext.size()) if(nextPos + 1 < SegmentChars.size())
{ {
val += segContext[nextPos + 1].weight; val += SegmentChars[nextPos + 1].weight;
} }
if(p) if(p)
@ -167,22 +166,22 @@ namespace CppJieba
{ {
val += _dictTrie.getMinLogFreq(); val += _dictTrie.getMinLogFreq();
} }
if(val > segContext[i].weight) if(val > SegmentChars[i].weight)
{ {
segContext[i].pInfo = p; SegmentChars[i].pInfo = p;
segContext[i].weight = val; SegmentChars[i].weight = val;
} }
} }
} }
return true; return true;
} }
bool _cut(SegmentContext& segContext, vector<Unicode>& res)const bool _cut(vector<SegmentChar>& SegmentChars, vector<Unicode>& res)const
{ {
size_t i = 0; size_t i = 0;
while(i < segContext.size()) while(i < SegmentChars.size())
{ {
const DictUnit* p = segContext[i].pInfo; const DictUnit* p = SegmentChars[i].pInfo;
if(p) if(p)
{ {
res.push_back(p->word); res.push_back(p->word);
@ -190,7 +189,7 @@ namespace CppJieba
} }
else//single chinese word else//single chinese word
{ {
res.push_back(Unicode(1, segContext[i].uniCh)); res.push_back(Unicode(1, SegmentChars[i].uniCh));
i++; i++;
} }
} }