mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
ci for lunch
This commit is contained in:
parent
1169521c42
commit
313e05da1b
@ -158,21 +158,22 @@ namespace CppJieba
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<pair<uint, const TrieNodeInfo*> > vp;
|
//vector<pair<uint, const TrieNodeInfo*> > vp;
|
||||||
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));
|
||||||
SegmentChar& back = segContext.back();
|
SegmentChar& back = segContext.back();
|
||||||
int i = it - begin;
|
uint i = it - begin;
|
||||||
vp.clear();
|
_trie.find(it, end, i, back.dag);
|
||||||
if(_trie.find(it, end, vp))
|
//vp.clear();
|
||||||
{
|
//if(_trie.find(it, end, vp))
|
||||||
for(uint j = 0; j < vp.size(); j++)
|
//{
|
||||||
{
|
// for(uint j = 0; j < vp.size(); j++)
|
||||||
uint nextp = vp[j].first + i;
|
// {
|
||||||
back.dag[nextp] = vp[j].second;
|
// uint nextp = vp[j].first + i;
|
||||||
}
|
// back.dag[nextp] = vp[j].second;
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
if(back.dag.end() == back.dag.find(i))
|
if(back.dag.end() == back.dag.find(i))
|
||||||
{
|
{
|
||||||
back.dag[i] = NULL;
|
back.dag[i] = NULL;
|
||||||
|
56
src/Trie.hpp
56
src/Trie.hpp
@ -157,15 +157,15 @@ namespace CppJieba
|
|||||||
bool _getInitFlag()const{return _initFlag;};
|
bool _getInitFlag()const{return _initFlag;};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const TrieNodeInfo* find(const string& str)const
|
//const TrieNodeInfo* find(const string& str)const
|
||||||
{
|
//{
|
||||||
Unicode uintVec;
|
// Unicode uintVec;
|
||||||
if(!TransCode::decode(str, uintVec))
|
// if(!TransCode::decode(str, uintVec))
|
||||||
{
|
// {
|
||||||
return NULL;
|
// return NULL;
|
||||||
}
|
// }
|
||||||
return find(uintVec.begin(), uintVec.end());
|
// return find(uintVec.begin(), uintVec.end());
|
||||||
}
|
//}
|
||||||
const TrieNodeInfo* find(Unicode::const_iterator begin, Unicode::const_iterator end)const
|
const TrieNodeInfo* find(Unicode::const_iterator begin, Unicode::const_iterator end)const
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -244,6 +244,44 @@ namespace CppJieba
|
|||||||
return !res.empty();
|
return !res.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool find(Unicode::const_iterator begin, Unicode::const_iterator end, uint offset, unordered_map<uint, const TrieNodeInfo* > & res) const
|
||||||
|
{
|
||||||
|
if(!_getInitFlag())
|
||||||
|
{
|
||||||
|
LogFatal("trie not initted!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (begin >= end)
|
||||||
|
{
|
||||||
|
LogFatal("begin >= end");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TrieNode* p = _root;
|
||||||
|
for (Unicode::const_iterator itr = begin; itr != end; itr++)
|
||||||
|
{
|
||||||
|
if(p->hmap.find(*itr) == p-> hmap.end())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p = p->hmap[*itr];
|
||||||
|
if(p->isLeaf)
|
||||||
|
{
|
||||||
|
uint pos = p->nodeInfoVecPos;
|
||||||
|
if(pos < _nodeInfoVec.size())
|
||||||
|
{
|
||||||
|
//res.push_back(make_pair(itr-begin, &_nodeInfoVec[pos]));
|
||||||
|
res[itr-begin + offset] = &_nodeInfoVec[pos];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogFatal("node's nodeInfoVecPos is out of _nodeInfoVec's range");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !res.empty();
|
||||||
|
}
|
||||||
|
|
||||||
//bool find(const Unicode& unico, vector<pair<uint, const TrieNodeInfo*> >& res)const
|
//bool find(const Unicode& unico, vector<pair<uint, const TrieNodeInfo*> >& res)const
|
||||||
//{
|
//{
|
||||||
// if (!unico.empty())
|
// if (!unico.empty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user