[dasher] Refactor Mandarin changes to CAlphabetManager into CMandarinAlphMgr subclass.
- From: Patrick Welche <pwelche src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [dasher] Refactor Mandarin changes to CAlphabetManager into CMandarinAlphMgr subclass.
- Date: Fri, 7 Aug 2009 21:02:07 +0000 (UTC)
commit 456756433dd453dd39af2c5184a90153ae09a5f0
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Fri Aug 7 18:18:32 2009 +0200
Refactor Mandarin changes to CAlphabetManager into CMandarinAlphMgr subclass.
(4-Jul-2009)
ChangeLog | 2 +
Src/DasherCore/AlphabetManager.cpp | 71 +++++++--------------------
Src/DasherCore/AlphabetManager.h | 12 +++--
Src/DasherCore/AlphabetManagerFactory.cpp | 7 ++-
Src/DasherCore/AlphabetManagerFactory.h | 2 +-
Src/DasherCore/Makefile.am | 2 +
Src/DasherCore/NodeCreationManager.cpp | 4 +-
Src/MacOSX/Dasher.xcodeproj/project.pbxproj | 10 +++-
8 files changed, 46 insertions(+), 64 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bf05023..7af9359 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,8 @@
* MacOSX build now includes Mandarin Dasher training texts,
PinYinConversionHelper.
* Move training code from CAlphabet into CTrainer.
+ * Refactor Mandarin changes to CAlphabetManager into CMandarinAlphMgr
+ subclass.
2009-08-06 Patrick Welche <prlw1 cam ac uk>
diff --git a/Src/DasherCore/AlphabetManager.cpp b/Src/DasherCore/AlphabetManager.cpp
index 7ebbf47..de4d66f 100644
--- a/Src/DasherCore/AlphabetManager.cpp
+++ b/Src/DasherCore/AlphabetManager.cpp
@@ -45,15 +45,12 @@ static char THIS_FILE[] = __FILE__;
#endif
#endif
-CAlphabetManager::CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext, int iConversionID)
+CAlphabetManager::CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext)
: CNodeManager(0), m_pLanguageModel(pLanguageModel), m_pNCManager(pNCManager) {
m_pInterface = pInterface;
m_iLearnContext = iLearnContext;
- //Added for Mandarin Dasher
- m_iConversionID = iConversionID;
-
}
CDasherNode *CAlphabetManager::GetRoot(CDasherNode *pParent, int iLower, int iUpper, void *pUserData) {
@@ -122,21 +119,7 @@ CDasherNode *CAlphabetManager::GetRoot(CDasherNode *pParent, int iLower, int iUp
pNodeUserData->iPhase = 0;
pNodeUserData->iSymbol = iSymbol;
-
-
- //Added for Mandarin Dasher
- if((m_iConversionID==2)&&(pParent)){
- CConversionManager::SConversionData *pParentConversionData = static_cast<CConversionManager::SConversionData *>(pParent->m_pUserData);
-
- pNodeUserData->iContext = m_pLanguageModel->CloneContext(pParentConversionData->iContext);
-
- }
- else if(m_iConversionID==2){
- pNodeUserData->iContext = m_pLanguageModel->CreateEmptyContext();
- }
- else
- pNodeUserData->iContext = iContext;
-
+ pNodeUserData->iContext = iContext;
pNodeUserData->pLanguageModel = m_pLanguageModel;
@@ -223,17 +206,22 @@ CDasherNode *CAlphabetManager::CreateSymbolNode(CDasherNode *pParent, symbol iSy
((*pCProb)[iMax-1] - (*pCProb)[iMin-1]);
#endif
+ return CreateSymbolNode(pParent, iSymbol, iLbnd, iHbnd, iExistingSymbol, pExistingChild);
+}
- SAlphabetData *pParentData = static_cast<SAlphabetData *>(pParent->m_pUserData);
- CDasherNode *pNewNode = NULL;
+CLanguageModel::Context CAlphabetManager::CreateSymbolContext(SAlphabetData *pParentData, symbol iSymbol)
+{
+ CLanguageModel::Context iContext = m_pLanguageModel->CloneContext(pParentData->iContext);
+ m_pLanguageModel->EnterSymbol(iContext, iSymbol); // TODO: Don't use symbols?
+ return iContext;
+}
-
- //Modified for Mandarin Dasher
+CDasherNode *CAlphabetManager::CreateSymbolNode(CDasherNode *pParent, symbol iSymbol, unsigned int iLbnd, unsigned int iHbnd, symbol iExistingSymbol, CDasherNode *pExistingChild) {
- //The following logic switch allows punctuation nodes in Mandarin to be treated in the same way as English (i.e. display and populate next round) instead of invoking a conversion node
+ SAlphabetData *pParentData = static_cast<SAlphabetData *>(pParent->m_pUserData);
+ CDasherNode *pNewNode = NULL;
- if((m_iConversionID!=2)||((m_iConversionID==2)&&(iSymbol>1288))){
- //Does not invoke conversion node
+ //Does not invoke conversion node
// TODO: Better way of specifying alternate roots
// TODO: Building with existing node
@@ -294,32 +282,10 @@ CDasherNode *CAlphabetManager::CreateSymbolNode(CDasherNode *pParent, symbol iSy
pNodeUserData->iOffset = pParentData->iOffset + 1;
pNodeUserData->iPhase = iPhase;
pNodeUserData->iSymbol = iSymbol;
+
+ pNodeUserData->iContext = CreateSymbolContext(pParentData, iSymbol);
- pNodeUserData->pLanguageModel = pParentData->pLanguageModel; // TODO: inconsistent with above?
-
-
- //Context carry-over. This code may worth looking at debug
- if(m_iConversionID==2){
- pNodeUserData->iContext = m_pLanguageModel->CloneContext(pParentData->iContext);
- }
- else{
- CLanguageModel::Context iContext;
- iContext = m_pLanguageModel->CloneContext(pParentData->iContext);
- m_pLanguageModel->EnterSymbol(iContext, iSymbol); // TODO: Don't use symbols?
-
- pNodeUserData->iContext = iContext;
- }
-
- }
- }
-
- //modified for Mandarin dasher
- else{
-
- pNewNode = m_pNCManager->GetRoot(2, pParent, iLbnd, iHbnd, &(pParentData->iOffset));
-
- static_cast<SAlphabetData *>(pNewNode->m_pUserData)->iSymbol = iSymbol;
-
+ pNodeUserData->pLanguageModel = pParentData->pLanguageModel; // TODO: inconsistent with above?
}
return pNewNode;
@@ -529,8 +495,7 @@ CDasherNode *CAlphabetManager::RebuildParent(CDasherNode *pNode) {
void CAlphabetManager::SetFlag(CDasherNode *pNode, int iFlag, bool bValue) {
switch(iFlag) {
case NF_COMMITTED:
- if(bValue && !pNode->GetFlag(NF_GAME) && m_pInterface->GetBoolParameter(BP_LM_ADAPTIVE)
- && m_iConversionID!=2)
+ if(bValue && !pNode->GetFlag(NF_GAME) && m_pInterface->GetBoolParameter(BP_LM_ADAPTIVE))
static_cast<SAlphabetData *>(pNode->m_pUserData)->pLanguageModel->LearnSymbol(m_iLearnContext, static_cast<SAlphabetData *>(pNode->m_pUserData)->iSymbol);
break;
}
diff --git a/Src/DasherCore/AlphabetManager.h b/Src/DasherCore/AlphabetManager.h
index df82dbc..e236a4f 100644
--- a/Src/DasherCore/AlphabetManager.h
+++ b/Src/DasherCore/AlphabetManager.h
@@ -44,7 +44,7 @@ namespace Dasher {
class CAlphabetManager : public CNodeManager {
public:
- CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext, int iConversionID);
+ CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext);
///
/// Does nothing - alphabet manager isn't reference counted.
@@ -100,6 +100,12 @@ namespace Dasher {
int iOffset;
};
+ protected:
+ virtual CDasherNode *CreateSymbolNode(CDasherNode *pParent, symbol iSymbol, unsigned int iLbnd, unsigned int iHbnd, symbol iExistingSymbol, CDasherNode *pExistingChild);
+ virtual CLanguageModel::Context CreateSymbolContext(SAlphabetData *pParentData, symbol iSymbol);
+
+ CLanguageModel *m_pLanguageModel;
+ CNodeCreationManager *m_pNCManager;
private:
@@ -110,12 +116,8 @@ namespace Dasher {
CDasherNode *CreateGroupNode(CDasherNode *pParent, SGroupInfo *pInfo, std::vector<unsigned int> *pCProb, unsigned int iStart, unsigned int iEnd, unsigned int iMin, unsigned int iMax);
CDasherNode *CreateSymbolNode(CDasherNode *pParent, symbol iSymbol, std::vector<unsigned int> *pCProb, unsigned int iStart, unsigned int iEnd, unsigned int iMin, unsigned int iMax, symbol iExistingSymbol, CDasherNode *pExistingChild);
- CLanguageModel *m_pLanguageModel;
- CNodeCreationManager *m_pNCManager;
CLanguageModel::Context m_iLearnContext;
CDasherInterfaceBase *m_pInterface;
- //Added for Mandarin Dasher
- int m_iConversionID;
};
/// @}
diff --git a/Src/DasherCore/AlphabetManagerFactory.cpp b/Src/DasherCore/AlphabetManagerFactory.cpp
index 83deadf..28d8c11 100644
--- a/Src/DasherCore/AlphabetManagerFactory.cpp
+++ b/Src/DasherCore/AlphabetManagerFactory.cpp
@@ -2,6 +2,7 @@
#include "../Common/Common.h"
#include "AlphabetManagerFactory.h"
+#include "MandarinAlphMgr.h"
#include "DasherInterfaceBase.h"
#include "LanguageModelling/PPMLanguageModel.h"
#include "LanguageModelling/WordLanguageModel.h"
@@ -105,7 +106,11 @@ CAlphabetManagerFactory::CAlphabetManagerFactory(CDasherInterfaceBase *pInterfac
// TODO: Tell the alphabet manager about the alphabet here, so we
// don't end up having to duck out to the NCM all the time
- m_pAlphabetManager = new CAlphabetManager(pInterface, pNCManager, m_pLanguageModel, m_iLearnContext,m_iConversionID);
+ //(ACL) Modify AlphabetManager for Mandarin Dasher
+ if (m_iConversionID == 2)
+ m_pAlphabetManager = new CMandarinAlphMgr(pInterface, pNCManager, m_pLanguageModel, m_iLearnContext);
+ else
+ m_pAlphabetManager = new CAlphabetManager(pInterface, pNCManager, m_pLanguageModel, m_iLearnContext);
}
CAlphabetManagerFactory::~CAlphabetManagerFactory() {
diff --git a/Src/DasherCore/AlphabetManagerFactory.h b/Src/DasherCore/AlphabetManagerFactory.h
index 60a65d0..f93589f 100644
--- a/Src/DasherCore/AlphabetManagerFactory.h
+++ b/Src/DasherCore/AlphabetManagerFactory.h
@@ -62,7 +62,7 @@ namespace Dasher {
CLanguageModel::Context m_iLearnContext; // Used to add data to model as it is entered
CAlphabet *m_pAlphabet; // pointer to the alphabet
CAlphabet *m_pCHAlphabet; // pointer to the Mandarin alphabet
- CTrainer *m_pTrainer;
+ CTrainer *m_pTrainer;
int m_iConversionID;
};
diff --git a/Src/DasherCore/Makefile.am b/Src/DasherCore/Makefile.am
index bd16f84..74ffecb 100644
--- a/Src/DasherCore/Makefile.am
+++ b/Src/DasherCore/Makefile.am
@@ -86,6 +86,8 @@ libdashercore_a_SOURCES = \
GnomeSettingsStore.cpp \
GnomeSettingsStore.h \
InputFilter.h \
+ MandarinAlphMgr.cpp \
+ MandarinAlphMgr.h \
MemoryLeak.cpp \
MemoryLeak.h \
ModuleManager.cpp \
diff --git a/Src/DasherCore/NodeCreationManager.cpp b/Src/DasherCore/NodeCreationManager.cpp
index f326277..b389b77 100644
--- a/Src/DasherCore/NodeCreationManager.cpp
+++ b/Src/DasherCore/NodeCreationManager.cpp
@@ -29,8 +29,6 @@ CNodeCreationManager::CNodeCreationManager(Dasher::CDasherInterfaceBase *pInterf
delete pTrainer;
- int iConversionID(m_pAlphabetManagerFactory->GetConversionID());
-
#ifndef _WIN32_WCE
m_pControlManager = new CControlManager(this);
#else
@@ -39,7 +37,7 @@ CNodeCreationManager::CNodeCreationManager(Dasher::CDasherInterfaceBase *pInterf
m_pConversionManagerFactory = new CConversionManagerFactory(pEventHandler,
pSettingsStore,
this,
- iConversionID,
+ m_pAlphabetManagerFactory->GetConversionID(),
pAlphIO,
m_pAlphabet);
}
diff --git a/Src/MacOSX/Dasher.xcodeproj/project.pbxproj b/Src/MacOSX/Dasher.xcodeproj/project.pbxproj
index ed877c4..a69b8ee 100755
--- a/Src/MacOSX/Dasher.xcodeproj/project.pbxproj
+++ b/Src/MacOSX/Dasher.xcodeproj/project.pbxproj
@@ -358,6 +358,8 @@
3306E0230FFD1CE60017324C /* PPMPYLanguageModel.h in Headers */ = {isa = PBXBuildFile; fileRef = 3306E0210FFD1CE60017324C /* PPMPYLanguageModel.h */; };
3306E1F70FFE6CAD0017324C /* Trainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3306E1F50FFE6CAD0017324C /* Trainer.cpp */; };
3306E1F80FFE6CAD0017324C /* Trainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3306E1F60FFE6CAD0017324C /* Trainer.h */; };
+ 3306E33D0FFFB9880017324C /* MandarinAlphMgr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3306E33B0FFFB9880017324C /* MandarinAlphMgr.cpp */; };
+ 3306E33E0FFFB9880017324C /* MandarinAlphMgr.h in Headers */ = {isa = PBXBuildFile; fileRef = 3306E33C0FFFB9880017324C /* MandarinAlphMgr.h */; };
335DB0FB100B332C006DB155 /* alphabet.spyDict.xml in Resources */ = {isa = PBXBuildFile; fileRef = 335DB0FA100B332C006DB155 /* alphabet.spyDict.xml */; };
335DB101100B3358006DB155 /* training_spyDict.txt in Resources */ = {isa = PBXBuildFile; fileRef = 335DB100100B3358006DB155 /* training_spyDict.txt */; };
335DB122100B3606006DB155 /* PinYinConversionHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1948BE760C226CFD001DFA32 /* PinYinConversionHelper.cpp */; };
@@ -776,6 +778,8 @@
3306E0210FFD1CE60017324C /* PPMPYLanguageModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PPMPYLanguageModel.h; sourceTree = "<group>"; };
3306E1F50FFE6CAD0017324C /* Trainer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Trainer.cpp; sourceTree = "<group>"; };
3306E1F60FFE6CAD0017324C /* Trainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Trainer.h; sourceTree = "<group>"; };
+ 3306E33B0FFFB9880017324C /* MandarinAlphMgr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MandarinAlphMgr.cpp; sourceTree = "<group>"; };
+ 3306E33C0FFFB9880017324C /* MandarinAlphMgr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MandarinAlphMgr.h; sourceTree = "<group>"; };
335DB0FA100B332C006DB155 /* alphabet.spyDict.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = alphabet.spyDict.xml; sourceTree = "<group>"; };
335DB100100B3358006DB155 /* training_spyDict.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = training_spyDict.txt; sourceTree = "<group>"; };
33ABFEC40FC379EA00EA2BA5 /* ButtonMultiPress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ButtonMultiPress.cpp; sourceTree = "<group>"; };
@@ -1006,6 +1010,8 @@
1948BE6B0C226CFD001DFA32 /* ModuleManager.cpp */,
1948BE6C0C226CFD001DFA32 /* ModuleManager.h */,
1948BE6D0C226CFD001DFA32 /* NodeCreationManager.cpp */,
+ 3306E33B0FFFB9880017324C /* MandarinAlphMgr.cpp */,
+ 3306E33C0FFFB9880017324C /* MandarinAlphMgr.h */,
1948BE6E0C226CFD001DFA32 /* NodeCreationManager.h */,
1948BE6F0C226CFD001DFA32 /* NodeManager.h */,
1948BE710C226CFD001DFA32 /* OneButtonFilter.cpp */,
@@ -1507,6 +1513,7 @@
33FC933A0FEFA2C900A9F08D /* TwoPushDynamicFilter.h in Headers */,
3306E0230FFD1CE60017324C /* PPMPYLanguageModel.h in Headers */,
3306E1F80FFE6CAD0017324C /* Trainer.h in Headers */,
+ 3306E33E0FFFB9880017324C /* MandarinAlphMgr.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1854,8 +1861,9 @@
33FC93390FEFA2C900A9F08D /* TwoPushDynamicFilter.cpp in Sources */,
33FC93430FEFA2FB00A9F08D /* FrameRate.cpp in Sources */,
3306E0220FFD1CE60017324C /* PPMPYLanguageModel.cpp in Sources */,
- 335DB122100B3606006DB155 /* PinYinConversionHelper.cpp in Sources */,
3306E1F70FFE6CAD0017324C /* Trainer.cpp in Sources */,
+ 3306E33D0FFFB9880017324C /* MandarinAlphMgr.cpp in Sources */,
+ 335DB122100B3606006DB155 /* PinYinConversionHelper.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]