mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
fix bugs
This commit is contained in:
parent
05a4ba3a22
commit
dce3755d79
@ -120,24 +120,22 @@ namespace CppJieba
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout<<__FILE__<<__LINE__<<endl;
|
|
||||||
if(!viterbi(unico, status))
|
if(!viterbi(unico, status))
|
||||||
{
|
{
|
||||||
LogError("viterbi failed.");
|
LogError("viterbi failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
begin = unico.begin();
|
begin = unico.begin();
|
||||||
|
left = begin;
|
||||||
res.clear();
|
res.clear();
|
||||||
for(uint i =0; i< status.size(); i++)
|
for(uint i =0; i< status.size(); i++)
|
||||||
{
|
{
|
||||||
switch(status[i])
|
switch(status[i])
|
||||||
{
|
{
|
||||||
case B:
|
|
||||||
left = begin + i;
|
|
||||||
break;
|
|
||||||
case E:
|
case E:
|
||||||
right = begin + i + 1;
|
right = begin + i + 1;
|
||||||
res.push_back(TransCode::vecToStr(left, right));
|
res.push_back(TransCode::vecToStr(left, right));
|
||||||
|
left = right;
|
||||||
break;
|
break;
|
||||||
case S:
|
case S:
|
||||||
res.push_back(TransCode::vecToStr(begin + i, begin + i +1));
|
res.push_back(TransCode::vecToStr(begin + i, begin + i +1));
|
||||||
@ -187,7 +185,6 @@ namespace CppJieba
|
|||||||
weight[0 + y * X] = _startProb[y] + _getEmitProb(_emitProbVec[y], unico[0], MIN_DOUBLE);
|
weight[0 + y * X] = _startProb[y] + _getEmitProb(_emitProbVec[y], unico[0], MIN_DOUBLE);
|
||||||
path[0 + y * X] = -1;
|
path[0 + y * X] = -1;
|
||||||
}
|
}
|
||||||
cout<<__FILE__<<__LINE__<<endl;
|
|
||||||
|
|
||||||
//process
|
//process
|
||||||
for(uint x = 1; x < X; x++)
|
for(uint x = 1; x < X; x++)
|
||||||
@ -196,12 +193,11 @@ namespace CppJieba
|
|||||||
{
|
{
|
||||||
now = x + y*X;
|
now = x + y*X;
|
||||||
weight[now] = MIN_DOUBLE;
|
weight[now] = MIN_DOUBLE;
|
||||||
path[now] = E;
|
path[now] = E; // warning
|
||||||
for(uint preY = 0; preY < Y; preY++)
|
for(uint preY = 0; preY < Y; preY++)
|
||||||
{
|
{
|
||||||
old = x - 1 + preY * X;
|
old = x - 1 + preY * X;
|
||||||
tmp = weight[old] + _transProb[preY][y] + _getEmitProb(_emitProbVec[y], unico[x], MIN_DOUBLE);
|
tmp = weight[old] + _transProb[preY][y] + _getEmitProb(_emitProbVec[y], unico[x], MIN_DOUBLE);
|
||||||
//cout<<__FILE__<<__LINE__<<endl;
|
|
||||||
//cout<<MIN_DOUBLE+MIN_DOUBLE+MIN_DOUBLE<<endl;
|
//cout<<MIN_DOUBLE+MIN_DOUBLE+MIN_DOUBLE<<endl;
|
||||||
//cout<<weight[old]<<":"<<_transProb[preY][y]<<":"<<_getEmitProb(_emitProbVec[y], unico[x], MIN_DOUBLE)<<endl;
|
//cout<<weight[old]<<":"<<_transProb[preY][y]<<":"<<_getEmitProb(_emitProbVec[y], unico[x], MIN_DOUBLE)<<endl;
|
||||||
//cout<<tmp<<endl;
|
//cout<<tmp<<endl;
|
||||||
@ -211,7 +207,6 @@ namespace CppJieba
|
|||||||
path[now] = preY;
|
path[now] = preY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//cout<<__FILE__<<__LINE__<<endl;
|
|
||||||
//cout<<x<<":"<<y<<":"<<weight[now]<<endl;
|
//cout<<x<<":"<<y<<":"<<weight[now]<<endl;
|
||||||
//getchar();
|
//getchar();
|
||||||
}
|
}
|
||||||
@ -228,19 +223,14 @@ namespace CppJieba
|
|||||||
{
|
{
|
||||||
stat = S;
|
stat = S;
|
||||||
}
|
}
|
||||||
cout<<__FILE__<<__LINE__<<endl;
|
|
||||||
|
|
||||||
status.assign(X, 0);
|
status.assign(X, 0);
|
||||||
cout<<__FILE__<<__LINE__<<endl;
|
|
||||||
for(int x = X -1 ; x >= 0; x--)
|
for(int x = X -1 ; x >= 0; x--)
|
||||||
{
|
{
|
||||||
status[x] = stat;
|
status[x] = stat;
|
||||||
cout<<__FILE__<<__LINE__<<endl;
|
|
||||||
cout<<stat<<endl;
|
|
||||||
stat = path[x + stat*X];
|
stat = path[x + stat*X];
|
||||||
}
|
}
|
||||||
|
|
||||||
cout<<__FILE__<<__LINE__<<endl;
|
|
||||||
delete [] path;
|
delete [] path;
|
||||||
delete [] weight;
|
delete [] weight;
|
||||||
return true;
|
return true;
|
||||||
@ -302,6 +292,7 @@ namespace CppJieba
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
double HMMSegment::_getEmitProb(const EmitProbMap& mp, uint16_t key, double defVal)
|
double HMMSegment::_getEmitProb(const EmitProbMap& mp, uint16_t key, double defVal)
|
||||||
{
|
{
|
||||||
EmitProbMap::const_iterator cit = mp.find(key);
|
EmitProbMap::const_iterator cit = mp.find(key);
|
||||||
@ -311,6 +302,7 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
return cit->second;
|
return cit->second;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
double HMMSegment::_getEmitProb(const EmitProbMap* ptMp, uint16_t key, double defVal)
|
double HMMSegment::_getEmitProb(const EmitProbMap* ptMp, uint16_t key, double defVal)
|
||||||
{
|
{
|
||||||
@ -339,7 +331,7 @@ int main()
|
|||||||
HMMSegment hmm;
|
HMMSegment hmm;
|
||||||
hmm.loadModel("../dicts/hmm_model.utf8");
|
hmm.loadModel("../dicts/hmm_model.utf8");
|
||||||
vector<string> res;
|
vector<string> res;
|
||||||
hmm.cut("小明硕士毕业于北邮网络研究院,然", res);
|
hmm.cut("小明硕士毕业于北邮网络研究院。。.", res);
|
||||||
cout<<joinStr(res, "/")<<endl;
|
cout<<joinStr(res, "/")<<endl;
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ namespace CppJieba
|
|||||||
bool _getLine(ifstream& ifile, string& line);
|
bool _getLine(ifstream& ifile, string& line);
|
||||||
bool _loadEmitProb(const string& line, EmitProbMap& mp);
|
bool _loadEmitProb(const string& line, EmitProbMap& mp);
|
||||||
bool _decodeOne(const string& str, uint16_t& res);
|
bool _decodeOne(const string& str, uint16_t& res);
|
||||||
double _getEmitProb(const EmitProbMap& mp, uint16_t key, double defVal);
|
//double _getEmitProb(const EmitProbMap& mp, uint16_t key, double defVal);
|
||||||
double _getEmitProb(const EmitProbMap* ptMp, uint16_t key, double defVal);
|
double _getEmitProb(const EmitProbMap* ptMp, uint16_t key, double defVal);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user