finishing cutDAG

This commit is contained in:
gwdwyy 2013-07-09 15:59:53 +08:00
parent b7f51f6772
commit 9122aeeba6
2 changed files with 20 additions and 13 deletions

View File

@ -32,19 +32,7 @@ namespace CppJieba
//calc DAG
vector<vector<uint> > dag;
for(uint i = 0; i < uniStr.size(); i+=2)
{
vector<uint> vec;
vec.push_back(i/2);
for(uint j = i + 4; j <= uniStr.size(); j+=2)
{
if(NULL != _trie.find(uniStr.substr(i, j - i)))
{
vec.push_back((j - 2)/2);
}
}
dag.push_back(vec);
}
_calcDAG(uniStr, dag);
cout<<__FILE__<<__LINE__<<endl;
PRINT_MATRIX(dag);
@ -86,6 +74,24 @@ namespace CppJieba
return uniStr;
}
bool Segment::_calcDAG(const string& uniStr, vector<vector<uint> >& dag)
{
for(uint i = 0; i < uniStr.size(); i+=2)
{
vector<uint> vec;
vec.push_back(i/2);
for(uint j = i + 4; j <= uniStr.size(); j+=2)
{
if(NULL != _trie.find(uniStr.substr(i, j - i)))
{
vec.push_back((j - 2)/2);
}
}
dag.push_back(vec);
}
return true;
}
bool Segment::_calcDP(const string& uniStr, const vector<vector<uint> >& dag, vector<pair<int, double> >& res)
{
if(uniStr.size() / 2 != dag.size())

View File

@ -22,6 +22,7 @@ namespace CppJieba
private:
string _utf8ToUni(const string& chStr);
bool _calcDAG(const string& uniStr, vector<vector<uint> >& dag);
bool _calcDP(const string& uniStr, const vector<vector<uint> >& dag, vector<pair<int, double> >& res);
private: