Tizen 2.1 base
[platform/core/uifw/ise-engine-sunpinyin.git] / src / pinyin / hunpin_seg.h
1 // -*- mode: c++ -*-
2 /*
3  *  hunpin_seg.h
4  *  FIT
5  *
6  *  Created by cererd.long on 10-10-8.
7  *  Copyright 2010 __MyCompanyName__. All rights reserved.
8  *
9  */
10
11
12 #ifndef SUNPY_HUNPIN_SEG_H
13 #define SUNPY_HUNPIN_SEG_H
14
15
16
17
18 #include "datrie.h"
19 #include "portability.h"
20 #include "shuangpin_data.h"
21 #include "segmentor.h"
22 #include "pinyin_data.h"
23 #include <vector>
24 #include <limits.h>
25
26 class CHunpinSegmentor : public IPySegmentor
27 {
28 public:
29     CHunpinSegmentor (EShuangpinType shpType);
30
31     virtual TSegmentVec& getSegments(bool) { return m_segs; }
32
33
34     virtual const wstring& getInputBuffer() { return m_inputBuf; }
35
36     virtual const char* getSylSeps() { return "'"; }
37
38     virtual unsigned push(unsigned ch);
39     virtual unsigned pop();
40     virtual unsigned insertAt(unsigned idx, unsigned ch);
41     virtual unsigned deleteAt(unsigned idx, bool backward = true);
42     virtual unsigned clear(unsigned from = 0);
43
44     virtual unsigned updatedFrom() { return m_updatedFrom; }
45
46     bool load(const char * pyTrieFileName);
47
48     void setGetFuzzySyllablesOp(CGetFuzzySyllablesOp<CPinyinData> *op) {
49         m_pGetFuzzySyllablesOp = op; }
50
51
52
53
54 private:
55     inline unsigned _push(unsigned ch);
56     inline unsigned _clear(unsigned from);
57     inline void _addFuzzySyllables(TSegment &seg);
58     inline unsigned _updateWith(const std::string& new_pystr,
59                                 unsigned from = UINT_MAX);
60     inline void _locateSegment(unsigned idx, unsigned &strIdx, unsigned &segIdx);
61     int _encode(const char* buf, int ret);
62     int _encode(const char* buf);
63
64
65     CGetFuzzySyllablesOp<CPinyinData>  *m_pGetFuzzySyllablesOp;
66
67
68     CDATrie<short>                      m_pytrie;
69     std::string m_pystr;
70     wstring m_inputBuf;
71     TSegmentVec m_segs;
72     TSegmentVec m_fuzzy_segs;
73     TSegmentVec m_merged_segs;
74
75     unsigned m_updatedFrom;
76     static CShuangpinData s_shpData;
77 };
78
79 #endif /* SUNPY_PINYIN_SEG_H */