mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
little modify MPSegment
This commit is contained in:
parent
45a7cac784
commit
61f542a6b1
@ -24,7 +24,7 @@ namespace CppJieba
|
|||||||
const TrieNodeInfo * pInfo;
|
const TrieNodeInfo * pInfo;
|
||||||
double weight;
|
double weight;
|
||||||
|
|
||||||
SegmentChar(uint16_t uni):uniCh(uni), pInfo(NULL), weight(0.0)
|
SegmentChar():uniCh(0), pInfo(NULL), weight(0.0)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
typedef vector<SegmentChar> SegmentContext;
|
typedef vector<SegmentChar> SegmentContext;
|
||||||
@ -117,15 +117,17 @@ 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, SegmentContext& segContext) const
|
||||||
{
|
{
|
||||||
|
SegmentChar schar;
|
||||||
|
size_t offset;
|
||||||
for(Unicode::const_iterator it = begin; it != end; it++)
|
for(Unicode::const_iterator it = begin; it != end; it++)
|
||||||
{
|
{
|
||||||
SegmentChar schar(*it);
|
schar.uniCh = *it;
|
||||||
size_t i = it - begin;
|
offset = it - begin;
|
||||||
_trie.find(it, end, schar.dag, i);
|
schar.dag.clear();
|
||||||
//DagType::iterator dagIter;
|
_trie.find(it, end, schar.dag, offset);
|
||||||
if(schar.dag.end() == schar.dag.find(i))
|
if(!isIn(schar.dag, offset))
|
||||||
{
|
{
|
||||||
schar.dag[i] = NULL;
|
schar.dag[offset] = NULL;
|
||||||
}
|
}
|
||||||
segContext.push_back(schar);
|
segContext.push_back(schar);
|
||||||
}
|
}
|
||||||
@ -139,15 +141,19 @@ namespace CppJieba
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t nextPos;
|
||||||
|
const TrieNodeInfo* p;
|
||||||
|
double val;
|
||||||
|
|
||||||
for(int i = segContext.size() - 1; i >= 0; i--)
|
for(int i = segContext.size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
segContext[i].pInfo = NULL;
|
segContext[i].pInfo = NULL;
|
||||||
segContext[i].weight = MIN_DOUBLE;
|
segContext[i].weight = MIN_DOUBLE;
|
||||||
for(DagType::const_iterator it = segContext[i].dag.begin(); it != segContext[i].dag.end(); it++)
|
for(DagType::const_iterator it = segContext[i].dag.begin(); it != segContext[i].dag.end(); it++)
|
||||||
{
|
{
|
||||||
size_t nextPos = it->first;
|
nextPos = it->first;
|
||||||
const TrieNodeInfo* p = it->second;
|
p = it->second;
|
||||||
double val = 0.0;
|
val = 0.0;
|
||||||
if(nextPos + 1 < segContext.size())
|
if(nextPos + 1 < segContext.size())
|
||||||
{
|
{
|
||||||
val += segContext[nextPos + 1].weight;
|
val += segContext[nextPos + 1].weight;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user