Beispiel #1
0
unsigned CShuangpinSegmentor::_clear (unsigned from)
{
    unsigned i, j;
    _locateSegment (from, i, j);

    std::string new_pystr = m_pystr.substr (i, from-i);
    m_pystr.resize (i);
    m_nAlpha = _getNumberOfNonAlpha();

    m_segs.erase (m_segs.begin()+j, m_segs.end());

    if (m_nLastValidPos + 1 >= from) {
        m_hasInvalid = false;
    }
    
    m_updatedFrom = from;
    
    for (std::string::const_iterator it = new_pystr.begin();
         it!= new_pystr.end(); ++it) {
        unsigned tmp = _push ((*it) & 0x7f);
        if (tmp < m_updatedFrom) m_updatedFrom = tmp;
    }

    return m_updatedFrom;
}
Beispiel #2
0
unsigned CShuangpinSegmentor::deleteAt (unsigned idx, bool backward)
{
    unsigned pyIdx, segIdx;
    if (!backward) idx += 1;
    _locateSegment (idx, pyIdx, segIdx);

    m_inputBuf.erase (idx, 1);
    m_pystr.erase (idx, 1);

    std::string new_pystr = m_pystr.substr (pyIdx);
    m_pystr.resize (pyIdx);
    TSegmentVec tmp_segs (m_segs.begin()+segIdx+1, m_segs.end());
    m_segs.erase (m_segs.begin()+segIdx, m_segs.end());

    if (m_nLastValidPos + 1 < idx) {
       //del invalid ch, and do not effect current status. 
        m_pystr.insert(idx, new_pystr);
        m_segs.insert (m_segs.end(), tmp_segs.begin(), tmp_segs.end());
        return m_inputBuf.size() -1;
    } else {
        m_hasInvalid = false;
        m_nAlpha = _getNumberOfNonAlpha();
    }

    m_updatedFrom = UINT_MAX;
    std::string::const_iterator it = new_pystr.begin();
    for (; it!= new_pystr.end(); ++it) {
        unsigned tmp = _push ((*it) & 0x7f);
        if (tmp < m_updatedFrom) m_updatedFrom = tmp;
    }

    return m_updatedFrom;
}
Beispiel #3
0
unsigned CHunpinSegmentor::_clear (unsigned from)
{
    unsigned i, j;
    _locateSegment (from, i, j);
	
	
    std::string new_pystr = m_pystr.substr (i, from-i);
    m_pystr.resize (i);
    m_segs.erase (m_segs.begin()+j, m_segs.end());
	
    m_updatedFrom = _updateWith (new_pystr, from);
	
    return m_updatedFrom;
}
Beispiel #4
0
unsigned CHunpinSegmentor::insertAt (unsigned idx, unsigned ch)
{
    unsigned i, j;
    _locateSegment (idx, i, j);
	
    m_inputBuf.insert (idx, 1, ch);
    m_pystr.insert (idx, 1, ch);
	
    std::string new_pystr = m_pystr.substr (i);
    m_pystr.resize (i);
    m_segs.erase (m_segs.begin()+j, m_segs.end());
	
    m_updatedFrom = _updateWith (new_pystr);
	
    return m_updatedFrom;
}
Beispiel #5
0
unsigned CHunpinSegmentor::deleteAt (unsigned idx, bool backward)
{
    unsigned i, j;
    if (!backward) idx += 1;
    _locateSegment (idx, i, j);
	
    m_inputBuf.erase (idx, 1);
    m_pystr.erase (idx, 1);
	
    std::string new_pystr = m_pystr.substr (i);
    m_pystr.resize (i);
    m_segs.erase (m_segs.begin()+j, m_segs.end());
	
    m_updatedFrom = _updateWith (new_pystr);
	
    return m_updatedFrom;
}
Beispiel #6
0
unsigned CShuangpinSegmentor::insertAt (unsigned idx, unsigned ch)
{
    unsigned pyIdx, segIdx;
    _locateSegment (idx, pyIdx, segIdx);

    m_inputBuf.insert (idx, 1, ch);
    m_pystr.insert (idx, 1, ch);

    std::string new_pystr = m_pystr.substr (pyIdx);
    m_pystr.resize (pyIdx);
    m_segs.erase (m_segs.begin()+segIdx, m_segs.end());
    
    if (m_nLastValidPos == idx) {
        m_hasInvalid = false;
        
    } else if (m_nLastValidPos + 1 == idx) {
        m_hasInvalid = false;
        int nSize = m_pystr.size();
        if (islower(m_pystr[nSize-1])) {
            m_nLastValidPos = idx - 1;
            new_pystr.insert((size_t)0, 1, m_pystr[nSize-1]);
            m_pystr.erase(nSize-1, 1);
            m_segs.erase (m_segs.begin()+segIdx-1);
        } 
    
    } else if (m_nLastValidPos + 1 > idx) {
        m_hasInvalid = false;
        m_nLastValidPos = idx;
    }
    m_nAlpha = _getNumberOfNonAlpha();

    m_updatedFrom = UINT_MAX;
    std::string::const_iterator it = new_pystr.begin();
    for (; it!= new_pystr.end(); ++it) {
        unsigned tmp = _push ((*it) & 0x7f);
        if (tmp < m_updatedFrom) m_updatedFrom = tmp;
    }

    return m_updatedFrom;
}