Diffstat (limited to 'inputmethods/dasher/PPMLanguageModel.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/dasher/PPMLanguageModel.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/inputmethods/dasher/PPMLanguageModel.h b/inputmethods/dasher/PPMLanguageModel.h index bd860b8..7025a0a 100644 --- a/inputmethods/dasher/PPMLanguageModel.h +++ b/inputmethods/dasher/PPMLanguageModel.h | |||
@@ -1,122 +1,123 @@ | |||
1 | // PPMLanguageModel.h | 1 | // PPMLanguageModel.h |
2 | // | 2 | // |
3 | ///////////////////////////////////////////////////////////////////////////// | 3 | ///////////////////////////////////////////////////////////////////////////// |
4 | // | 4 | // |
5 | // Copyright (c) 1999-2002 David Ward | 5 | // Copyright (c) 1999-2002 David Ward |
6 | // | 6 | // |
7 | ///////////////////////////////////////////////////////////////////////////// | 7 | ///////////////////////////////////////////////////////////////////////////// |
8 | 8 | ||
9 | #ifndef __PPMLanguageModel_h__ | 9 | #ifndef __PPMLanguageModel_h__ |
10 | #define __PPMLanguageModel_h__ | 10 | #define __PPMLanguageModel_h__ |
11 | 11 | ||
12 | #include "NoClones.h" | 12 | #include "NoClones.h" |
13 | #include "MSVC_Unannoy.h" | 13 | #include "MSVC_Unannoy.h" |
14 | #include <vector> | 14 | #include <vector> |
15 | #include <stdio.h> | 15 | #include <stdio.h> |
16 | 16 | ||
17 | #include "LanguageModel.h" | 17 | #include "LanguageModel.h" |
18 | 18 | ||
19 | static char dumpTrieStr[40000]; | 19 | // static char dumpTrieStr[40000]; |
20 | const int MAX_ORDER = 5; | 20 | const int MAX_ORDER = 5; |
21 | const int maxcont =200; | 21 | const int maxcont =200; |
22 | 22 | ||
23 | namespace Dasher {class CPPMLanguageModel;} | 23 | namespace Dasher {class CPPMLanguageModel;} |
24 | class Dasher::CPPMLanguageModel : public Dasher::CLanguageModel, private NoClones | 24 | class Dasher::CPPMLanguageModel : public Dasher::CLanguageModel, private NoClones |
25 | { | 25 | { |
26 | public: | 26 | public: |
27 | CPPMLanguageModel(CAlphabet *_alphabet, int _normalization); | 27 | CPPMLanguageModel(CAlphabet *_alphabet, int _normalization); |
28 | ~CPPMLanguageModel(); | 28 | virtual ~CPPMLanguageModel(); |
29 | 29 | ||
30 | class CPPMnode { | 30 | class CPPMnode { |
31 | public: | 31 | public: |
32 | CPPMnode* find_symbol(int sym); | 32 | CPPMnode* find_symbol(int sym); |
33 | CPPMnode* add_symbol_to_node(int sym,int *update); | 33 | CPPMnode* add_symbol_to_node(int sym,int *update); |
34 | CPPMnode* child; | 34 | CPPMnode* child; |
35 | CPPMnode* next; | 35 | CPPMnode* next; |
36 | CPPMnode* vine; | 36 | CPPMnode* vine; |
37 | short int count; | 37 | short int count; |
38 | const short int symbol; | 38 | const short int symbol; |
39 | CPPMnode(int sym); | 39 | CPPMnode(int sym); |
40 | }; | 40 | }; |
41 | 41 | ||
42 | class CPPMContext : public CContext { | 42 | class CPPMContext : public CContext { |
43 | public: | 43 | public: |
44 | CPPMContext(CPPMContext const &input) {head = input.head;order= input.order;} | 44 | CPPMContext(CPPMContext const &input) : CContext(input) |
45 | { head = input.head;order= input.order;} | ||
45 | CPPMContext(CPPMnode* _head=0, int _order=0) : head(_head),order(_order) {}; | 46 | CPPMContext(CPPMnode* _head=0, int _order=0) : head(_head),order(_order) {}; |
46 | ~CPPMContext() {}; | 47 | ~CPPMContext() {}; |
47 | void dump(); | 48 | void dump(); |
48 | CPPMnode* head; | 49 | CPPMnode* head; |
49 | int order; | 50 | int order; |
50 | }; | 51 | }; |
51 | 52 | ||
52 | void ReleaseContext(CContext*); | 53 | void ReleaseContext(CContext*); |
53 | CContext* GetRootContext(); | 54 | CContext* GetRootContext(); |
54 | inline CContext* CloneContext(CContext*); | 55 | inline CContext* CloneContext(CContext*); |
55 | void EnterSymbol(CContext* context, modelchar Symbol); | 56 | void EnterSymbol(CContext* context, modelchar Symbol); |
56 | //inline bool GetProbs(CContext*,std::vector<symbol> &newchars,std::vector<unsigned int> &groups,std::vector<unsigned int> &probs,double addprob); | 57 | //inline bool GetProbs(CContext*,std::vector<symbol> &newchars,std::vector<unsigned int> &groups,std::vector<unsigned int> &probs,double addprob); |
57 | bool GetProbs(CContext*, std::vector<unsigned int> &Probs, double AddProb); | 58 | bool GetProbs(CContext*, std::vector<unsigned int> &Probs, double AddProb); |
58 | 59 | ||
59 | void LearnSymbol(CContext* Context, modelchar Symbol); | 60 | void LearnSymbol(CContext* Context, modelchar Symbol); |
60 | void dump(); | 61 | void dump(); |
61 | 62 | ||
62 | private: | 63 | private: |
63 | CPPMContext *m_rootcontext; | 64 | CPPMContext *m_rootcontext; |
64 | CPPMnode *root; | 65 | CPPMnode *root; |
65 | void AddSymbol(CPPMContext& context,int symbol); | 66 | void AddSymbol(CPPMContext& context,int symbol); |
66 | void dumpSymbol(int symbol); | 67 | void dumpSymbol(int symbol); |
67 | void dumpString( char *str, int pos, int len ); | 68 | void dumpString( char *str, int pos, int len ); |
68 | void dumpTrie( CPPMnode *t, int d ); | 69 | void dumpTrie( CPPMnode *t, int d ); |
69 | 70 | ||
70 | 71 | ||
71 | 72 | ||
72 | }; | 73 | }; |
73 | 74 | ||
74 | //////////////////////////////////////////////////////////////////////// | 75 | //////////////////////////////////////////////////////////////////////// |
75 | // Inline functions | 76 | // Inline functions |
76 | //////////////////////////////////////////////////////////////////////// | 77 | //////////////////////////////////////////////////////////////////////// |
77 | 78 | ||
78 | //////////////////////////////////////////////////////////////////////// | 79 | //////////////////////////////////////////////////////////////////////// |
79 | 80 | ||
80 | inline CPPMLanguageModel::CPPMnode::CPPMnode(int sym) : symbol(sym) | 81 | inline CPPMLanguageModel::CPPMnode::CPPMnode(int sym) : symbol(sym) |
81 | { | 82 | { |
82 | child=next=vine=0; | 83 | child=next=vine=0; |
83 | count=1; | 84 | count=1; |
84 | } | 85 | } |
85 | 86 | ||
86 | /////////////////////////////////////////////////////////////////// | 87 | /////////////////////////////////////////////////////////////////// |
87 | 88 | ||
88 | inline void CPPMLanguageModel::CPPMContext::dump() | 89 | inline void CPPMLanguageModel::CPPMContext::dump() |
89 | // diagnostic output | 90 | // diagnostic output |
90 | { | 91 | { |
91 | // TODO uncomment this when headers sorted out | 92 | // TODO uncomment this when headers sorted out |
92 | //dchar debug[128]; | 93 | //dchar debug[128]; |
93 | //Usprintf(debug,TEXT("head %x order %d\n"),head,order); | 94 | //Usprintf(debug,TEXT("head %x order %d\n"),head,order); |
94 | //DebugOutput(debug); | 95 | //DebugOutput(debug); |
95 | } | 96 | } |
96 | 97 | ||
97 | /////////////////////////////////////////////////////////////////// | 98 | /////////////////////////////////////////////////////////////////// |
98 | 99 | ||
99 | inline CContext* CPPMLanguageModel::GetRootContext() | 100 | inline CContext* CPPMLanguageModel::GetRootContext() |
100 | { | 101 | { |
101 | CPPMContext * nc = new CPPMLanguageModel::CPPMContext(*m_rootcontext); | 102 | CPPMContext * nc = new CPPMLanguageModel::CPPMContext(*m_rootcontext); |
102 | CContext *cont=static_cast<CContext *> (nc); | 103 | CContext *cont=static_cast<CContext *> (nc); |
103 | return cont; | 104 | return cont; |
104 | } | 105 | } |
105 | 106 | ||
106 | /////////////////////////////////////////////////////////////////// | 107 | /////////////////////////////////////////////////////////////////// |
107 | 108 | ||
108 | inline CContext* CPPMLanguageModel::CloneContext(CContext *copythis) | 109 | inline CContext* CPPMLanguageModel::CloneContext(CContext *copythis) |
109 | { | 110 | { |
110 | CPPMContext *ppmcontext=static_cast<CPPMContext *> (copythis); | 111 | CPPMContext *ppmcontext=static_cast<CPPMContext *> (copythis); |
111 | CPPMContext * nc = new CPPMLanguageModel::CPPMContext(*ppmcontext); | 112 | CPPMContext * nc = new CPPMLanguageModel::CPPMContext(*ppmcontext); |
112 | return static_cast<CContext *> (nc); | 113 | return static_cast<CContext *> (nc); |
113 | } | 114 | } |
114 | 115 | ||
115 | /////////////////////////////////////////////////////////////////// | 116 | /////////////////////////////////////////////////////////////////// |
116 | 117 | ||
117 | inline void CPPMLanguageModel::ReleaseContext(CContext *release) | 118 | inline void CPPMLanguageModel::ReleaseContext(CContext *release) |
118 | { | 119 | { |
119 | delete release; | 120 | delete release; |
120 | } | 121 | } |
121 | 122 | ||
122 | #endif /* #ifndef __PPMLanguageModel_H__ */ | 123 | #endif /* #ifndef __PPMLanguageModel_H__ */ |