[dasher] whitespace
- From: Patrick Welche <pwelche src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [dasher] whitespace
- Date: Sat, 15 Aug 2009 14:24:03 +0000 (UTC)
commit cbc77ff893a9608f433bfb687bf53f3586289175
Author: Patrick Welche <prlw1 cam ac uk>
Date: Tue Aug 11 19:47:03 2009 +0200
whitespace
Src/DasherCore/AlphabetManager.cpp | 111 ++++----
Src/DasherCore/AlternatingDirectMode.cpp | 16 +-
Src/DasherCore/ConversionHelper.cpp | 112 ++++----
Src/DasherCore/ConversionManager.cpp | 42 ++--
Src/DasherCore/ConversionManagerFactory.cpp | 2 +-
Src/DasherCore/ConversionManagerFactory.h | 4 +-
Src/DasherCore/DasherInterfaceBase.cpp | 104 ++++----
.../LanguageModelling/CTWLanguageModel.cpp | 316 ++++++++++----------
Src/DasherCore/MandarinAlphMgr.cpp | 12 +-
Src/DasherCore/OneButtonFilter.cpp | 10 +-
10 files changed, 363 insertions(+), 366 deletions(-)
---
diff --git a/Src/DasherCore/AlphabetManager.cpp b/Src/DasherCore/AlphabetManager.cpp
index 33a48a4..56785ee 100644
--- a/Src/DasherCore/AlphabetManager.cpp
+++ b/Src/DasherCore/AlphabetManager.cpp
@@ -15,7 +15,7 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with Dasher; if not, write to the Free Software
+// along with Dasher; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../Common/Common.h"
@@ -45,7 +45,7 @@ static char THIS_FILE[] = __FILE__;
#endif
#endif
-CAlphabetManager::CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext)
+CAlphabetManager::CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext)
: CNodeManager(0), m_pLanguageModel(pLanguageModel), m_pNCManager(pNCManager) {
m_pInterface = pInterface;
@@ -62,7 +62,7 @@ CDasherNode *CAlphabetManager::GetRoot(CDasherNode *pParent, int iLower, int iUp
int iSymbol;
int iOffset;
int iColour;
-
+
std::string strContext;
CLanguageModel::Context iContext;
@@ -87,7 +87,7 @@ CDasherNode *CAlphabetManager::GetRoot(CDasherNode *pParent, int iLower, int iUp
}
else {
// Create a root node
-
+
if(pUserData)
iOffset = static_cast<SRootData *>(pUserData)->iOffset;
else
@@ -99,7 +99,7 @@ CDasherNode *CAlphabetManager::GetRoot(CDasherNode *pParent, int iLower, int iUp
}
// FIXME - Make this a CDasherComponent
-
+
// Stuff which could in principle be done in the symbol node creation routine
CDasherNode::SDisplayInfo *pDisplayInfo = new CDasherNode::SDisplayInfo;
@@ -126,12 +126,12 @@ CDasherNode *CAlphabetManager::GetRoot(CDasherNode *pParent, int iLower, int iUp
pNewNode->SetFlag(NF_SEEN, true);
-
+
// if(m_bGameMode) {
// pNodeUserData->iGameOffset = -1;
pNewNode->SetFlag(NF_GAME, true);
// }
-
+
return pNewNode;
}
@@ -142,23 +142,23 @@ void CAlphabetManager::PopulateChildren( CDasherNode *pNode ) {
CDasherNode *CAlphabetManager::CreateGroupNode(CDasherNode *pParent, SGroupInfo *pInfo, std::vector<unsigned int> *pCProb, unsigned int iStart, unsigned int iEnd, unsigned int iMin, unsigned int iMax) {
#ifdef WIN32
- unsigned int iLbnd = (((*pCProb)[iStart-1] - (*pCProb)[iMin-1]) *
+ unsigned int iLbnd = (((*pCProb)[iStart-1] - (*pCProb)[iMin-1]) *
(unsigned __int64)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
((*pCProb)[iMax-1] - (*pCProb)[iMin-1]);
- unsigned int iHbnd = (((*pCProb)[iEnd-1] - (*pCProb)[iMin-1]) *
- (unsigned __int64)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
+ unsigned int iHbnd = (((*pCProb)[iEnd-1] - (*pCProb)[iMin-1]) *
+ (unsigned __int64)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
((*pCProb)[iMax-1] - (*pCProb)[iMin-1]);
#else
- unsigned int iLbnd = (((*pCProb)[iStart-1] - (*pCProb)[iMin-1]) *
+ unsigned int iLbnd = (((*pCProb)[iStart-1] - (*pCProb)[iMin-1]) *
(unsigned long long int)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
((*pCProb)[iMax-1] - (*pCProb)[iMin-1]);
- unsigned int iHbnd = (((*pCProb)[iEnd-1] - (*pCProb)[iMin-1]) *
- (unsigned long long int)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
+ unsigned int iHbnd = (((*pCProb)[iEnd-1] - (*pCProb)[iMin-1]) *
+ (unsigned long long int)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
((*pCProb)[iMax-1] - (*pCProb)[iMin-1]);
#endif
SAlphabetData *pParentData = static_cast<SAlphabetData *>(pParent->m_pUserData);
-
+
// TODO: More sensible structure in group data to map directly to this
CDasherNode::SDisplayInfo *pDisplayInfo = new CDasherNode::SDisplayInfo;
pDisplayInfo->iColour = pInfo->iColour;
@@ -191,18 +191,18 @@ CDasherNode *CAlphabetManager::CreateSymbolNode(CDasherNode *pParent, symbol iSy
//std::cout << "isymbol: "<<iSymbol << " " << m_pNCManager->GetStartConversionSymbol() << std::endl;
#ifdef WIN32
- unsigned int iLbnd = (((*pCProb)[iStart-1] - (*pCProb)[iMin-1]) *
- (unsigned __int64)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
+ unsigned int iLbnd = (((*pCProb)[iStart-1] - (*pCProb)[iMin-1]) *
+ (unsigned __int64)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
((*pCProb)[iMax-1] - (*pCProb)[iMin-1]);
- unsigned int iHbnd = (((*pCProb)[iEnd-1] - (*pCProb)[iMin-1]) *
- (unsigned __int64)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
+ unsigned int iHbnd = (((*pCProb)[iEnd-1] - (*pCProb)[iMin-1]) *
+ (unsigned __int64)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
((*pCProb)[iMax-1] - (*pCProb)[iMin-1]);
#else
- unsigned int iLbnd = (((*pCProb)[iStart-1] - (*pCProb)[iMin-1]) *
- (unsigned long long int)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
+ unsigned int iLbnd = (((*pCProb)[iStart-1] - (*pCProb)[iMin-1]) *
+ (unsigned long long int)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
((*pCProb)[iMax-1] - (*pCProb)[iMin-1]);
- unsigned int iHbnd = (((*pCProb)[iEnd-1] - (*pCProb)[iMin-1]) *
- (unsigned long long int)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
+ unsigned int iHbnd = (((*pCProb)[iEnd-1] - (*pCProb)[iMin-1]) *
+ (unsigned long long int)(m_pNCManager->GetLongParameter(LP_NORMALIZATION))) /
((*pCProb)[iMax-1] - (*pCProb)[iMin-1]);
#endif
@@ -214,7 +214,7 @@ CLanguageModel::Context CAlphabetManager::CreateSymbolContext(SAlphabetData *pPa
CLanguageModel::Context iContext = m_pLanguageModel->CloneContext(pParentData->iContext);
m_pLanguageModel->EnterSymbol(iContext, iSymbol); // TODO: Don't use symbols?
return iContext;
-}
+}
CDasherNode *CAlphabetManager::CreateSymbolNode(CDasherNode *pParent, symbol iSymbol, unsigned int iLbnd, unsigned int iHbnd, symbol iExistingSymbol, CDasherNode *pExistingChild) {
@@ -229,14 +229,14 @@ CDasherNode *CAlphabetManager::CreateSymbolNode(CDasherNode *pParent, symbol iSy
pNewNode = pExistingChild;
pNewNode->SetRange(iLbnd, iHbnd);
pNewNode->SetParent(pParent);
-
+
DASHER_ASSERT(static_cast<SAlphabetData *>(pExistingChild->m_pUserData)->iOffset == pParentData->iOffset + 1);
-
+
}
// TODO: Need to fix fact that this is created even when control mode is switched off
else if(iSymbol == m_pNCManager->GetControlSymbol()) {
- pNewNode = m_pNCManager->GetRoot(1, pParent, iLbnd, iHbnd, &(pParentData->iOffset));
-
+ pNewNode = m_pNCManager->GetRoot(1, pParent, iLbnd, iHbnd, &(pParentData->iOffset));
+
// For now, just hack it so we get a normal root node here
if(!pNewNode) {
pNewNode = m_pNCManager->GetRoot(0, pParent, iLbnd, iHbnd, NULL);
@@ -244,50 +244,47 @@ CDasherNode *CAlphabetManager::CreateSymbolNode(CDasherNode *pParent, symbol iSy
}
else if(iSymbol == m_pNCManager->GetStartConversionSymbol()) {
// else if(iSymbol == m_pNCManager->GetSpaceSymbol()) {
-
+
// TODO: Need to consider the case where there is no compile-time support for this
pNewNode = m_pNCManager->GetRoot(2, pParent, iLbnd, iHbnd, &(pParentData->iOffset));
- }
+ }
else {
int iPhase = (pParentData->iPhase + 1) % 2;
int iColour = m_pNCManager->GetColour(iSymbol, iPhase);
-
+
// TODO: Exceptions / error handling in general
-
+
CDasherNode::SDisplayInfo *pDisplayInfo = new CDasherNode::SDisplayInfo;
pDisplayInfo->iColour = iColour;
pDisplayInfo->bShove = true;
pDisplayInfo->bVisible = true;
pDisplayInfo->strDisplayText = m_pNCManager->GetAlphabet()->GetDisplayText(iSymbol);
-
-
-
+
pNewNode = new CDasherNode(pParent, iLbnd, iHbnd, pDisplayInfo);
-
-
+
// std::stringstream ssLabel;
// ssLabel << m_pNCManager->GetAlphabet()->GetDisplayText(iSymbol) << ": " << pNewNode;
-
+
// pDisplayInfo->strDisplayText = ssLabel.str();
-
-
+
+
pNewNode->m_pNodeManager = this;
-
+
pNewNode->m_iNumSymbols = 1;
-
+
SAlphabetData *pNodeUserData = new SAlphabetData;
pNewNode->m_pUserData = pNodeUserData;
-
+
pNodeUserData->iOffset = pParentData->iOffset + 1;
pNodeUserData->iPhase = iPhase;
pNodeUserData->iSymbol = iSymbol;
-
- pNodeUserData->iContext = CreateSymbolContext(pParentData, iSymbol);
-
- pNodeUserData->pLanguageModel = pParentData->pLanguageModel; // TODO: inconsistent with above?
+
+ pNodeUserData->iContext = CreateSymbolContext(pParentData, iSymbol);
+
+ pNodeUserData->pLanguageModel = pParentData->pLanguageModel; // TODO: inconsistent with above?
}
-
+
return pNewNode;
}
@@ -358,17 +355,17 @@ void CAlphabetManager::PopulateChildrenWithSymbol( CDasherNode *pNode, int iExis
// FIXME: this has to change for history stuff and Japanese dasher
std::vector < symbol > newchars; // place to put this list of characters
std::vector < unsigned int >cum; // for the probability list
-
+
// TODO: Need to fix up relation to language model here (use one from node, not global).
m_pNCManager->GetProbs(pParentUserData->iContext, newchars, cum, m_pNCManager->GetLongParameter(LP_NORMALIZATION));
int iChildCount = newchars.size();
-
+
// work out cumulative probs in place
for(int i = 1; i < iChildCount; i++) {
cum[i] += cum[i - 1];
}
- RecursiveIterateGroup(pNode, m_pNCManager->GetAlphabet()->m_pBaseGroup, &newchars,
+ RecursiveIterateGroup(pNode, m_pNCManager->GetAlphabet()->m_pBaseGroup, &newchars,
&cum, 1, iChildCount, iExistingSymbol, pExistingChild);
}
@@ -440,7 +437,7 @@ CDasherNode *CAlphabetManager::RebuildParent(CDasherNode *pNode) {
pDisplayInfo->bShove = true;
pDisplayInfo->bVisible = true;
pDisplayInfo->strDisplayText = "";
-
+
pNewNode = new CDasherNode(NULL, 0, 0, pDisplayInfo);
}
else {
@@ -457,7 +454,7 @@ CDasherNode *CAlphabetManager::RebuildParent(CDasherNode *pNode) {
iNewPhase = ((iOldPhase + 2 - 1) % 2);
int iColour(m_pNCManager->GetColour(iNewSymbol, iNewPhase));
-
+
CDasherNode::SDisplayInfo *pDisplayInfo = new CDasherNode::SDisplayInfo;
pDisplayInfo->iColour = iColour;
pDisplayInfo->bShove = true;
@@ -469,7 +466,7 @@ CDasherNode *CAlphabetManager::RebuildParent(CDasherNode *pNode) {
}
// TODO: Some of this context stuff could be consolidated
-
+
pNewNode->m_pNodeManager = this;
pNewNode->SetFlag(NF_SEEN, true);
@@ -484,7 +481,7 @@ CDasherNode *CAlphabetManager::RebuildParent(CDasherNode *pNode) {
PopulateChildrenWithSymbol(pNewNode, static_cast<SAlphabetData *>(pNode->m_pUserData)->iSymbol, pNode);
-
+
// std::cout << "**" << std::endl;
return pNewNode;
@@ -508,13 +505,13 @@ void CAlphabetManager::BuildContext(std::string &strContext, bool bRoot, CLangua
std::vector<symbol> vContextSymbols;
m_pNCManager->GetAlphabet()->GetSymbols(vContextSymbols, strContext);
-
+
oContext = m_pLanguageModel->CreateEmptyContext();
-
+
for(std::vector<symbol>::iterator it(vContextSymbols.begin()); it != vContextSymbols.end(); ++it)
if(*it != 0)
m_pLanguageModel->EnterSymbol(oContext, *it);
-
+
if((vContextSymbols.size() == 0) || bRoot)
iSymbol = 0;
else
diff --git a/Src/DasherCore/AlternatingDirectMode.cpp b/Src/DasherCore/AlternatingDirectMode.cpp
index 1e57622..b902265 100644
--- a/Src/DasherCore/AlternatingDirectMode.cpp
+++ b/Src/DasherCore/AlternatingDirectMode.cpp
@@ -51,20 +51,20 @@ void CAlternatingDirectMode::SetupBoxes()
m_pBoxes[2].iTop = 0;
m_pBoxes[2].iBottom = 3096;
m_pBoxes[3].iTop = 1000;
- m_pBoxes[3].iBottom = 4096;
+ m_pBoxes[3].iBottom = 4096;
- m_pBoxes[0].iDisplayTop = m_pBoxes[0].iTop;
+ m_pBoxes[0].iDisplayTop = m_pBoxes[0].iTop;
m_pBoxes[0].iDisplayBottom = m_pBoxes[0].iBottom;
- m_pBoxes[1].iDisplayTop = m_pBoxes[1].iTop;
+ m_pBoxes[1].iDisplayTop = m_pBoxes[1].iTop;
m_pBoxes[1].iDisplayBottom = m_pBoxes[1].iBottom;
- m_pBoxes[2].iDisplayTop = m_pBoxes[2].iTop;
+ m_pBoxes[2].iDisplayTop = m_pBoxes[2].iTop;
m_pBoxes[2].iDisplayBottom = m_pBoxes[2].iBottom;
- m_pBoxes[3].iDisplayTop = m_pBoxes[3].iTop;
+ m_pBoxes[3].iDisplayTop = m_pBoxes[3].iTop;
m_pBoxes[3].iDisplayBottom = m_pBoxes[3].iBottom;
m_pBoxes[m_iNumBoxes-1].iDisplayTop = 0;
m_pBoxes[m_iNumBoxes-1].iDisplayBottom = iDasherY;
-
+
m_pBoxes[m_iNumBoxes-1].iTop = int(- iDasherY / 2);
m_pBoxes[m_iNumBoxes-1].iBottom = int(iDasherY * 1.5);
@@ -88,7 +88,7 @@ bool CAlternatingDirectMode::DecorateView(CDasherView *pView) {
m_bDecorationChanged = false;
return bRV;
}
-
+
void CAlternatingDirectMode::DirectKeyDown(int iTime, int iId, CDasherView *pView, CDasherModel *pModel, CUserLogBase *pUserLog) {
@@ -99,7 +99,7 @@ void CAlternatingDirectMode::DirectKeyDown(int iTime, int iId, CDasherView *pVie
else
pModel->ScheduleZoom((m_pBoxes[0].iBottom - m_pBoxes[0].iTop)/2, (m_pBoxes[0].iBottom + m_pBoxes[0].iTop)/2);
m_iLastBox = 1;
- break;
+ break;
case 3:
case 4:
if(m_iLastBox == 2)
diff --git a/Src/DasherCore/ConversionHelper.cpp b/Src/DasherCore/ConversionHelper.cpp
index 9ad6324..41eb624 100644
--- a/Src/DasherCore/ConversionHelper.cpp
+++ b/Src/DasherCore/ConversionHelper.cpp
@@ -15,12 +15,12 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with Dasher; if not, write to the Free Software
+// along with Dasher; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
+#endif
#include "ConversionHelper.h"
#include "Event.h"
@@ -58,10 +58,10 @@ CDasherNode *CConversionHelper::GetRoot(CDasherNode *pParent, int iLower, int iU
SConversionData *pNodeUserData = static_cast<SConversionData *>(pNewNode->m_pUserData);
pNodeUserData->pLanguageModel = m_pLanguageModel;
-
- CAlphabetManager::SAlphabetData *pParentAlphabetData = static_cast<CAlphabetManager::SAlphabetData *>(pParent->m_pUserData);
+
+ CAlphabetManager::SAlphabetData *pParentAlphabetData = static_cast<CAlphabetManager::SAlphabetData *>(pParent->m_pUserData);
if((pParent->m_pNodeManager->GetID()==0)&&(pParentAlphabetData->iContext)){
- pNodeUserData->iContext=m_pLanguageModel->CloneContext(pParentAlphabetData->iContext);
+ pNodeUserData->iContext=m_pLanguageModel->CloneContext(pParentAlphabetData->iContext);
}
else{
CLanguageModel::Context iContext;
@@ -122,11 +122,11 @@ void CConversionHelper::AssignChildSizes(SCENode **pNode, CLanguageModel::Contex
// imagine:
//
// 1. Probabilities provided directly with translation? Maybe hard
- // to represent in the lattice itself.
+ // to represent in the lattice itself.
//
// 2. Full n-gram language model provided - in general assign
// probabilities to paths through the lattice
- //
+ //
// 3. Ordered results, but no probabilities - using a power law
// rule or the like.
//
@@ -137,13 +137,13 @@ void CConversionHelper::AssignChildSizes(SCENode **pNode, CLanguageModel::Contex
// Things to be thought out:
// - How to deal with contexts - backtrace at time of call or stored in node?
// - Sharing of language model infrastructure?
-
-
+
+
// Lookup scores for each of the children
-
+
// TODO: Reimplement -----
-
+
// for(int i(0); i < pCurrentSCEChild->IsHeadAndCandNum; ++i){
// score[i] = CalculateScore(pNode, i);
// total += score[i];
@@ -151,15 +151,15 @@ void CConversionHelper::AssignChildSizes(SCENode **pNode, CLanguageModel::Contex
// if (score[i]>score[i-1])
// max = score[i];
// }
-
+
// -----
-
+
// Use the scores to calculate the size of the nodes
-
-
+
+
iNChildren = 0;
SCENode *pChild(*pNode);
-
+
while(pChild) {
pChild = pChild->GetNext();
++iNChildren;
@@ -168,7 +168,7 @@ void CConversionHelper::AssignChildSizes(SCENode **pNode, CLanguageModel::Contex
// std::cout<<"iNChildren: "<<iNChildren<<std::endl;
AssignSizes(pNode, context, m_pNCManager->GetLongParameter(LP_NORMALIZATION), m_pNCManager->GetLongParameter(LP_UNIFORM), iNChildren);
-
+
}
void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
@@ -180,7 +180,7 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
// Do the conversion and build the tree (lattice) if it hasn't been
// done already.
//
-
+
if(pCurrentDataNode->bisRoot) {
BuildTree(pNode);
@@ -189,7 +189,7 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
SCENode *pCurrentSCEChild;
if(pCurrentDataNode->pSCENode){
-
+
// RecursiveDumpTree(pCurrentDataNode->pSCENode, 1);
pCurrentSCEChild = pCurrentDataNode->pSCENode->GetChild();
@@ -200,13 +200,13 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
//else
pCurrentSCEChild = 0;
}
-
+
if(pCurrentSCEChild) {
// std::cout<<"Populating character nodes!"<<std::endl;
// std::cout << "Current SCE Child: " << pCurrentSCEChild << std::endl;
// TODO: Reimplement (in subclass) -----
-
+
// if(m_iHZCount>1)
// if(!m_bPhrasesProcessed[pCurrentSCEChild->AcCharCount-1])
// if(pCurrentSCEChild->AcCharCount<m_iHZCount)
@@ -215,17 +215,17 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
// -----
//int *iSize;
-
+
// iSize = new int[pCurrentSCEChild->IsHeadAndCandNum];
-
-
+
+
AssignChildSizes(&pCurrentSCEChild, pCurrentDataNode->iContext, pCurrentSCEChild->IsHeadAndCandNum);
int iIdx(0);
int iCum(0);
-
+
// int parentClr = pNode->Colour();
// TODO: Fixme
int parentClr = 0;
@@ -240,28 +240,28 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
//m_pNCManager->GetLongParameter(LP_NORMALIZATION));//
iCum = iHbnd;
-
+
// TODO: Parameters here are placeholders - need to figure out
// what's right
-
+
CDasherNode::SDisplayInfo *pDisplayInfo = new CDasherNode::SDisplayInfo;
pDisplayInfo->iColour = AssignColour(parentClr, pCurrentSCEChild, iIdx);
pDisplayInfo->bShove = true;
pDisplayInfo->bVisible = true;
-
+
// std::cout << "#" << pCurrentSCEChild->pszConversion << "#" << std::endl;
pDisplayInfo->strDisplayText = pCurrentSCEChild->pszConversion;
-
+
pNewNode = new CDasherNode(pNode, iLbnd, iHbnd, pDisplayInfo);
-
+
// TODO: Reimplement ----
// FIXME - handle context properly
// pNewNode->SetContext(m_pLanguageModel->CreateEmptyContext());
// -----
-
+
pNewNode->m_pNodeManager = this;
pNewNode->m_pNodeManager->Ref();
@@ -277,13 +277,13 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
if(pCurrentSCEChild ->Symbol !=-1)
pNodeUserData->pLanguageModel->EnterSymbol(iContext, pCurrentSCEChild->Symbol); // TODO: Don't use symbols?
-
-
+
+
pNodeUserData->iContext = iContext;
}
-
+
pNewNode->m_pUserData = pNodeUserData;
-
+
pNode->Children().push_back(pNewNode);
pCurrentSCEChild = pCurrentSCEChild->GetNext();
@@ -293,20 +293,20 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
}
else {//End of conversion -> default to alphabet
-
+
//Phil//
// TODO: Placeholder algorithm here
// TODO: Add an 'end of conversion' node?
int iLbnd(0);
- int iHbnd(m_pNCManager->GetLongParameter(LP_NORMALIZATION));
-
+ int iHbnd(m_pNCManager->GetLongParameter(LP_NORMALIZATION));
+
CAlphabetManager::SRootData oRootData;
oRootData.szContext = NULL;
oRootData.iOffset = pCurrentDataNode->iOffset;
-
+
pNewNode = m_pNCManager->GetRoot(0, pNode, iLbnd, iHbnd, &oRootData);
pNewNode->SetFlag(NF_SEEN, false);
-
+
pNode->Children().push_back(pNewNode);
// pNode->SetHasAllChildren(false);
//}
@@ -315,22 +315,22 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
std::cout<<"DOES IT EVER COME TO HERE?"<<std::endl;
int iLbnd(0);
- int iHbnd(m_pNCManager->GetLongParameter(LP_NORMALIZATION));
+ int iHbnd(m_pNCManager->GetLongParameter(LP_NORMALIZATION));
CDasherNode::SDisplayInfo *pDisplayInfo = new CDasherNode::SDisplayInfo;
pDisplayInfo->iColour = AssignColour(0, pCurrentSCEChild, 0);
pDisplayInfo->bShove = true;
pDisplayInfo->bVisible = true;
pDisplayInfo->strDisplayText = "";
-
+
pNewNode = new CDasherNode(pNode, iLbnd, iHbnd, pDisplayInfo);
-
+
// TODO: Reimplement ----
// FIXME - handle context properly
// pNewNode->SetContext(m_pLanguageModel->CreateEmptyContext());
// -----
-
+
pNewNode->m_pNodeManager = this;
pNewNode->m_pNodeManager->Ref();
@@ -339,11 +339,11 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
pNodeUserData->pSCENode = NULL;
pNodeUserData->pLanguageModel = pCurrentDataNode->pLanguageModel;
pNodeUserData->iOffset = pCurrentDataNode->iOffset + 1;
-
+
pNewNode->m_pUserData = pNodeUserData;
pNewNode->SetFlag(NF_SEEN, false);
-
+
pNode->Children().push_back(pNewNode);
}
*/
@@ -352,7 +352,7 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
void CConversionHelper::BuildTree(CDasherNode *pRoot) {
- std::string strCurrentString;
+ std::string strCurrentString;
//Find the pinyin (roman) text (stored in Display text) of the previous alphabet node
@@ -360,20 +360,20 @@ void CConversionHelper::BuildTree(CDasherNode *pRoot) {
//Get pinyin string (to translate) from 'Display Text' in the alphabet file (refer to alphabet.spyDict.xml)
strCurrentString = m_pAlphabet->GetDisplayText(pRootAlphabetData->iSymbol);
-
+
SCENode *pStartTemp;
- Convert(strCurrentString, &pStartTemp);
-
+ Convert(strCurrentString, &pStartTemp);
+
SConversionData *pRootConversionData = static_cast<CConversionHelper::SConversionData *>(pRoot->m_pUserData);
-
+
if(!(pRootConversionData->bisRoot))
std::cout<<"ERROR IN BUILD TREE"<<std::endl;
//Store all conversion trees(SCENode trees) in the pUserData->pSCENode of each Conversion Root
-
+
else{
pRootConversionData->pSCENode = pStartTemp;
- }
+ }
}
void CConversionHelper::SetFlag(CDasherNode *pNode, int iFlag, bool bValue) {
@@ -382,14 +382,14 @@ void CConversionHelper::SetFlag(CDasherNode *pNode, int iFlag, bool bValue) {
if(bValue){
CLanguageModel * pLan = static_cast<SConversionData *>(pNode->m_pUserData)->pLanguageModel;
- SCENode * pSCENode = static_cast<SConversionData *>(pNode->m_pUserData)->pSCENode;
+ SCENode * pSCENode = static_cast<SConversionData *>(pNode->m_pUserData)->pSCENode;
if(!pSCENode)
return;
symbol s =pSCENode ->Symbol;
-
-
+
+
if(s!=-1)
pLan->LearnSymbol(m_iLearnContext, s);
}
diff --git a/Src/DasherCore/ConversionManager.cpp b/Src/DasherCore/ConversionManager.cpp
index 5b3b6f0..8d757b9 100644
--- a/Src/DasherCore/ConversionManager.cpp
+++ b/Src/DasherCore/ConversionManager.cpp
@@ -15,12 +15,12 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with Dasher; if not, write to the Free Software
+// along with Dasher; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
+#endif
#include "ConversionManager.h"
#include "Event.h"
@@ -39,7 +39,7 @@
using namespace Dasher;
-CConversionManager::CConversionManager(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet)
+CConversionManager::CConversionManager(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet)
: CNodeManager(2) {
m_pNCManager = pNCManager;
@@ -47,7 +47,7 @@ CConversionManager::CConversionManager(CNodeCreationManager *pNCManager, CAlphab
m_iRefCount = 1;
- //Testing for alphabet details, delete if needed:
+ //Testing for alphabet details, delete if needed:
/*
int alphSize = pNCManager->GetAlphabet()->GetNumberSymbols();
std::cout<<"Alphabet size: "<<alphSize<<std::endl;
@@ -60,7 +60,7 @@ CDasherNode *CConversionManager::GetRoot(CDasherNode *pParent, int iLower, int i
CDasherNode *pNewNode;
int iOffset = *(static_cast<int *>(pUserData));
-
+
// TODO: Parameters here are placeholders - need to figure out what's right
CDasherNode::SDisplayInfo *pDisplayInfo = new CDasherNode::SDisplayInfo;
@@ -68,9 +68,9 @@ CDasherNode *CConversionManager::GetRoot(CDasherNode *pParent, int iLower, int i
pDisplayInfo->bShove = true;
pDisplayInfo->bVisible = true;
pDisplayInfo->strDisplayText = ""; // TODO: Hard coded value, needs i18n
-
+
pNewNode = new CDasherNode(pParent, iLower, iUpper, pDisplayInfo);
-
+
// FIXME - handle context properly
// TODO: Reimplemnt -----
// pNewNode->SetContext(m_pLanguageModel->CreateEmptyContext());
@@ -86,7 +86,7 @@ CDasherNode *CConversionManager::GetRoot(CDasherNode *pParent, int iLower, int i
pNodeUserData->iOffset = iOffset + 1;
pNodeUserData->pLanguageModel = NULL;
-
+
pNodeUserData->pSCENode = 0;
return pNewNode;
@@ -104,8 +104,8 @@ void CConversionManager::PopulateChildren( CDasherNode *pNode ) {
// user should have been warned here.
//
int iLbnd(0);
- int iHbnd(m_pNCManager->GetLongParameter(LP_NORMALIZATION));
-
+ int iHbnd(m_pNCManager->GetLongParameter(LP_NORMALIZATION));
+
CAlphabetManager::SRootData oRootData;
oRootData.szContext = NULL;
@@ -113,7 +113,7 @@ void CConversionManager::PopulateChildren( CDasherNode *pNode ) {
pNewNode = m_pNCManager->GetRoot(0, pNode, iLbnd, iHbnd, &oRootData);
pNewNode->SetFlag(NF_SEEN, false);
-
+
pNode->Children().push_back(pNewNode);
return;
@@ -122,7 +122,7 @@ void CConversionManager::PopulateChildren( CDasherNode *pNode ) {
void CConversionManager::ClearNode( CDasherNode *pNode ) {
if(pNode->m_pUserData){
SConversionData *pUserData(static_cast<SConversionData *>(pNode->m_pUserData));
-
+
pUserData->pLanguageModel->ReleaseContext(pUserData->iContext);
delete (SConversionData *)(pNode->m_pUserData);
}
@@ -139,9 +139,9 @@ void CConversionManager::RecursiveDumpTree(SCENode *pCurrent, unsigned int iDept
}
/*
while(pCurrent) {
- for(unsigned int i(0); i < iDepth; ++i)
+ for(unsigned int i(0); i < iDepth; ++i)
std::cout << "-";
-
+
std::cout << " " << pCurrent->pszConversion << " " << pCurrent->IsHeadAndCandNum << " " << pCurrent->CandIndex << " " << pCurrent->IsComplete << " " << pCurrent->AcCharCount << std::endl;
RecursiveDumpTree(pCurrent->GetChild(), iDepth + 1);
@@ -152,14 +152,14 @@ void CConversionManager::RecursiveDumpTree(SCENode *pCurrent, unsigned int iDept
void CConversionManager::Output( CDasherNode *pNode, Dasher::VECTOR_SYMBOL_PROB* pAdded, int iNormalization) {
// TODO: Reimplement this
- // m_pNCManager->m_bContextSensitive = true;
-
+ // m_pNCManager->m_bContextSensitive = true;
+
SCENode *pCurrentSCENode((static_cast<SConversionData *>(pNode->m_pUserData))->pSCENode);
-
+
if(pCurrentSCENode){
Dasher::CEditEvent oEvent(1, pCurrentSCENode->pszConversion, static_cast<SConversionData *>(pNode->m_pUserData)->iOffset);
m_pNCManager->InsertEvent(&oEvent);
-
+
if((pNode->GetChildren())[0]->m_pNodeManager != this) {
Dasher::CEditEvent oEvent(11, "", 0);
m_pNCManager->InsertEvent(&oEvent);
@@ -174,13 +174,13 @@ void CConversionManager::Output( CDasherNode *pNode, Dasher::VECTOR_SYMBOL_PROB*
Dasher::CEditEvent oOPEvent(1, ">", static_cast<SConversionData *>(pNode->m_pUserData)->iOffset);
m_pNCManager->InsertEvent(&oOPEvent);
}
-
+
Dasher::CEditEvent oEvent(10, "", 0);
m_pNCManager->InsertEvent(&oEvent);
}
}
-void CConversionManager::Undo( CDasherNode *pNode ) {
+void CConversionManager::Undo( CDasherNode *pNode ) {
SCENode *pCurrentSCENode((static_cast<SConversionData *>(pNode->m_pUserData))->pSCENode);
if(pCurrentSCENode) {
@@ -188,7 +188,7 @@ void CConversionManager::Undo( CDasherNode *pNode ) {
Dasher::CEditEvent oEvent(2, pCurrentSCENode->pszConversion, static_cast<SConversionData *>(pNode->m_pUserData)->iOffset);
m_pNCManager->InsertEvent(&oEvent);
}
- }
+ }
else {
if(!((static_cast<SConversionData *>(pNode->m_pUserData))->bisRoot)) {
Dasher::CEditEvent oOPEvent(2, "|", static_cast<SConversionData *>(pNode->m_pUserData)->iOffset);
diff --git a/Src/DasherCore/ConversionManagerFactory.cpp b/Src/DasherCore/ConversionManagerFactory.cpp
index a61be32..13d3a50 100644
--- a/Src/DasherCore/ConversionManagerFactory.cpp
+++ b/Src/DasherCore/ConversionManagerFactory.cpp
@@ -30,7 +30,7 @@ CConversionManagerFactory::CConversionManagerFactory(Dasher::CEventHandler *pEve
// TODO: Need to deal with the case of GetHelper returning NULL
m_pMgr = GetHelper(pEventHandler, pSettingsStore, iID, pCAlphIO);
-
+
//To clean up:
// TODO: These shouldn't be here - need to figure out exactly how it all works
pagecount = 0; // TODO: Doesn't actually appear to do anything
diff --git a/Src/DasherCore/ConversionManagerFactory.h b/Src/DasherCore/ConversionManagerFactory.h
index a07db8a..11bdce4 100644
--- a/Src/DasherCore/ConversionManagerFactory.h
+++ b/Src/DasherCore/ConversionManagerFactory.h
@@ -17,7 +17,7 @@ namespace Dasher {
CConversionManagerFactory(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, CNodeCreationManager *pNCManager, int iID, Dasher::CAlphIO *pCAlphIO, CAlphabet *pAlphabet);
virtual CDasherNode *GetRoot(CDasherNode *pParent, int iLower, int iUpper, void *pUserData);
~CConversionManagerFactory();
-
+
private:
CConversionManager *GetHelper(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, int iID, Dasher::CAlphIO *pCAlphIO);
@@ -26,7 +26,7 @@ namespace Dasher {
CNodeCreationManager *m_pNCManager;
CConversionManager *m_pMgr;
CAlphabet *m_pAlphabet;
-
+
int m_iCMCount;
int pagecount;//test
};
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index 42ce44c..5b344f1 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -15,7 +15,7 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with Dasher; if not, write to the Free Software
+// along with Dasher; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../Common/Common.h"
@@ -42,7 +42,7 @@
// Input filters
#include "AlternatingDirectMode.h"
#include "ButtonMode.h"
-#include "ClickFilter.h"
+#include "ClickFilter.h"
#include "CompassMode.h"
#include "DefaultFilter.h"
@@ -63,7 +63,7 @@
#include "../DasherCore/FileLogger.h"
#ifdef _DEBUG
const eLogLevel g_iLogLevel = logDEBUG;
-const int g_iLogOptions = logTimeStamp | logDateStamp | logDeleteOldFile;
+const int g_iLogOptions = logTimeStamp | logDateStamp | logDeleteOldFile;
#else
const eLogLevel g_iLogLevel = logNORMAL;
const int g_iLogOptions = logTimeStamp | logDateStamp;
@@ -102,9 +102,9 @@ CDasherInterfaceBase::CDasherInterfaceBase() {
// Various state variables
m_bRedrawScheduled = false;
-
+
m_iCurrentState = ST_START;
-
+
// m_bGlobalLock = false;
// TODO: Are these actually needed?
@@ -132,7 +132,7 @@ void CDasherInterfaceBase::Realize() {
CreateSettingsStore();
SetupUI();
SetupPaths();
-
+
std::vector<std::string> vAlphabetFiles;
ScanAlphabetFiles(vAlphabetFiles);
m_AlphIO = new CAlphIO(GetStringParameter(SP_SYSTEM_LOC), GetStringParameter(SP_USER_LOC), vAlphabetFiles);
@@ -155,8 +155,8 @@ void CDasherInterfaceBase::Realize() {
if(iUserLogLevel == 10)
m_pUserLog = new CBasicLog(m_pEventHandler, m_pSettingsStore);
- else if (iUserLogLevel > 0)
- m_pUserLog = new CUserLog(m_pEventHandler, m_pSettingsStore, iUserLogLevel, m_Alphabet);
+ else if (iUserLogLevel > 0)
+ m_pUserLog = new CUserLog(m_pEventHandler, m_pSettingsStore, iUserLogLevel, m_Alphabet);
#else
m_pUserLog = NULL;
#endif
@@ -177,11 +177,11 @@ void CDasherInterfaceBase::Realize() {
// FIXME - need to rationalise this sort of thing.
// InvalidateContext(true);
ScheduleRedraw();
-
+
#ifndef _WIN32_WCE
// All the setup is done by now, so let the user log object know
// that future parameter changes should be logged.
- if (m_pUserLog != NULL)
+ if (m_pUserLog != NULL)
m_pUserLog->InitIsDone();
#endif
@@ -189,7 +189,7 @@ void CDasherInterfaceBase::Realize() {
ChangeState(TR_MODEL_INIT);
using GameMode::CDasherGameMode;
- // Create the teacher singleton object.
+ // Create the teacher singleton object.
CDasherGameMode::CreateTeacher(m_pEventHandler, m_pSettingsStore, this);
CDasherGameMode::GetTeacher()->SetDasherView(m_pDasherView);
CDasherGameMode::GetTeacher()->SetDasherModel(m_pDasherModel);
@@ -231,7 +231,7 @@ CDasherInterfaceBase::~CDasherInterfaceBase() {
for (std::vector<CActionButton *>::iterator it=m_vRightButtons.begin(); it != m_vRightButtons.end(); ++it)
delete *it;
-
+
// Must delete event handler after all CDasherComponent derived classes
delete m_pEventHandler;
@@ -243,20 +243,20 @@ void CDasherInterfaceBase::PreSetNotify(int iParameter, const std::string &sNewV
// infrastructure
switch(iParameter) {
- case SP_ALPHABET_ID:
+ case SP_ALPHABET_ID:
// Cycle the alphabet history
if(GetStringParameter(SP_ALPHABET_ID) != sNewValue) {
if(GetStringParameter(SP_ALPHABET_1) != sNewValue) {
if(GetStringParameter(SP_ALPHABET_2) != sNewValue) {
if(GetStringParameter(SP_ALPHABET_3) != sNewValue)
SetStringParameter(SP_ALPHABET_4, GetStringParameter(SP_ALPHABET_3));
-
+
SetStringParameter(SP_ALPHABET_3, GetStringParameter(SP_ALPHABET_2));
}
-
+
SetStringParameter(SP_ALPHABET_2, GetStringParameter(SP_ALPHABET_1));
}
-
+
SetStringParameter(SP_ALPHABET_1, GetStringParameter(SP_ALPHABET_ID));
}
@@ -300,7 +300,7 @@ void CDasherInterfaceBase::InterfaceEventHandler(Dasher::CEvent *pEvent) {
ScheduleRedraw();
break;
case SP_DEFAULT_COLOUR_ID: // Delibarate fallthrough
- case BP_PALETTE_CHANGE:
+ case BP_PALETTE_CHANGE:
if(GetBoolParameter(BP_PALETTE_CHANGE))
SetStringParameter(SP_COLOUR_ID, GetStringParameter(SP_DEFAULT_COLOUR_ID));
break;
@@ -329,7 +329,7 @@ void CDasherInterfaceBase::InterfaceEventHandler(Dasher::CEvent *pEvent) {
}
else if(pEvent->m_iEventType == EV_EDIT && !GetBoolParameter(BP_GAME_MODE)) {
CEditEvent *pEditEvent(static_cast < CEditEvent * >(pEvent));
-
+
if(pEditEvent->m_iEditType == 1) {
strCurrentContext += pEditEvent->m_sText;
if( strCurrentContext.size() > 20 )
@@ -369,7 +369,7 @@ void CDasherInterfaceBase::InterfaceEventHandler(Dasher::CEvent *pEvent) {
// if(!m_bGlobalLock)
// ReleaseLock(0);
// }
-
+
// m_bGlobalLock = pLockEvent->m_bLock;
}
}
@@ -394,13 +394,13 @@ void CDasherInterfaceBase::CreateModel(int iOffset) {
delete m_pDasherModel;
m_pDasherModel = 0;
}
-
+
m_pDasherModel = new CDasherModel(m_pEventHandler, m_pSettingsStore, m_pNCManager, this, m_pDasherView, iOffset);
-
+
// Notify the teacher of the new model
if(GameMode::CDasherGameMode* pTeacher = GameMode::CDasherGameMode::GetTeacher())
pTeacher->SetDasherModel(m_pDasherModel);
-
+
}
void CDasherInterfaceBase::CreateNCManager() {
@@ -411,12 +411,12 @@ void CDasherInterfaceBase::CreateNCManager() {
int lmID = GetLongParameter(LP_LANGUAGE_MODEL_ID);
- if( lmID == -1 )
+ if( lmID == -1 )
return;
// Train the new language model
// CLockEvent *pEvent;
-
+
// pEvent = new CLockEvent("Training Dasher", true, 0);
// m_pEventHandler->InsertEvent(pEvent);
// delete pEvent;
@@ -441,11 +441,11 @@ void CDasherInterfaceBase::CreateNCManager() {
delete m_pNCManager;
m_pNCManager = 0;
}
-
+
m_pNCManager = new CNodeCreationManager(this, m_pEventHandler, m_pSettingsStore, m_AlphIO);
m_Alphabet = m_pNCManager->GetAlphabet();
-
+
ReleaseLock(iTrainingLock);
@@ -481,7 +481,7 @@ void CDasherInterfaceBase::GameMessageIn(int message, void* messagedata) {
void CDasherInterfaceBase::Unpause(unsigned long Time) {
SetBoolParameter(BP_DASHER_PAUSED, false);
- if(m_pDasherModel != 0)
+ if(m_pDasherModel != 0)
m_pDasherModel->Reset_framerate(Time);
Dasher::CStartEvent oEvent;
@@ -517,11 +517,11 @@ void CDasherInterfaceBase::CreateInput() {
void CDasherInterfaceBase::NewFrame(unsigned long iTime, bool bForceRedraw) {
// Prevent NewFrame from being reentered. This can happen occasionally and
- // cause crashes.
+ // cause crashes.
static bool bReentered=false;
if(bReentered) return;
bReentered=true;
-
+
// Fail if Dasher is locked
// if(m_iCurrentState != ST_NORMAL)
// return;
@@ -536,7 +536,7 @@ void CDasherInterfaceBase::NewFrame(unsigned long iTime, bool bForceRedraw) {
//So initialise appropriately...
Dasher::VECTOR_SYMBOL_PROB vAdded;
int iNumDeleted = 0;
-
+
if(m_pInputFilter) {
bChanged = m_pInputFilter->Timer(iTime, m_pDasherView, m_pDasherModel, &vAdded, &iNumDeleted);
}
@@ -547,14 +547,14 @@ void CDasherInterfaceBase::NewFrame(unsigned long iTime, bool bForceRedraw) {
if (vAdded.size() > 0)
m_pUserLog->AddSymbols(&vAdded);
#endif
-
+
}
else {
if(m_pInputFilter) {
bChanged = m_pInputFilter->Timer(iTime, m_pDasherView, m_pDasherModel, 0, 0);
}
}
-
+
m_pDasherModel->CheckForNewRoot(m_pDasherView);
}
}
@@ -571,14 +571,14 @@ void CDasherInterfaceBase::NewFrame(unsigned long iTime, bool bForceRedraw) {
m_pDasherView->Screen()->SetCaptureBackground(true);
m_pDasherView->Screen()->SetLoadBackground(true);
}
-
+
bForceRedraw |= m_bLastChanged;
m_bLastChanged = bChanged; //will also be set in Redraw if any nodes were expanded.
-
+
//limit the number of nodes we expand per frame...
LimitedNodeQueue nq(max(1l,(500+GetLongParameter(LP_NODE_BUDGET))/1000)); //amortize over multiple frames
Redraw(bChanged || m_bRedrawScheduled || bForceRedraw, nq);
-
+
m_bRedrawScheduled = false;
// This just passes the time through to the framerate tracker, so we
@@ -593,7 +593,7 @@ void CDasherInterfaceBase::Redraw(bool bRedrawNodes, NodeQueue &nodeQueue) {
// No point continuing if there's nothing to draw on...
if(!m_pDasherView)
return;
-
+
// Draw the nodes
if(bRedrawNodes) {
m_pDasherView->Screen()->SendMarker(0);
@@ -602,10 +602,10 @@ void CDasherInterfaceBase::Redraw(bool bRedrawNodes, NodeQueue &nodeQueue) {
// Draw the decorations
m_pDasherView->Screen()->SendMarker(1);
-
+
if(GameMode::CDasherGameMode* pTeacher = GameMode::CDasherGameMode::GetTeacher())
pTeacher->DrawGameDecorations(m_pDasherView);
-
+
bool bDecorationsChanged(false);
if(m_pInputFilter) {
@@ -634,7 +634,7 @@ void CDasherInterfaceBase::ChangeAlphabet() {
// exit from the first recursion
return;
}
-
+
// Send a lock event
WriteTrainFileFull();
@@ -662,13 +662,13 @@ void CDasherInterfaceBase::ChangeAlphabet() {
void CDasherInterfaceBase::ChangeColours() {
if(!m_ColourIO || !m_DasherScreen)
return;
-
+
// TODO: Make fuction return a pointer directly
m_DasherScreen->SetColourScheme(&(m_ColourIO->GetInfo(GetStringParameter(SP_COLOUR_ID))));
}
void CDasherInterfaceBase::ChangeScreen(CDasherScreen *NewScreen) {
- // What does ChangeScreen do?
+ // What does ChangeScreen do?
m_DasherScreen = NewScreen;
ChangeColours();
@@ -691,13 +691,13 @@ void CDasherInterfaceBase::ChangeScreen(CDasherScreen *NewScreen) {
void CDasherInterfaceBase::ChangeView() {
// TODO: Actually respond to LP_VIEW_ID parameter (although there is only one view at the moment)
-
+
// removed condition that m_pDasherModel != 0. Surely the view can exist without the model?-pconlon
- if(m_DasherScreen != 0 /*&& m_pDasherModel != 0*/) {
+ if(m_DasherScreen != 0 /*&& m_pDasherModel != 0*/) {
delete m_pDasherView;
-
+
m_pDasherView = new CDasherViewSquare(m_pEventHandler, m_pSettingsStore, m_DasherScreen);
-
+
if (m_pInput)
m_pDasherView->SetInput(m_pInput);
@@ -780,7 +780,7 @@ void CDasherInterfaceBase::ResetNats() {
// PauseAt(0,0);
// }
// }
-
+
// strCurrentContext = strNewContext;
// WriteTrainFileFull();
// }
@@ -834,7 +834,7 @@ void CDasherInterfaceBase::SetBoolParameter(int iParameter, bool bValue) {
m_pSettingsStore->SetBoolParameter(iParameter, bValue);
};
-void CDasherInterfaceBase::SetLongParameter(int iParameter, long lValue) {
+void CDasherInterfaceBase::SetLongParameter(int iParameter, long lValue) {
m_pSettingsStore->SetLongParameter(iParameter, lValue);
};
@@ -910,7 +910,7 @@ void CDasherInterfaceBase::CreateInputFilter()
CDasherModule *CDasherInterfaceBase::RegisterModule(CDasherModule *pModule) {
return m_oModuleManager.RegisterModule(pModule);
}
-
+
CDasherModule *CDasherInterfaceBase::GetModule(ModuleID_t iID) {
return m_oModuleManager.GetModule(iID);
}
@@ -1128,7 +1128,7 @@ void CDasherInterfaceBase::LeaveState(EState iState) {
void CDasherInterfaceBase::EnterState(EState iState) {
switch(iState) {
case ST_SHUTDOWN:
- ShutdownTimer();
+ ShutdownTimer();
WriteTrainFileFull();
break;
default:
@@ -1153,7 +1153,7 @@ int CDasherInterfaceBase::AddLock(const std::string &strDisplay) {
++m_iNextLockID;
NoNodeQueue nnq; //don't allow change to expansion state.
- Redraw(false, nnq);
+ Redraw(false, nnq);
return (m_iNextLockID - 1);
}
@@ -1183,7 +1183,7 @@ SLockData *CDasherInterfaceBase::GetCurrentLock() {
return NULL;
}
-void CDasherInterfaceBase::SetBuffer(int iOffset) {
+void CDasherInterfaceBase::SetBuffer(int iOffset) {
CreateModel(iOffset);
}
@@ -1213,7 +1213,7 @@ const char* CDasherInterfaceBase::ClSet(const std::string &strKey, const std::st
}
-void
+void
CDasherInterfaceBase::ImportTrainingText(const std::string &strPath) {
if(m_pNCManager)
m_pNCManager->ImportTrainingText(strPath);
diff --git a/Src/DasherCore/LanguageModelling/CTWLanguageModel.cpp b/Src/DasherCore/LanguageModelling/CTWLanguageModel.cpp
index 6d35ee0..af10800 100644
--- a/Src/DasherCore/LanguageModelling/CTWLanguageModel.cpp
+++ b/Src/DasherCore/LanguageModelling/CTWLanguageModel.cpp
@@ -15,10 +15,10 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with Dasher; if not, write to the Free Software
+// along with Dasher; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
-// For information on the CTW method visit
+// For information on the CTW method visit
// http://www.sps.ele.tue.nl/members/F.M.J.Willems/RESEARCH_files/CTW/ResearchCTW.htm
//
@@ -43,57 +43,57 @@ static char THIS_FILE[] = __FILE__;
CCTWLanguageModel::CCTWLanguageModel(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, const CSymbolAlphabet &SymbolAlphabet)
:CLanguageModel(pEventHandler, pSettingsStore, SymbolAlphabet){
- Dasher::CHashTable HashTable; // create hashtable
+ Dasher::CHashTable HashTable; // create hashtable
MaxDepth = 6; // Maximum depth of the context tree
MaxTries = 15; // Max. number of attempts to find a spot in the hash table
alpha = 14; // 2: KT-estimator, 1: Laplace estimator, 14 = found by P.A.J. Volf to be 'good' for text
MaxNrNodes = 4194304; // Max number of CCTWNodes in the table, trade-off between compression and memory usage. 2^22 = 4M
TotalNodes = 0; // to keep track of how many nodes are created in the table.
MaxFill = 0.9; // Threshold to decide when to freeze the tree
- Failed = 0; // keep track of how many nodes couldn't be found or created //debug
- Frozen = false; // to indicate if there is still room in the array of CCTWNodes
+ Failed = 0; // keep track of how many nodes couldn't be found or created //debug
+ Frozen = false; // to indicate if there is still room in the array of CCTWNodes
MaxCount = 255; // Maximum value for the counts for count-halving
NrBits = 9; // number of bits used for representation of probabilities
MaxValue = (1<<NrBits) -1;
-
+
NrPhases = (int)ceil(log((double)(GetSize()))/log(2.0)); // number of bits per input-symbol
- Tree = new CCTWNode[MaxNrNodes]; // create array with all CCTWNodes.
-
+ Tree = new CCTWNode[MaxNrNodes]; // create array with all CCTWNodes.
+
// Fill RootIndex table with indices of the RootNodes <- now I round up to next power of 2, should only create for possible symbols
- // Does that make a noticable difference in memory usage? Rootnodes with no symbols associated will accumulate no counts, so they only cost 1 node each (6 bytes).
+ // Does that make a noticable difference in memory usage? Rootnodes with no symbols associated will accumulate no counts, so they only cost 1 node each (6 bytes).
// Does it waste codespace? Do rootnodes with no symbols associated with them still get assigned a positive probability?
// Set NrTries to max+1, to identify a RootNode
- for (int i = 0; i<(1<<NrPhases);i++)
+ for (int i = 0; i<(1<<NrPhases);i++)
{
RootIndex[i] = HashTable.GetHashOffSet(i) & (MaxNrNodes-1); // MaxNrNodes is a power of 2, & results in a mod operation, walk 'round' through the array
Tree[RootIndex[i]].NrTries = MaxTries+1; // in rootnodes the character value doesn't matter, as long as Tries = unique
TotalNodes++;
- }
+ }
}
-CCTWLanguageModel::~ CCTWLanguageModel(){ // destructor
- delete [] Tree;
+CCTWLanguageModel::~ CCTWLanguageModel(){ // destructor
+ delete [] Tree;
}
// **** Implementation of help functions *****
// To get the 'phase' bit in byte
-#define ByteBit(byte,Phase) ((byte >> ((NrPhases-1)-Phase)) & 1)
-
-// To find the index of the RootNode for a byte and a phase.
+#define ByteBit(byte,Phase) ((byte >> ((NrPhases-1)-Phase)) & 1)
+
+// To find the index of the RootNode for a byte and a phase.
inline int CCTWLanguageModel::MapIndex(int b, int f){
return ((1<<f)-1 + (b>>(NrPhases-f))); //(2^phase -1) + dec. value of most significant bits
}
inline void CCTWLanguageModel::Scale(uint64 &a, uint64 &b)
{
- // Instead of using the full 16 bits for the probabilities, use only 9,
+ // Instead of using the full 16 bits for the probabilities, use only 9,
// that's the only relevant information the other bits are noise <- depends on the value of MaxCount,
// should use log2(alpha) bits more than for the counts a and b
-
+
while ((a > MaxValue) | (b > MaxValue))
{ // scale to right
a = a>>1;
- b = b>>1;
+ b = b>>1;
}
while ((a < (MaxValue>>1)) & (b < (MaxValue>>1)))
{// scale to left
@@ -103,53 +103,53 @@ inline void CCTWLanguageModel::Scale(uint64 &a, uint64 &b)
//prevent 0
if (a == 0)
{
- a = 1;
+ a = 1;
}
if (b == 0)
{
b = 1;
- }
+ }
}
-void CCTWLanguageModel::UpdatePath(int bit, int Update, int ValidDepth, int* & index, unsigned short int & P0, unsigned short int & P1)
-{ // updates the CTW data of the nodes in 'index' with value of 'bit'.
+void CCTWLanguageModel::UpdatePath(int bit, int Update, int ValidDepth, int* & index, unsigned short int & P0, unsigned short int & P1)
+{ // updates the CTW data of the nodes in 'index' with value of 'bit'.
// Update specifies yes (1) or no (0) (GetProbs). In the case 'no', the new Pws are calculated but the tree is not
// altered in any way
-
+
uint64 GammaZero; // (GammaZero / (GammaZero + GammaOne)) = Pw(0|x)
- uint64 GammaOne; // (GammaOne / (GammaZero + GammaOne)) = Pw(1|x)
- unsigned short int CountZero; // Number of zeros seen so far in this node
- unsigned short int CountOne; // Number of ones seen so far in this node
- uint64 PeBlockZero; // Local block probability of sequence (0,x)
+ uint64 GammaOne; // (GammaOne / (GammaZero + GammaOne)) = Pw(1|x)
+ unsigned short int CountZero; // Number of zeros seen so far in this node
+ unsigned short int CountOne; // Number of ones seen so far in this node
+ uint64 PeBlockZero; // Local block probability of sequence (0,x)
uint64 PeBlockOne; // Local block probability of sequence (1,x)
uint64 PwCBlockZero; // Product of the weighted block probabilities of the childnodes of sequence (0,x)
uint64 PwCBlockOne; // Product of the weighted block probabilities of the childnodes of sequence (1,x)
uint64 PeCondZero; // Conditional local probability (0|x)
uint64 PeCondOne; // Conditional local probability (1|x)
- uint64 PwCBlock; // Product of the weighted block probabilities of the childnodes of sequence (x)
- uint64 PeBlock; // Local block probability of sequence (x)
-
+ uint64 PwCBlock; // Product of the weighted block probabilities of the childnodes of sequence (x)
+ uint64 PeBlock; // Local block probability of sequence (x)
+
// The deepest index can be a leaf, a failed node, or a not-placed node
const int DeepestIndex = index[ValidDepth];
-
+
if (DeepestIndex == MaxNrNodes) // node didn't exist yet, both probs. equal
- {
- GammaZero = MaxValue;
- GammaOne = MaxValue;
+ {
+ GammaZero = MaxValue;
+ GammaOne = MaxValue;
}
else if (DeepestIndex == MaxNrNodes+1) // node couldn't be placed
- { // could do more fancy things here
- GammaZero = MaxValue;
- GammaOne = MaxValue;
+ { // could do more fancy things here
+ GammaZero = MaxValue;
+ GammaOne = MaxValue;
}
- else
- { // node has to be a leaf
+ else
+ { // node has to be a leaf
CountZero = Tree[DeepestIndex].a;
CountOne = Tree[DeepestIndex].b;
GammaZero = alpha*CountZero +1;
- GammaOne = alpha*CountOne +1;
-
+ GammaOne = alpha*CountOne +1;
+
if (Update == 1) // update tree
{// first update counts
if(bit)
@@ -157,96 +157,96 @@ void CCTWLanguageModel::UpdatePath(int bit, int Update, int ValidDepth, int* & i
if (CountOne == MaxCount)
{ // half counts
CountZero = (CountZero+1) / 2;
- CountOne = (CountOne+1) / 2;
+ CountOne = (CountOne+1) / 2;
}
else
- CountOne++;
+ CountOne++;
}
else // bit = 0
{
if (CountZero == MaxCount)
{ // half counts
CountZero = (CountZero+1) / 2;
- CountOne = (CountOne+1) / 2;
+ CountOne = (CountOne+1) / 2;
}
else
CountZero++;
- }
+ }
Tree[DeepestIndex].a = CountZero;
- Tree[DeepestIndex].b = CountOne;
+ Tree[DeepestIndex].b = CountOne;
} // end if update
- } // end if/else, deepest index done
- // now all the internal nodes, including the rootnode
+ } // end if/else, deepest index done
+ // now all the internal nodes, including the rootnode
for(int i=ValidDepth-1;i>=0;i--)
- {
+ {
CountZero = Tree[index[i]].a;
CountOne = Tree[index[i]].b;
-
+
PwCBlock = Tree[index[i]].PwChild;
- PeBlock = Tree[index[i]].Pe;
-
+ PeBlock = Tree[index[i]].Pe;
+
PeCondZero = (alpha*CountZero)+1;
PeCondOne = (alpha*CountOne) +1;
PeBlockZero = PeBlock*PeCondZero*(GammaOne+GammaZero);
PeBlockOne = PeBlock*PeCondOne*(GammaOne+GammaZero);
PwCBlockZero = PwCBlock*GammaZero*((alpha*(CountZero+CountOne))+2);
PwCBlockOne = PwCBlock*GammaOne *((alpha*(CountZero+CountOne))+2);
-
+
GammaZero = (PeBlockZero + PwCBlockZero);
GammaOne = (PeBlockOne + PwCBlockOne );
- Scale(GammaZero, GammaOne);
-
+ Scale(GammaZero, GammaOne);
+
if (Update == 1) // update tree
- {// first update counts
+ {// first update counts
if(bit)
{
if (CountOne == MaxCount)
{ // half counts
CountZero = (CountZero+1) / 2;
- CountOne = (CountOne+1) / 2;
+ CountOne = (CountOne+1) / 2;
}
else
CountOne++;
- Scale(PeBlockOne, PwCBlockOne);
- Tree[index[i]].Pe = PeBlockOne; // conversion after scaling, no problem
- Tree[index[i]].PwChild = PwCBlockOne;
+ Scale(PeBlockOne, PwCBlockOne);
+ Tree[index[i]].Pe = PeBlockOne; // conversion after scaling, no problem
+ Tree[index[i]].PwChild = PwCBlockOne;
}
else // bit = 0
{
if (CountZero == MaxCount)
{ // half counts
CountZero = (CountZero+1) / 2;
- CountOne = (CountOne+1) / 2;
+ CountOne = (CountOne+1) / 2;
}
else
CountZero++;
- Scale(PeBlockZero, PwCBlockZero);
- Tree[index[i]].Pe = PeBlockZero;
- Tree[index[i]].PwChild = PwCBlockZero;
+ Scale(PeBlockZero, PwCBlockZero);
+ Tree[index[i]].Pe = PeBlockZero;
+ Tree[index[i]].PwChild = PwCBlockZero;
}
Tree[index[i]].a = CountZero;
- Tree[index[i]].b = CountOne;
- } // end if update
- }
+ Tree[index[i]].b = CountOne;
+ } // end if update
+ }
P0 = GammaZero; // Gammas are already scaled back to 16 bits
- P1 = GammaOne;
-}
-
-int CCTWLanguageModel::FindPath(CCTWContext & context, char NewChar, int phase, int create, int* & index)
+ P1 = GammaOne;
+}
+
+int CCTWLanguageModel::FindPath(CCTWContext & context, char NewChar, int phase, int create, int* & index)
{ // Puts the Tree-array indices of the CCTWNodes on the path of Context in index.
// Returns the depth till which the path is found, index[] deeper than that is garbage!
// If 'create' = 1, new nodes are created when an empty spot is found
int Stepsize = 0;
int curindex = RootIndex[MapIndex(NewChar,phase)]; // Find root, depending on current (newest) character in context
index[0] = curindex;
-
+
// From the root, find/create the nodes, corresponding to the context
- for (unsigned int i=0; i<context.Context.size();i++)
+ for (unsigned int i=0; i<context.Context.size();i++)
{
- unsigned char CurChar = context.Context.at(i);
+ unsigned char CurChar = context.Context.at(i);
Stepsize = (HashTable.GetHashOffSet(CurChar)<<1)+1; // get stepsize. Shift+1 to keep result odd, to prevent cycles
bool found = false;
for (int Tries = 1; Tries<MaxTries; Tries++)
@@ -256,13 +256,13 @@ int CCTWLanguageModel::FindPath(CCTWContext & context, char NewChar, int phase,
if (Tree[curindex].NrTries == Tries) // node in use, is it the correct node?
{// see if this is the correct node: compare tries and last (current) character
if (Tree[curindex].Symbol == CurChar) // node found
- {
+ {
found = true; // to avoid 'failed'
index[i+1] = curindex; // tell calling function where to find the node, i+1 because index[0] = rootnode
break; // to escape loop and continue with next character
}
}
- if (Tree[curindex].NrTries == 0) // empty node found, create new node
+ if (Tree[curindex].NrTries == 0) // empty node found, create new node
{
if (!create) // No need to create a new node, let calling function know empty spot found
{
@@ -272,7 +272,7 @@ int CCTWLanguageModel::FindPath(CCTWContext & context, char NewChar, int phase,
if (!Frozen) // Still space in the tree
{
Tree[curindex].NrTries = Tries;
- Tree[curindex].Symbol = CurChar;
+ Tree[curindex].Symbol = CurChar;
TotalNodes++; // new node in use
if ((float)(TotalNodes)/(float)(MaxNrNodes) > MaxFill) // Max fillratio of tree reached, freeze tree
Frozen = true;
@@ -284,111 +284,111 @@ int CCTWLanguageModel::FindPath(CCTWContext & context, char NewChar, int phase,
{
found = false;
index[i+1] = MaxNrNodes+1; // to indicate node could not be placed
- return (i+1); // +i since i=0 is the rootnode, always valid
+ return (i+1); // +i since i=0 is the rootnode, always valid
}
} // else collision, set next step
} // for Tries
// after MaxTries attempts:
if (!found) // check to see if we were succesfull
- { // apparently, character could not be placed
+ { // apparently, character could not be placed
index[i+1] = MaxNrNodes+1; // to indicate node could not be placed
- return i+1; // indicate node could not be found/created for this phase
- } //if !found
+ return i+1; // indicate node could not be found/created for this phase
+ } //if !found
} // for i contextsize
-return context.Context.size(); // all nodes on the path found/created
+return context.Context.size(); // all nodes on the path found/created
} // end findpath
// **** Implementation of interface functions *****
void CCTWLanguageModel::EnterSymbol(Context CurContext, int Symbol)
-{ // add Symbol to the front of Context. If there are more than MaxDepth symbols, pop the last one
+{ // add Symbol to the front of Context. If there are more than MaxDepth symbols, pop the last one
CCTWLanguageModel::CCTWContext &Context = *(CCTWLanguageModel::CCTWContext *) (CurContext);
if (Context.Full == true)
- Context.Context.pop_back();
-
+ Context.Context.pop_back();
+
Context.Context.push_front(Symbol);
if (Context.Context.size() == MaxDepth)
- Context.Full = true;
+ Context.Full = true;
}
void CCTWLanguageModel::LearnSymbol(Context CurContext, int Symbol)
-{
+{
CCTWLanguageModel::CCTWContext &Context = *(CCTWLanguageModel::CCTWContext *) (CurContext);
-
+
if (Context.Full == true) // context is complete, update the tree
{ // find indices of the tree nodes corresponding to the context
-
- int *Index = new int[Context.Context.size()+1]; // +1 for the rootnode
- int ValidDepth = 0;
- for (int phase = 0;phase<NrPhases;phase++)
+
+ int *Index = new int[Context.Context.size()+1]; // +1 for the rootnode
+ int ValidDepth = 0;
+ for (int phase = 0;phase<NrPhases;phase++)
{
- ValidDepth = FindPath(Context, Symbol, phase, 1, Index); // Find indices of the nodes for this phase and context
- // nodes on the path for this phase found, update the tree
+ ValidDepth = FindPath(Context, Symbol, phase, 1, Index); // Find indices of the nodes for this phase and context
+ // nodes on the path for this phase found, update the tree
unsigned short int stubZ =0;
unsigned short int stubO =0;
- UpdatePath(ByteBit(Symbol,phase), 1, ValidDepth, Index, stubZ, stubO);
- }
+ UpdatePath(ByteBit(Symbol,phase), 1, ValidDepth, Index, stubZ, stubO);
+ }
delete [] Index;
Context.Context.pop_back(); // only delete last symbol if context is complete
}
- Context.Context.push_front(Symbol); // update context with newest symbol
-
+ Context.Context.push_front(Symbol); // update context with newest symbol
+
if (Context.Context.size() == MaxDepth)
Context.Full = true;
}
-void CCTWLanguageModel::GetProbs(Context context, std::vector<unsigned int> &Probs, int Norm, int iUniform) const
+void CCTWLanguageModel::GetProbs(Context context, std::vector<unsigned int> &Probs, int Norm, int iUniform) const
{ // because we reuse findpath and updatepath function, we need to de-const the object :(
// findpath should be declared const anyway (?)
-
+
CCTWLanguageModel* self = const_cast<CCTWLanguageModel*>(this);
-
- CCTWContext *CTWContext = ( CCTWContext *)(context);
- CCTWContext LocalContext(*CTWContext);
-
+
+ CCTWContext *CTWContext = ( CCTWContext *)(context);
+ CCTWContext LocalContext(*CTWContext);
+
int iNumSymbols = GetSize();
int MinProb = iUniform / iNumSymbols; //smallest probability to assign
- Probs.resize(iNumSymbols);
+ Probs.resize(iNumSymbols);
int pLeft = 0;
-
- // calculate probabilities of all possible symbols. Again assume all 2^NrPhases
+
+ // calculate probabilities of all possible symbols. Again assume all 2^NrPhases
int *Index = new int[LocalContext.Context.size()+1]; // +1 for the rootnode
-
+
vector <unsigned short int>Interval((1<<(NrPhases+1))-1); // number of rootnodes*2 (1 prob for bit 0 and 1 each)
if (Norm>65535)
{
Interval[0]=65535; // to prevent overflow
- pLeft = Norm-65535; // if Norm is way bigger than 2^16 - 1, uniformly distributing the 'leftover' coudl still cause overflow
+ pLeft = Norm-65535; // if Norm is way bigger than 2^16 - 1, uniformly distributing the 'leftover' could still cause overflow
}
else
- Interval[0] = Norm;
+ Interval[0] = Norm;
int ValidDepth = 0;
uint64 IntervalB = 0; // 'base' interval
uint64 IntervalZ = 0; // divided interval for the 0-branch
uint64 IntervalO = 0; // divided interval for the 1-branch
- unsigned int MinInterval = 0;
+ unsigned int MinInterval = 0;
unsigned short int Pw0 = 0;
unsigned short int Pw1 = 0;
- for (int phase = 0;phase<NrPhases;phase++)
+ for (int phase = 0;phase<NrPhases;phase++)
{
int stepsize = 1 <<(NrPhases-phase); // 2^maxphase-1 - fase
- for (int steps = 0;steps < 1<<phase;steps++)
- { // find the path for all needed symbols
+ for (int steps = 0;steps < 1<<phase;steps++)
+ { // find the path for all needed symbols
// FIXME now I round up to next power of 2
- ValidDepth = self->FindPath(LocalContext, steps*stepsize, phase, 0, Index); // Find indices of the nodes for this phase and context
-
- IntervalB = Interval[(1<<phase)+ steps - 1];
+ ValidDepth = self->FindPath(LocalContext, steps*stepsize, phase, 0, Index); // Find indices of the nodes for this phase and context
+
+ IntervalB = Interval[(1<<phase)+ steps - 1];
self->UpdatePath(0,0, ValidDepth, Index, Pw0, Pw1);
IntervalZ = (IntervalB * Pw0)/(uint64)(Pw0+Pw1); // flooring, influence of flooring P0 instead of P1 is negligible
- IntervalO = IntervalB - IntervalZ;
-
+ IntervalO = IntervalB - IntervalZ;
+
MinInterval = MinProb*1<<(NrPhases-1-phase); // leafs for each rootnode at the current phase, assuming a full alphabet!!
//make sure all leafs from this point will get at least probability 1
@@ -403,23 +403,23 @@ void CCTWLanguageModel::GetProbs(Context context, std::vector<unsigned int> &Pro
IntervalO = IntervalO + (MinInterval-IntervalO);
}
- Interval[(1<<(phase+1))+ 2*steps - 1] = IntervalZ;
- Interval[(1<<(phase+1))+ 2*steps] = IntervalO;
+ Interval[(1<<(phase+1))+ 2*steps - 1] = IntervalZ;
+ Interval[(1<<(phase+1))+ 2*steps] = IntervalO;
} // for steps
} // for phase
delete [] Index;
// Copy the intervals associated with the actual symbols to the vector Probs.
- Probs.assign((Interval.end()-(1<<NrPhases)), (Interval.end()-(1<<NrPhases)+iNumSymbols));
+ Probs.assign((Interval.end()-(1<<NrPhases)), (Interval.end()-(1<<NrPhases)+iNumSymbols));
pLeft +=Probs[0]; //symbol 0 is a special dummy symbol, should get prob. 0
Probs[0] = 0;
-
+
// calculate how many extra symbols exist in tree, because iNumSymbols is not a power of 2
int Extra = (1<<NrPhases) - iNumSymbols;
// take the probabilities from non-existing symbols and re-divide it over existing symbols
for (int j = Extra; j >0; j-- ) {
pLeft +=Interval[Interval.size()-j];
- }
+ }
int iLeft = iNumSymbols-1; //divide the probability that is left over the symbols
for(int j = 1; j < iNumSymbols; ++j) {
@@ -428,14 +428,14 @@ void CCTWLanguageModel::GetProbs(Context context, std::vector<unsigned int> &Pro
--iLeft;
pLeft -= p;
}
-
+
} // end function GetProbs
-bool CCTWLanguageModel::WriteToFile(std::string strFilename, std::string AlphabetName){
+bool CCTWLanguageModel::WriteToFile(std::string strFilename, std::string AlphabetName){
SLMFileHeader GenericHeader;
// Magic number ("%DLF" in ASCII)
- GenericHeader.szMagic[0] = '%';
+ GenericHeader.szMagic[0] = '%';
GenericHeader.szMagic[1] = 'D';
GenericHeader.szMagic[2] = 'L';
GenericHeader.szMagic[3] = 'F';
@@ -446,16 +446,16 @@ bool CCTWLanguageModel::WriteToFile(std::string strFilename, std::string Alphabe
GenericHeader.iLMMinVersion = 1; //Minimum backwards compatible version for the language model
GenericHeader.iLMVersion = 1; // Version number of the language model, version 1 is the stored hashtable, april 2007
GenericHeader.iHeaderSize = sizeof(SLMFileHeader) + AlphabetName.length(); // Total size of header (including variable length alphabet name)
-
+
FILE *OutputFile;
- OutputFile = fopen(strFilename.c_str(), "wb");
+ OutputFile = fopen(strFilename.c_str(), "wb");
if(OutputFile)
{
char * buffer;
buffer = new char[AlphabetName.length()+1];
strcpy(buffer, AlphabetName.c_str());
- // write header
+ // write header
fwrite(GenericHeader.szMagic , sizeof(GenericHeader.szMagic[0]), sizeof(GenericHeader.szMagic), OutputFile );
fwrite(&GenericHeader.iHeaderVersion, 2,1, OutputFile);
fwrite(&GenericHeader.iHeaderSize, 2,1, OutputFile);
@@ -476,8 +476,8 @@ bool CCTWLanguageModel::WriteToFile(std::string strFilename, std::string Alphabe
fwrite(&Tree[i].Symbol, 1,1,OutputFile);
fwrite(&Tree[i].NrTries, 1,1,OutputFile);
fwrite(&Tree[i].Pe, 2,1,OutputFile);
- fwrite(&Tree[i].PwChild, 2,1,OutputFile);
- }
+ fwrite(&Tree[i].PwChild, 2,1,OutputFile);
+ }
fclose(OutputFile);
return true;
}
@@ -485,23 +485,23 @@ bool CCTWLanguageModel::WriteToFile(std::string strFilename, std::string Alphabe
return false;
}
-bool CCTWLanguageModel::ReadFromFile(std::string strFilename, std::string AlphabetName){
+bool CCTWLanguageModel::ReadFromFile(std::string strFilename, std::string AlphabetName){
FILE *InputFile;
- InputFile = fopen(strFilename.c_str(), "rb");
+ InputFile = fopen(strFilename.c_str(), "rb");
if(InputFile)
{
/* Read and check header, close file and return failure when header is not what we expect.
TODO: Checking of the SLMFileHeader, which is not specific to the CTW languagemodel should be done in DasherModel,
- only CTW specific information (MaxNrNodes) should be checked here.
+ only CTW specific information (MaxNrNodes) should be checked here.
The values to compare with should be parameters and not hardcoded. */
-
+
SLMFileHeader GenericHeader;
char * ReadAlphabetName;
fread(&GenericHeader.szMagic , sizeof(GenericHeader.szMagic[0]), sizeof(GenericHeader.szMagic), InputFile);
if(memcmp(GenericHeader.szMagic,"%DLF",4))
- { // magic strings not equal
- return false;
+ { // magic strings not equal
+ return false;
}
fread(&GenericHeader.iHeaderVersion,2,1, InputFile);
if(GenericHeader.iHeaderVersion != 1)
@@ -517,31 +517,31 @@ bool CCTWLanguageModel::ReadFromFile(std::string strFilename, std::string Alphab
fread(&GenericHeader.iLMVersion,2,1, InputFile);
fread(&GenericHeader.iLMMinVersion,2,1, InputFile);
if(GenericHeader.iLMMinVersion > 1)
- { // header indicates stored model newer than we can handle
+ { // header indicates stored model newer than we can handle
return false;
}
fread(&GenericHeader.iAlphabetSize,2,1, InputFile);
if(GenericHeader.iAlphabetSize != GetSize())
{ // header indicates stored model uses an alphabet of different size
return false;
- }
-
+ }
+
ReadAlphabetName = new char[GenericHeader.iHeaderSize - sizeof(SLMFileHeader)+1];
fread(ReadAlphabetName,1,GenericHeader.iHeaderSize - sizeof(SLMFileHeader), InputFile);
ReadAlphabetName[GenericHeader.iHeaderSize - sizeof(SLMFileHeader)] = '\0'; // write the terminating 0 and read it in as well
-
+
if(strcmp(ReadAlphabetName,AlphabetName.c_str()))
- { // header indicates stored model uses a different alphabet
- delete[] ReadAlphabetName;
- return false;
- }
- delete[] ReadAlphabetName;
+ { // header indicates stored model uses a different alphabet
+ delete[] ReadAlphabetName;
+ return false;
+ }
+ delete[] ReadAlphabetName;
int ReadNrNodes;
fread(&ReadNrNodes,4,1, InputFile);
if(ReadNrNodes != MaxNrNodes)
- { // header indicates different number of nodes in the hashtable
- return false;
- }
+ { // header indicates different number of nodes in the hashtable
+ return false;
+ }
for(int i=0;i<MaxNrNodes;i++)
{
@@ -550,31 +550,31 @@ bool CCTWLanguageModel::ReadFromFile(std::string strFilename, std::string Alphab
fread(&Tree[i].Symbol, 1,1,InputFile);
fread(&Tree[i].NrTries, 1,1,InputFile);
fread(&Tree[i].Pe, 2,1,InputFile);
- fread(&Tree[i].PwChild, 2,1,InputFile);
+ fread(&Tree[i].PwChild, 2,1,InputFile);
}
fclose(InputFile);
- return true;
+ return true;
}
else
return false;
}
-inline CLanguageModel::Context CCTWLanguageModel::CreateEmptyContext() {
+inline CLanguageModel::Context CCTWLanguageModel::CreateEmptyContext() {
CCTWContext *pCont = new CCTWContext;
- return (Context) pCont;
+ return (Context) pCont;
}
inline CLanguageModel::Context CCTWLanguageModel::CloneContext(Context Copy) {
CCTWContext *pCont = new CCTWContext;
CCTWContext *pCopy = (CCTWContext *) Copy;
-
+
pCont->Full = pCopy->Full;
pCont->Context.assign(pCopy->Context.begin( ), pCopy->Context.end( ));
- return (Context) pCont;
+ return (Context) pCont;
}
-inline void CCTWLanguageModel::ReleaseContext(Context release) {
+inline void CCTWLanguageModel::ReleaseContext(Context release) {
delete (CCTWContext *) release;
};
diff --git a/Src/DasherCore/MandarinAlphMgr.cpp b/Src/DasherCore/MandarinAlphMgr.cpp
index 4f5af1d..5f37fc9 100644
--- a/Src/DasherCore/MandarinAlphMgr.cpp
+++ b/Src/DasherCore/MandarinAlphMgr.cpp
@@ -15,7 +15,7 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with Dasher; if not, write to the Free Software
+// along with Dasher; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../Common/Common.h"
@@ -45,7 +45,7 @@ static char THIS_FILE[] = __FILE__;
#endif
#endif
-CMandarinAlphMgr::CMandarinAlphMgr(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext)
+CMandarinAlphMgr::CMandarinAlphMgr(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext)
: CAlphabetManager(pInterface, pNCManager, pLanguageModel, iLearnContext) {
}
@@ -59,7 +59,7 @@ CDasherNode *CMandarinAlphMgr::GetRoot(CDasherNode *pParent, int iLower, int iUp
CConversionManager::SConversionData *pParentConversionData = static_cast<CConversionManager::SConversionData *>(pParent->m_pUserData);
pNodeUserData->iContext = m_pLanguageModel->CloneContext(pParentConversionData->iContext);
}
- else
+ else
pNodeUserData->iContext = m_pLanguageModel->CreateEmptyContext();
return pNewNode;
@@ -69,7 +69,7 @@ CDasherNode *CMandarinAlphMgr::CreateSymbolNode(CDasherNode *pParent, symbol iSy
if (iSymbol <= 1288) {
SAlphabetData *pParentData = static_cast<SAlphabetData *>(pParent->m_pUserData);
-
+
//Modified for Mandarin Dasher
//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
CDasherNode *pNewNode = m_pNCManager->GetRoot(2, pParent, iLbnd, iHbnd, &(pParentData->iOffset));
@@ -81,11 +81,11 @@ CDasherNode *CMandarinAlphMgr::CreateSymbolNode(CDasherNode *pParent, symbol iSy
CLanguageModel::Context CMandarinAlphMgr::CreateSymbolContext(SAlphabetData *pParentData, symbol iSymbol)
{
- //Context carry-over. This code may worth looking at debug
+ //Context carry-over. This code may worth looking at debug
return m_pLanguageModel->CloneContext(pParentData->iContext);
}
void CMandarinAlphMgr::SetFlag(CDasherNode *pNode, int iFlag, bool bValue) {
//disable learn-as-you-write for Mandarin Dasher
if (iFlag!=NF_COMMITTED) CAlphabetManager::SetFlag(pNode, iFlag, bValue);
-}
\ No newline at end of file
+}
diff --git a/Src/DasherCore/OneButtonFilter.cpp b/Src/DasherCore/OneButtonFilter.cpp
index 14cf3d0..77550f9 100644
--- a/Src/DasherCore/OneButtonFilter.cpp
+++ b/Src/DasherCore/OneButtonFilter.cpp
@@ -25,9 +25,9 @@ COneButtonFilter::~COneButtonFilter() {
}
bool COneButtonFilter::DecorateView(CDasherView *pView) {
-
+
CDasherScreen *pScreen(pView->Screen());
-
+
if (iLocation == 0) {
if (!bStarted) return false;
//reverse!
@@ -39,7 +39,7 @@ bool COneButtonFilter::DecorateView(CDasherView *pView) {
pScreen->Polyline(p, 4, 1, 1);
} else {
CDasherScreen::point p[2];
-
+
pView->Dasher2Screen(-100, iLocation, p[0].x, p[0].y);
pView->Dasher2Screen(-1000, iLocation, p[1].x, p[1].y);
pScreen->Polyline(p, 2, 1, 1);
@@ -61,7 +61,7 @@ bool COneButtonFilter::Timer(int Time, CDasherView *m_pDasherView, CDasherModel
iLocation = 8192-iLocation;
}
}
-
+
return m_pDasherModel->NextScheduledStep(Time, pAdded, pNumDeleted);
}
@@ -85,6 +85,6 @@ void COneButtonFilter::KeyDown(int iTime, int iId, CDasherView *pView, CDasherMo
bool COneButtonFilter::GetSettings(SModuleSettings **pSettings, int *iCount) {
*pSettings = sSettings;
*iCount = sizeof(sSettings) / sizeof(SModuleSettings);
-
+
return true;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]