summaryrefslogtreecommitdiff
path: root/inputmethods/dasher/LanguageModel.cpp
blob: 963527328bd7772517354f5df1b1885025600cd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// LanguageModel.cpp
//
/////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2001-2002 David Ward
//
/////////////////////////////////////////////////////////////////////////////

#include "LanguageModel.h"

using namespace Dasher;
using namespace std;

// I have removed the following as it doesn't seem to compile in gcc:

// using CLanguageModel::CNodeContext;

///////////////////////////////////////////////////////////////////

CLanguageModel::CLanguageModel(CAlphabet* Alphabet, int Normalization)
	: m_Alphabet(Alphabet), m_iNorm(Normalization)
{
	m_iModelChars = m_Alphabet->GetNumberSymbols();
}


///////////////////////////////////////////////////////////////////

void CLanguageModel::EnterText(CNodeContext* NodeContext, string TheText)
{
	vector<symbol> Symbols;
	m_Alphabet->GetSymbols(&Symbols, &TheText, false);
	for (unsigned int i=0; i<Symbols.size(); i++)
		EnterSymbol((CContext*) NodeContext, (modelchar) Symbols[i]);
}

///////////////////////////////////////////////////////////////////

void CLanguageModel::LearnText(CNodeContext* NodeContext, string* TheText, bool IsMore)
{
	vector<symbol> Symbols;
	
	m_Alphabet->GetSymbols(&Symbols, TheText, IsMore);
	
	for (unsigned int i=0; i<Symbols.size(); i++)
		LearnSymbol((CContext*) NodeContext, (modelchar) Symbols[i]);
}

///////////////////////////////////////////////////////////////////

bool CLanguageModel::GetNodeProbs(CNodeContext* Context, vector<symbol> &NewSymbols,
		vector<unsigned int> &Groups, vector<unsigned int> &Probs, double AddProb)
{
	// make sure it is a valid context
	if (Context) {
		int s = m_Alphabet->GetNumberSymbols();
		NewSymbols.resize(s);
		Groups.resize(s);
		for (int i=0;i<s;i++) {
			NewSymbols[i]=i; // This will be replaced by something that works out valid nodes for this context
			Groups[i]=m_Alphabet->get_group(i);
		}
		GetProbs((CContext*) Context,Probs,AddProb);
		return true;
	}
	return false;
}

int CLanguageModel::GetColour(int character)
{
  std::string colour=m_Alphabet->GetColour(character);
  if (colour!="") {
    return atoi(colour.c_str());
  } else {
    return 0;
  }
}