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