author | mickeyl <mickeyl> | 2003-09-27 11:29:26 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-09-27 11:29:26 (UTC) |
commit | 651b6c612db4e809c506973996f2580c4158ac3a (patch) (unidiff) | |
tree | 8c8edc86e4b206dd4542a6b556ad1a319d6698ab /inputmethods/dasher/LanguageModel.cpp | |
parent | d1a11b45e805fe7771ea05944757d767c3c4c8ea (diff) | |
download | opie-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/LanguageModel.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | inputmethods/dasher/LanguageModel.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/inputmethods/dasher/LanguageModel.cpp b/inputmethods/dasher/LanguageModel.cpp new file mode 100644 index 0000000..9635273 --- a/dev/null +++ b/inputmethods/dasher/LanguageModel.cpp | |||
@@ -0,0 +1,77 @@ | |||
1 | // LanguageModel.cpp | ||
2 | // | ||
3 | ///////////////////////////////////////////////////////////////////////////// | ||
4 | // | ||
5 | // Copyright (c) 2001-2002 David Ward | ||
6 | // | ||
7 | ///////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | #include "LanguageModel.h" | ||
10 | |||
11 | using namespace Dasher; | ||
12 | using namespace std; | ||
13 | |||
14 | // I have removed the following as it doesn't seem to compile in gcc: | ||
15 | |||
16 | // using CLanguageModel::CNodeContext; | ||
17 | |||
18 | /////////////////////////////////////////////////////////////////// | ||
19 | |||
20 | CLanguageModel::CLanguageModel(CAlphabet* Alphabet, int Normalization) | ||
21 | : m_Alphabet(Alphabet), m_iNorm(Normalization) | ||
22 | { | ||
23 | m_iModelChars = m_Alphabet->GetNumberSymbols(); | ||
24 | } | ||
25 | |||
26 | |||
27 | /////////////////////////////////////////////////////////////////// | ||
28 | |||
29 | void CLanguageModel::EnterText(CNodeContext* NodeContext, string TheText) | ||
30 | { | ||
31 | vector<symbol> Symbols; | ||
32 | m_Alphabet->GetSymbols(&Symbols, &TheText, false); | ||
33 | for (unsigned int i=0; i<Symbols.size(); i++) | ||
34 | EnterSymbol((CContext*) NodeContext, (modelchar) Symbols[i]); | ||
35 | } | ||
36 | |||
37 | /////////////////////////////////////////////////////////////////// | ||
38 | |||
39 | void CLanguageModel::LearnText(CNodeContext* NodeContext, string* TheText, bool IsMore) | ||
40 | { | ||
41 | vector<symbol> Symbols; | ||
42 | |||
43 | m_Alphabet->GetSymbols(&Symbols, TheText, IsMore); | ||
44 | |||
45 | for (unsigned int i=0; i<Symbols.size(); i++) | ||
46 | LearnSymbol((CContext*) NodeContext, (modelchar) Symbols[i]); | ||
47 | } | ||
48 | |||
49 | /////////////////////////////////////////////////////////////////// | ||
50 | |||
51 | bool CLanguageModel::GetNodeProbs(CNodeContext* Context, vector<symbol> &NewSymbols, | ||
52 | vector<unsigned int> &Groups, vector<unsigned int> &Probs, double AddProb) | ||
53 | { | ||
54 | // make sure it is a valid context | ||
55 | if (Context) { | ||
56 | int s = m_Alphabet->GetNumberSymbols(); | ||
57 | NewSymbols.resize(s); | ||
58 | Groups.resize(s); | ||
59 | for (int i=0;i<s;i++) { | ||
60 | NewSymbols[i]=i; // This will be replaced by something that works out valid nodes for this context | ||
61 | Groups[i]=m_Alphabet->get_group(i); | ||
62 | } | ||
63 | GetProbs((CContext*) Context,Probs,AddProb); | ||
64 | return true; | ||
65 | } | ||
66 | return false; | ||
67 | } | ||
68 | |||
69 | int CLanguageModel::GetColour(int character) | ||
70 | { | ||
71 | std::string colour=m_Alphabet->GetColour(character); | ||
72 | if (colour!="") { | ||
73 | return atoi(colour.c_str()); | ||
74 | } else { | ||
75 | return 0; | ||
76 | } | ||
77 | } | ||