mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
commit
47ba6b60ee
@ -21,7 +21,7 @@ namespace CppJieba
|
|||||||
DagType dag;
|
DagType dag;
|
||||||
const TrieNodeInfo * pInfo;
|
const TrieNodeInfo * pInfo;
|
||||||
double weight;
|
double weight;
|
||||||
|
|
||||||
SegmentChar(uint16_t uni):uniCh(uni), pInfo(NULL), weight(0.0)
|
SegmentChar(uint16_t uni):uniCh(uni), pInfo(NULL), weight(0.0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -102,59 +102,59 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
bool cut(const string& str, vector<TrieNodeInfo>& segWordInfos)const
|
bool cut(const string& str, vector<TrieNodeInfo>& segWordInfos)const
|
||||||
{
|
{
|
||||||
if(!_getInitFlag())
|
if(!_getInitFlag())
|
||||||
{
|
{
|
||||||
LogError("not inited.");
|
LogError("not inited.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(str.empty())
|
if(str.empty())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Unicode sentence;
|
Unicode sentence;
|
||||||
|
|
||||||
if(!TransCode::decode(str, sentence))
|
if(!TransCode::decode(str, sentence))
|
||||||
{
|
{
|
||||||
LogError("TransCode::decode failed.");
|
LogError("TransCode::decode failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return cut(sentence.begin(), sentence.end(), segWordInfos);
|
return cut(sentence.begin(), sentence.end(), segWordInfos);
|
||||||
|
|
||||||
}
|
}
|
||||||
bool cut(Unicode::const_iterator begin , Unicode::const_iterator end, vector<TrieNodeInfo>& segWordInfos)const
|
bool cut(Unicode::const_iterator begin , Unicode::const_iterator end, vector<TrieNodeInfo>& segWordInfos)const
|
||||||
{
|
{
|
||||||
if(!_getInitFlag())
|
if(!_getInitFlag())
|
||||||
{
|
{
|
||||||
LogError("not inited.");
|
LogError("not inited.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SegmentContext segContext;
|
SegmentContext segContext;
|
||||||
for(Unicode::const_iterator it = begin; it != end; it++)
|
for(Unicode::const_iterator it = begin; it != end; it++)
|
||||||
{
|
{
|
||||||
segContext.push_back(SegmentChar(*it));
|
segContext.push_back(SegmentChar(*it));
|
||||||
}
|
}
|
||||||
|
|
||||||
//calc DAG
|
|
||||||
if(!_calcDAG(segContext))
|
|
||||||
{
|
|
||||||
LogError("_calcDAG failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!_calcDP(segContext))
|
//calc DAG
|
||||||
{
|
if(!_calcDAG(segContext))
|
||||||
LogError("_calcDP failed.");
|
{
|
||||||
return false;
|
LogError("_calcDAG failed.");
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if(!_cut(segContext, segWordInfos))
|
if(!_calcDP(segContext))
|
||||||
{
|
{
|
||||||
LogError("_cut failed.");
|
LogError("_calcDP failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
if(!_cut(segContext, segWordInfos))
|
||||||
}
|
{
|
||||||
|
LogError("_cut failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
//virtual bool cut(const string& str, vector<string>& res)const;
|
//virtual bool cut(const string& str, vector<string>& res)const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user