2 #include "../Common/Common.h"
4 #include "AlphabetManagerFactory.h"
5 #include "DasherInterfaceBase.h"
6 #include "LanguageModelling/PPMLanguageModel.h"
7 #include "LanguageModelling/WordLanguageModel.h"
8 #include "LanguageModelling/DictLanguageModel.h"
9 #include "LanguageModelling/MixtureLanguageModel.h"
11 using namespace Dasher
;
13 // Track memory leaks on Windows to the line that new'd the memory
15 #ifdef _DEBUG_MEMLEAKS
16 #define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
19 static char THIS_FILE
[] = __FILE__
;
23 CAlphabetManagerFactory::CAlphabetManagerFactory(CDasherInterfaceBase
*pInterface
, CEventHandler
*pEventHandler
, CSettingsStore
*pSettingsStore
, Dasher::CAlphIO
*pAlphIO
, CNodeCreationManager
*pNCManager
, bool bGameMode
, const std::string
&strGameModeText
) {
24 // -- put all this in a separate method
25 // TODO: Think about having 'prefered' values here, which get
26 // retrieved by DasherInterfaceBase and used to set parameters
28 // TODO: We might get a different alphabet to the one we asked for -
29 // if this is the case then the parameter value should be updated,
30 // but not in such a way that it causes everything to be rebuilt.
32 Dasher::CAlphIO::AlphInfo oAlphInfo
= pAlphIO
->GetInfo(pSettingsStore
->GetStringParameter(SP_ALPHABET_ID
));
33 m_pAlphabet
= new CAlphabet(oAlphInfo
);
35 pSettingsStore
->SetStringParameter(SP_TRAIN_FILE
, m_pAlphabet
->GetTrainingFile());
36 pSettingsStore
->SetStringParameter(SP_DEFAULT_COLOUR_ID
, m_pAlphabet
->GetPalette());
38 if(pSettingsStore
->GetLongParameter(LP_ORIENTATION
) == Dasher::Opts::AlphabetDefault
)
39 pSettingsStore
->SetLongParameter(LP_REAL_ORIENTATION
, m_pAlphabet
->GetOrientation());
42 CSymbolAlphabet
alphabet(m_pAlphabet
->GetNumberTextSymbols());
43 alphabet
.SetSpaceSymbol(m_pAlphabet
->GetSpaceSymbol()); // FIXME - is this right, or do we have to do some kind of translation?
44 alphabet
.SetAlphabetPointer(m_pAlphabet
); // Horrible hack, but ignore for now.
46 // Create an appropriate language model;
48 // FIXME - return to using enum here
50 switch (pSettingsStore
->GetLongParameter(LP_LANGUAGE_MODEL_ID
)) {
52 m_pLanguageModel
= new CPPMLanguageModel(pEventHandler
, pSettingsStore
, alphabet
);
55 m_pLanguageModel
= new CWordLanguageModel(pEventHandler
, pSettingsStore
, alphabet
);
58 m_pLanguageModel
= new CMixtureLanguageModel(pEventHandler
, pSettingsStore
, alphabet
);
61 // If there is a bogus value for the language model ID, we'll default
62 // to our trusty old PPM language model.
63 m_pLanguageModel
= new CPPMLanguageModel(pEventHandler
, pSettingsStore
, alphabet
);
67 m_iLearnContext
= m_pLanguageModel
->CreateEmptyContext();
69 m_iConversionID
= oAlphInfo
.m_iConversionID
;
71 // TODO: Tell the alphabet manager about the alphabet here, so we
72 // don't end up having to duck out to the NCM all the time
74 m_pAlphabetManager
= new CAlphabetManager(pInterface
, pNCManager
, m_pLanguageModel
, m_iLearnContext
, bGameMode
, strGameModeText
);
77 CAlphabetManagerFactory::~CAlphabetManagerFactory() {
78 m_pLanguageModel
->ReleaseContext(m_iLearnContext
);
79 delete m_pLanguageModel
;
80 delete m_pAlphabetManager
;
83 CDasherNode
*CAlphabetManagerFactory::GetRoot(CDasherNode
*pParent
, int iLower
, int iUpper
, void *pUserData
) {
84 return m_pAlphabetManager
->GetRoot(pParent
, iLower
, iUpper
, pUserData
);
87 CAlphabetManagerFactory::CTrainer::CTrainer(CLanguageModel
*pLanguageModel
) {
88 m_pLanguageModel
= pLanguageModel
;
89 m_Context
= m_pLanguageModel
->CreateEmptyContext();
92 void CAlphabetManagerFactory::CTrainer::Train(const std::vector
<symbol
> &vSymbols
) {
93 for(std::vector
<symbol
>::const_iterator
it(vSymbols
.begin()); it
!= vSymbols
.end(); ++it
)
94 m_pLanguageModel
->LearnSymbol(m_Context
, *it
);
97 CAlphabetManagerFactory::CTrainer::~CTrainer() {
98 m_pLanguageModel
->ReleaseContext(m_Context
);
101 CAlphabetManagerFactory::CTrainer
*CAlphabetManagerFactory::GetTrainer() {
102 return new CTrainer(m_pLanguageModel
);