[dasher] Remove CConversionManagerFactory and CAlphabetManagerFactory



commit 8fc47048dcde6bea02aef496b6264a27036d3db2
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Fri Dec 4 15:38:29 2009 +0000

    Remove CConversionManagerFactory and CAlphabetManagerFactory
    
    Both existed only to create an appropriate Conversion/AlphabetManager object,
    and then wrap it; the selection code has been moved into NodeCreationManager,
    which now uses the other Managers directly.
    
    Also hid Language Model inside NodeCreationManager and learning context inside
    AlphabetManager and GC'd NodeCreationManager::EnterText.

 ChangeLog                                   |    4 +
 Src/DasherCore/Alphabet/Alphabet.cpp        |    1 -
 Src/DasherCore/AlphabetManager.cpp          |    4 +-
 Src/DasherCore/AlphabetManager.h            |    2 +-
 Src/DasherCore/AlphabetManagerFactory.cpp   |  124 ---------------------
 Src/DasherCore/AlphabetManagerFactory.h     |   72 ------------
 Src/DasherCore/ControlManager.cpp           |    2 +-
 Src/DasherCore/ControlManager.h             |    2 -
 Src/DasherCore/ConversionHelper.cpp         |    4 +-
 Src/DasherCore/ConversionHelper.h           |   16 +--
 Src/DasherCore/ConversionManagerFactory.cpp |   81 --------------
 Src/DasherCore/ConversionManagerFactory.h   |   36 ------
 Src/DasherCore/DasherInterfaceBase.cpp      |    1 -
 Src/DasherCore/DasherModel.cpp              |    4 -
 Src/DasherCore/Makefile.am                  |    4 -
 Src/DasherCore/MandarinAlphMgr.cpp          |    4 +-
 Src/DasherCore/MandarinAlphMgr.h            |    2 +-
 Src/DasherCore/NodeCreationManager.cpp      |  159 ++++++++++++++++++--------
 Src/DasherCore/NodeCreationManager.h        |   28 ++---
 Src/DasherCore/PinYinConversionHelper.cpp   |    9 +-
 Src/DasherCore/PinYinConversionHelper.h     |   10 +-
 Src/DasherCore/Trainer.cpp                  |    5 -
 Src/DasherCore/TrainingHelper.cpp           |    1 -
 Src/MacOSX/Dasher.xcodeproj/project.pbxproj |   16 ---
 24 files changed, 147 insertions(+), 444 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 438e239..4b9008f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-12-04  Alan Lawrence <acl33 inf phy cam ac uk>
+
+	* Remove CConversionManagerFactory and CAlphabetManagerFactory
+
 2009-12-02  Alan Lawrence <acl33 inf phy cam ac uk>
 
 	* Made Children() read-only; nodes add selves to parent
diff --git a/Src/DasherCore/Alphabet/Alphabet.cpp b/Src/DasherCore/Alphabet/Alphabet.cpp
index bce8772..875578e 100644
--- a/Src/DasherCore/Alphabet/Alphabet.cpp
+++ b/Src/DasherCore/Alphabet/Alphabet.cpp
@@ -24,7 +24,6 @@
 #include "../../Common/Common.h"
 #include "../TrainingHelper.h"
 #include "Alphabet.h"
-#include "../AlphabetManagerFactory.h"
 #include "AlphabetMap.h"
 #include <cstring>
 
diff --git a/Src/DasherCore/AlphabetManager.cpp b/Src/DasherCore/AlphabetManager.cpp
index f6629b8..924d8a1 100644
--- a/Src/DasherCore/AlphabetManager.cpp
+++ b/Src/DasherCore/AlphabetManager.cpp
@@ -45,11 +45,11 @@ 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)
   : m_pLanguageModel(pLanguageModel), m_pNCManager(pNCManager) {
   m_pInterface = pInterface;
 
-  m_iLearnContext = iLearnContext;
+  m_iLearnContext = m_pLanguageModel->CreateEmptyContext();
 
 }
 
diff --git a/Src/DasherCore/AlphabetManager.h b/Src/DasherCore/AlphabetManager.h
index a4199d3..3412d0a 100644
--- a/Src/DasherCore/AlphabetManager.h
+++ b/Src/DasherCore/AlphabetManager.h
@@ -43,7 +43,7 @@ namespace Dasher {
   class CAlphabetManager {
   public:
 
-    CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext);
+    CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel);
 
   protected:
     class CAlphNode : public CDasherNode {
diff --git a/Src/DasherCore/ControlManager.cpp b/Src/DasherCore/ControlManager.cpp
index a5f9bb0..96cb26f 100644
--- a/Src/DasherCore/ControlManager.cpp
+++ b/Src/DasherCore/ControlManager.cpp
@@ -38,7 +38,7 @@ static char THIS_FILE[] = __FILE__;
 int CControlManager::m_iNextID = 0;
 
 CControlManager::CControlManager( CNodeCreationManager *pNCManager )
-  : m_pNCManager(pNCManager), m_pLanguageModel(NULL) {
+  : m_pNCManager(pNCManager) {
   string SystemString = m_pNCManager->GetStringParameter(SP_SYSTEM_LOC);
   string UserLocation = m_pNCManager->GetStringParameter(SP_USER_LOC);
   m_iNextID = 0;
diff --git a/Src/DasherCore/ControlManager.h b/Src/DasherCore/ControlManager.h
index 91d83be..560d2e4 100644
--- a/Src/DasherCore/ControlManager.h
+++ b/Src/DasherCore/ControlManager.h
@@ -21,7 +21,6 @@
 #ifndef __controlmanager_h__
 #define __controlmanager_h__
 
-#include "LanguageModelling/LanguageModel.h" // Urgh - we really shouldn't need to know about language models here
 #include "DasherModel.h"
 #include "DasherNode.h"
 #include "Event.h"
@@ -119,7 +118,6 @@ namespace Dasher {
 
     static int m_iNextID;
     CNodeCreationManager *m_pNCManager;
-    CLanguageModel *m_pLanguageModel;
     std::map<int,SControlItem*> m_mapControlMap;
 
     ///Whether we'd temporarily disabled Automatic Speed Control
diff --git a/Src/DasherCore/ConversionHelper.cpp b/Src/DasherCore/ConversionHelper.cpp
index 3720be0..aa21d08 100644
--- a/Src/DasherCore/ConversionHelper.cpp
+++ b/Src/DasherCore/ConversionHelper.cpp
@@ -39,8 +39,8 @@
 
 using namespace Dasher;
 
-CConversionHelper::CConversionHelper(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet) :
-  CConversionManager(pNCManager, pAlphabet), m_pLanguageModel(pNCManager->GetLanguageModel()) {
+CConversionHelper::CConversionHelper(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet, CLanguageModel *pLanguageModel) :
+  CConversionManager(pNCManager, pAlphabet), m_pLanguageModel(pLanguageModel) {
 	  colourStore[0][0]=66;//light blue
 	  colourStore[0][1]=64;//very light green
 	  colourStore[0][2]=62;//light yellow
diff --git a/Src/DasherCore/ConversionHelper.h b/Src/DasherCore/ConversionHelper.h
index 37bb920..f514bee 100644
--- a/Src/DasherCore/ConversionHelper.h
+++ b/Src/DasherCore/ConversionHelper.h
@@ -43,7 +43,7 @@ namespace Dasher{
 ///
   class CConversionHelper : public CConversionManager {
   public:
-	CConversionHelper(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet);
+	CConversionHelper(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet, CLanguageModel *pLanguageModel);
 	
 	/// Convert a given string to a lattice of candidates. Sizes for
 	/// candidates aren't assigned at this point. The input string
@@ -68,10 +68,7 @@ namespace Dasher{
 	/// @param iNChildren The number of children to be expected (more efficient than iterating linked list).
 	///
 	virtual void AssignSizes(SCENode ** pStart, Dasher::CLanguageModel::Context context, long normalization, int uniform, int iNChildren)=0;
-	
-	//TODO: figure out why this function cannot return a CLanguageModel
-	virtual Dasher::CLanguageModel * GetLanguageModel()=0;
-	
+		
 	/// Assign colours to the children of a given conversion node.
 	/// This function needs a rethink.
 	///
@@ -136,10 +133,11 @@ namespace Dasher{
     
     virtual void BuildTree(CConvHNode *pRoot);
 	
-    ///
-    /// Language model (TODO: We don't need to know about this, surely)
-    ///
-	
+    virtual Dasher::CLanguageModel *GetLanguageModel() {
+      return m_pLanguageModel;
+    }
+    
+  private:
     CLanguageModel *m_pLanguageModel;
 	
     CLanguageModel::Context m_iLearnContext;
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index a81ce92..b7388bf 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -23,7 +23,6 @@
 #include "DasherInterfaceBase.h"
 
 //#include "ActionButton.h"
-#include "AlphabetManagerFactory.h"
 #include "DasherViewSquare.h"
 #include "ControlManager.h"
 #include "DasherScreen.h"
diff --git a/Src/DasherCore/DasherModel.cpp b/Src/DasherCore/DasherModel.cpp
index 7ed652f..3887838 100644
--- a/Src/DasherCore/DasherModel.cpp
+++ b/Src/DasherCore/DasherModel.cpp
@@ -29,10 +29,6 @@
 
 #include "Event.h"
 #include "DasherInterfaceBase.h"
-#include "LanguageModelling/PPMLanguageModel.h"
-#include "LanguageModelling/WordLanguageModel.h"
-#include "LanguageModelling/DictLanguageModel.h"
-#include "LanguageModelling/MixtureLanguageModel.h"
 #include "NodeCreationManager.h"
 #include "DasherGameMode.h"
 #include "AlphabetManager.h"
diff --git a/Src/DasherCore/Makefile.am b/Src/DasherCore/Makefile.am
index 47ad84d..0d5aa82 100644
--- a/Src/DasherCore/Makefile.am
+++ b/Src/DasherCore/Makefile.am
@@ -21,8 +21,6 @@ libdashercore_a_SOURCES = \
 		ActionButton.h \
 		AlphabetManager.cpp \
 		AlphabetManager.h \
-		AlphabetManagerFactory.cpp \
-		AlphabetManagerFactory.h \
 		AutoSpeedControl.cpp \
 		AutoSpeedControl.h \
 		BasicLog.cpp \
@@ -45,8 +43,6 @@ libdashercore_a_SOURCES = \
 		ConversionHelper.h \
 		ConversionManager.cpp \
 		ConversionManager.h \
-		ConversionManagerFactory.cpp \
-		ConversionManagerFactory.h \
 		DasherButtons.cpp \
 		DasherButtons.h \
 		DasherComponent.cpp \
diff --git a/Src/DasherCore/MandarinAlphMgr.cpp b/Src/DasherCore/MandarinAlphMgr.cpp
index 66e8db0..88ae976 100644
--- a/Src/DasherCore/MandarinAlphMgr.cpp
+++ b/Src/DasherCore/MandarinAlphMgr.cpp
@@ -46,8 +46,8 @@ static char THIS_FILE[] = __FILE__;
 #endif
 #endif
 
-CMandarinAlphMgr::CMandarinAlphMgr(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext)
-  : CAlphabetManager(pInterface, pNCManager, pLanguageModel, iLearnContext) {
+CMandarinAlphMgr::CMandarinAlphMgr(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel)
+  : CAlphabetManager(pInterface, pNCManager, pLanguageModel) {
 }
 
 CAlphabetManager::CAlphNode *CMandarinAlphMgr::GetRoot(CDasherNode *pParent, int iLower, int iUpper, char *szContext, int iOffset) {
diff --git a/Src/DasherCore/MandarinAlphMgr.h b/Src/DasherCore/MandarinAlphMgr.h
index 24ca897..61c8d49 100644
--- a/Src/DasherCore/MandarinAlphMgr.h
+++ b/Src/DasherCore/MandarinAlphMgr.h
@@ -35,7 +35,7 @@ namespace Dasher {
   class CMandarinAlphMgr : public CAlphabetManager {
   public:
 
-    CMandarinAlphMgr(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext);
+    CMandarinAlphMgr(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel);
 
     ///
     /// Get a new root node owned by this manager
diff --git a/Src/DasherCore/NodeCreationManager.cpp b/Src/DasherCore/NodeCreationManager.cpp
index f293cc7..c5ac6d0 100644
--- a/Src/DasherCore/NodeCreationManager.cpp
+++ b/Src/DasherCore/NodeCreationManager.cpp
@@ -5,7 +5,10 @@
 #include "LanguageModelling/DictLanguageModel.h"
 #include "LanguageModelling/MixtureLanguageModel.h"
 #include "LanguageModelling/PPMPYLanguageModel.h"
+#include "LanguageModelling/CTWLanguageModel.h"
 #include "NodeCreationManager.h"
+#include "MandarinAlphMgr.h"
+#include "PinYinConversionHelper.h"
 #include "ControlManager.h"
 #include "EventHandler.h"
 
@@ -16,25 +19,86 @@ CNodeCreationManager::CNodeCreationManager(Dasher::CDasherInterfaceBase *pInterf
 					   CSettingsStore *pSettingsStore,
 					   Dasher::CAlphIO *pAlphIO) : CDasherComponent(pEventHandler, pSettingsStore) {
 
-  m_pAlphabetManagerFactory = new CAlphabetManagerFactory(pInterface,
-							  pEventHandler,
-							  pSettingsStore,
-							  pAlphIO,
-							  this);
+  const Dasher::CAlphIO::AlphInfo &oAlphInfo(pAlphIO->GetInfo(pSettingsStore->GetStringParameter(SP_ALPHABET_ID)));
+  m_pAlphabet = new CAlphabet(oAlphInfo);
   
-  m_pLanguageModel = m_pAlphabetManagerFactory->GetLanguageModel();
-  m_pAlphabet = m_pAlphabetManagerFactory->GetAlphabet();
-
-  CTrainer *pTrainer =  m_pAlphabetManagerFactory->GetTrainer();
+  pSettingsStore->SetStringParameter(SP_TRAIN_FILE, m_pAlphabet->GetTrainingFile());
+  pSettingsStore->SetStringParameter(SP_GAME_TEXT_FILE, m_pAlphabet->GetGameModeFile());
+  
+  pSettingsStore->SetStringParameter(SP_DEFAULT_COLOUR_ID, m_pAlphabet->GetPalette());
+  
+  if(pSettingsStore->GetLongParameter(LP_ORIENTATION) == Dasher::Opts::AlphabetDefault)
+    pSettingsStore->SetLongParameter(LP_REAL_ORIENTATION, m_pAlphabet->GetOrientation());
+  // --
+  
+  CSymbolAlphabet alphabet(m_pAlphabet->GetNumberTextSymbols());
+  alphabet.SetSpaceSymbol(m_pAlphabet->GetSpaceSymbol());      // FIXME - is this right, or do we have to do some kind of translation?
+  alphabet.SetAlphabetPointer(m_pAlphabet);    // Horrible hack, but ignore for now.
+  
+  // Create an appropriate language model;
+  
+  m_iConversionID = oAlphInfo.m_iConversionID;
+  
+  //WZ: Mandarin Dasher Change
+  //If statement checks for the specific Super PinYin alphabet, and sets language model to PPMPY
+  if((m_iConversionID==2)&&(pSettingsStore->GetStringParameter(SP_ALPHABET_ID)=="Chinese Super Pin Yin, grouped by Dictionary")){
+    
+    std::string CHAlphabet = "Chinese / ç®?ä½?中æ?? (simplified chinese, in pin yin groups)";
+    Dasher::CAlphIO::AlphInfo oCHAlphInfo = pAlphIO->GetInfo(CHAlphabet);
+    CAlphabet *pCHAlphabet = new CAlphabet(oCHAlphInfo);
+    
+    CSymbolAlphabet chalphabet(pCHAlphabet->GetNumberTextSymbols());
+    chalphabet.SetSpaceSymbol(pCHAlphabet->GetSpaceSymbol());
+    chalphabet.SetAlphabetPointer(pCHAlphabet);
+    //std::cout<<"CHALphabet size "<<chalphabet.GetSize(); [7603]
+    m_pLanguageModel = new CPPMPYLanguageModel(pEventHandler, pSettingsStore, chalphabet, alphabet);
+    m_pTrainer = new CMandarinTrainer(m_pLanguageModel, m_pAlphabet, pCHAlphabet);
+    std::cout<<"Setting PPMPY model"<<std::endl;
+  }
+  else{
+    //End Mandarin Dasher Change
+    
+    // FIXME - return to using enum here
+    switch (pSettingsStore->GetLongParameter(LP_LANGUAGE_MODEL_ID)) {
+      case 0:
+        m_pLanguageModel = new CPPMLanguageModel(pEventHandler, pSettingsStore, alphabet);
+        break;
+      case 2:
+        m_pLanguageModel = new CWordLanguageModel(pEventHandler, pSettingsStore, alphabet);
+        break;
+      case 3:
+        m_pLanguageModel = new CMixtureLanguageModel(pEventHandler, pSettingsStore, alphabet);
+        break;  
+      case 4:
+        m_pLanguageModel = new CCTWLanguageModel(pEventHandler, pSettingsStore, alphabet);
+        break;
+        
+      default:
+        // If there is a bogus value for the language model ID, we'll default
+        // to our trusty old PPM language model.
+        m_pLanguageModel = new CPPMLanguageModel(pEventHandler, pSettingsStore, alphabet);    
+        break;
+    }
+    m_pTrainer = new CTrainer(m_pLanguageModel, m_pAlphabet);
+  }
+    
+  // 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
+  
+  //(ACL) Modify AlphabetManager for Mandarin Dasher
+  if (m_iConversionID == 2)
+    m_pAlphabetManager = new CMandarinAlphMgr(pInterface, this, m_pLanguageModel);
+  else
+    m_pAlphabetManager = new CAlphabetManager(pInterface, this, m_pLanguageModel);
 
   //1. Look for system training text...
   CLockEvent oEvent("Training on System Text", true, 0);
   pEventHandler->InsertEvent(&oEvent);
-  pTrainer->LoadFile(GetStringParameter(SP_SYSTEM_LOC) + m_pAlphabet->GetTrainingFile());
+  m_pTrainer->LoadFile(GetStringParameter(SP_SYSTEM_LOC) + m_pAlphabet->GetTrainingFile());
   //Now add in any user-provided individual training text...
   oEvent.m_strMessage = "Training on User Text"; oEvent.m_bLock=true; oEvent.m_iPercent = 0;
   pEventHandler->InsertEvent(&oEvent);
-  pTrainer->LoadFile(GetStringParameter(SP_USER_LOC) + m_pAlphabet->GetTrainingFile());
+  m_pTrainer->LoadFile(GetStringParameter(SP_USER_LOC) + m_pAlphabet->GetTrainingFile());
   oEvent.m_bLock = false;
   pEventHandler->InsertEvent(&oEvent);
 
@@ -57,28 +121,41 @@ CNodeCreationManager::CNodeCreationManager(Dasher::CDasherInterfaceBase *pInterf
 #else
   m_pControlManager = 0;
 #endif
-  m_pConversionManagerFactory = new CConversionManagerFactory(pEventHandler,
-							      pSettingsStore,
-							      this,
-							      m_pAlphabetManagerFactory->GetConversionID(),
-							      pAlphIO,
-							      m_pAlphabet);
+  
+  switch(m_iConversionID) {
+    default:
+      //TODO: Error reporting here
+      //fall through to
+    case 0: // No conversion required
+      m_pConversionManager = new CConversionManager(this, m_pAlphabet);
+      //ACL no, not quite - ConvMgrFac would always be created, so (ConvMgrFac==NULL) would always fail; but then segfault on ConvMgr->GetRoot() ?
+      break;
+#ifdef JAPANESE
+    case 1: // Japanese
+#ifdef WIN32
+      m_pConversionManager = new CIMEConversionHelper;
+#else
+      m_pConversionManager = new CCannaConversionHelper(this, m_pAlphabet, GetLongParameter(LP_CONVERSION_TYPE), GetLongParameter(LP_CONVERSION_ORDER));
+#endif
+      break;
+#endif
+#ifdef CHINESE
+    case 2: // Chinese
+      m_pConversionManager = new CPinYinConversionHelper(this, m_pEventHandler, m_pSettingsStore, pAlphIO,
+                                         GetStringParameter(SP_SYSTEM_LOC) +"/alphabet.chineseRuby.xml",
+                                         m_pAlphabet, static_cast<CPPMPYLanguageModel *>(m_pLanguageModel));
+      break;
+#endif
+  }
 }
 
 CNodeCreationManager::~CNodeCreationManager() {
-
-  // C++ standard dictates that
-  // delete NULL;
-  // is totally safe, and does nothing. Do we need all these if statements?
-
-  if(m_pAlphabetManagerFactory)
-    delete m_pAlphabetManagerFactory;
+  delete m_pAlphabetManager;
+  delete m_pTrainer;
   
-  if(m_pControlManager)
-    delete m_pControlManager;
+  delete m_pControlManager;
 
-  if(m_pConversionManagerFactory)
-    delete m_pConversionManagerFactory;
+  if (m_pConversionManager) m_pConversionManager->Unref();
 }
 
 void CNodeCreationManager::RegisterNode( int iID, const std::string &strLabel, int iColour ) {
@@ -97,7 +174,7 @@ void CNodeCreationManager::DisconnectNode(int iChild, int iParent) {
 }
 
 CDasherNode *CNodeCreationManager::GetAlphRoot(Dasher::CDasherNode *pParent, int iLower, int iUpper, char *szContext, int iOffset) { 
- return m_pAlphabetManagerFactory->GetRoot(pParent, iLower, iUpper, szContext, iOffset);
+ return m_pAlphabetManager->GetRoot(pParent, iLower, iUpper, szContext, iOffset);
 }
 
 CDasherNode *CNodeCreationManager::GetCtrlRoot(Dasher::CDasherNode *pParent, int iLower, int iUpper, int iOffset) { 
@@ -108,9 +185,8 @@ CDasherNode *CNodeCreationManager::GetCtrlRoot(Dasher::CDasherNode *pParent, int
 }
 
 CDasherNode *CNodeCreationManager::GetConvRoot(Dasher::CDasherNode *pParent, int iLower, int iUpper, int iOffset) { 
- if(m_pConversionManagerFactory)
- return m_pConversionManagerFactory->GetRoot(pParent, iLower, iUpper, iOffset);
- else
+ if(m_pConversionManager)
+   return m_pConversionManager->GetRoot(pParent, iLower, iUpper, iOffset);
  return NULL;
 }
 
@@ -150,7 +226,7 @@ void CNodeCreationManager::GetProbs(CLanguageModel::Context context, std::vector
    //  m_pLanguageModel->GetProbs(context, Probs, iNorm, ((iNorm * uniform) / 1000));
    
    //WZ: Mandarin Dasher Change
-   if(m_pAlphabetManagerFactory->GetConversionID()==2){
+   if(m_iConversionID==2){
      //Mark: static cast ok?
      static_cast<CPPMPYLanguageModel *>(m_pLanguageModel)->GetPYProbs(context, Probs, iNorm, 0);
    }
@@ -181,22 +257,7 @@ void CNodeCreationManager::GetProbs(CLanguageModel::Context context, std::vector
 
 }
 
-void CNodeCreationManager::EnterText(CLanguageModel::Context context, std::string TheText) const {
-  std::vector < symbol > Symbols;
-  m_pAlphabet->GetSymbols(Symbols, TheText);
-  for(unsigned int i = 0; i < Symbols.size(); i++)
-    m_pLanguageModel->EnterSymbol(context, Symbols[i]); // FIXME - conversion to symbol alphabet
-}
-
 void 
 CNodeCreationManager::ImportTrainingText(const std::string &strPath) {
-  CTrainer *pTrainer = NULL;
-
-  if(m_pAlphabetManagerFactory)
-    pTrainer = m_pAlphabetManagerFactory->GetTrainer();
-
-  if(m_pAlphabet && pTrainer)
-	pTrainer->LoadFile(strPath);
-
-  delete pTrainer;
+	m_pTrainer->LoadFile(strPath);
 }
diff --git a/Src/DasherCore/NodeCreationManager.h b/Src/DasherCore/NodeCreationManager.h
index 9042ae8..7588838 100644
--- a/Src/DasherCore/NodeCreationManager.h
+++ b/Src/DasherCore/NodeCreationManager.h
@@ -3,11 +3,11 @@
 
 #include "Alphabet/Alphabet.h"
 #include "Alphabet/AlphIO.h"
-#include "AlphabetManagerFactory.h"
-#include "ConversionManagerFactory.h"
+#include "AlphabetManager.h"
+#include "ConversionManager.h"
 #include "DasherComponent.h"
-
 #include "LanguageModelling/LanguageModel.h"
+#include "Trainer.h"
 
 #include <string>
 #include <vector>
@@ -54,20 +54,7 @@ class CNodeCreationManager : public Dasher::CDasherComponent {
 
   void DisconnectNode(int iChild, int iParent);
 
-  ///
-  /// Temporary methods: TODO: remove
-  ///
-
-  Dasher::CLanguageModel *GetLanguageModel() {
-    return m_pLanguageModel;
-  };
-
-  Dasher::CLanguageModel::Context GetLearnContext() {
-    return m_pAlphabetManagerFactory->GetLearnContext();
-  }
-
   void GetProbs(Dasher::CLanguageModel::Context context, std::vector <Dasher::symbol >&NewSymbols, std::vector <unsigned int >&Probs, int iNorm) const;
-  void EnterText(Dasher::CLanguageModel::Context context, std::string TheText) const;
 
   inline int GetColour(Dasher::symbol s, int iPhase) const {
     return m_pAlphabet->GetColour(s, iPhase); 
@@ -118,10 +105,13 @@ class CNodeCreationManager : public Dasher::CDasherComponent {
  private:
   Dasher::CLanguageModel *m_pLanguageModel;     // pointer to the language model
   Dasher::CAlphabet *m_pAlphabet;        // pointer to the alphabet
-
-  Dasher::CAlphabetManagerFactory *m_pAlphabetManagerFactory;
+  Dasher::CTrainer *m_pTrainer;
+  
+  int m_iConversionID;
+  
+  Dasher::CAlphabetManager *m_pAlphabetManager;
   Dasher::CControlManager *m_pControlManager;
-  Dasher::CConversionManagerFactory *m_pConversionManagerFactory;
+  Dasher::CConversionManager *m_pConversionManager;
 };
 /// @}
 
diff --git a/Src/DasherCore/PinYinConversionHelper.cpp b/Src/DasherCore/PinYinConversionHelper.cpp
index a605bb3..32e8f04 100644
--- a/Src/DasherCore/PinYinConversionHelper.cpp
+++ b/Src/DasherCore/PinYinConversionHelper.cpp
@@ -16,11 +16,10 @@
 
 using namespace Dasher;
 
-CPinYinConversionHelper::CPinYinConversionHelper(CNodeCreationManager *pNCManager, Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, Dasher::CAlphIO *pCAlphIO, const std::string strCHAlphabetPath, CAlphabet * pAlphabet)
-: CConversionHelper(pNCManager,pAlphabet) {
+CPinYinConversionHelper::CPinYinConversionHelper(CNodeCreationManager *pNCManager, Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, Dasher::CAlphIO *pCAlphIO, const std::string strCHAlphabetPath, CAlphabet * pAlphabet, CPPMPYLanguageModel *pLanguageModel)
+: CConversionHelper(pNCManager,pAlphabet,pLanguageModel) {
 
   m_pPYAlphabet = pAlphabet;
-  m_pLanguageModel = static_cast<CPPMPYLanguageModel *>(pNCManager->GetLanguageModel());
   // This section cleans initialises the Chinese character alphabet 
 
   const std::string CHAlphabet = "Chinese / ç®?ä½?中æ?? (simplified chinese, in pin yin groups)";
@@ -81,7 +80,7 @@ unsigned int CPinYinConversionHelper::GetSumPYProbs(Dasher::CLanguageModel::Cont
   std::vector <unsigned int> Probs;
   unsigned int sumProb=0;
   
-  m_pLanguageModel->GetProbs(context, Probs, norm, 0);
+  GetLanguageModel()->GetProbs(context, Probs, norm, 0);
 
   SCENode * pCurrentNode = pPYCandStart;
 
@@ -159,7 +158,7 @@ void CPinYinConversionHelper::AssignSizes(SCENode **pStart, Dasher::CLanguageMod
  
   //  std::cout<<"norm input: "<<nonuniform_norm/(iSymbols/iNChildren/100)<<std::endl;
 
-  m_pLanguageModel->GetPartProbs(context, pStart, iNChildren, nonuniform_norm, 0);
+  GetLanguageModel()->GetPartProbs(context, pStart, iNChildren, nonuniform_norm, 0);
 
   //std::cout<<"after get probs "<<std::endl;
 
diff --git a/Src/DasherCore/PinYinConversionHelper.h b/Src/DasherCore/PinYinConversionHelper.h
index 29167ba..b617047 100644
--- a/Src/DasherCore/PinYinConversionHelper.h
+++ b/Src/DasherCore/PinYinConversionHelper.h
@@ -19,7 +19,7 @@ class CPinYinConversionHelper : public CConversionHelper {
   friend class CMandarinAlphMgr;
  public:
 
-  CPinYinConversionHelper(CNodeCreationManager *pNCManager, Dasher::CEventHandler *pEventHandler,  CSettingsStore *pSettingsStore, Dasher::CAlphIO *pAlphIO, const std::string strCHAlphabetPath, Dasher::CAlphabet * pAlphabet);
+  CPinYinConversionHelper(CNodeCreationManager *pNCManager, Dasher::CEventHandler *pEventHandler,  CSettingsStore *pSettingsStore, Dasher::CAlphIO *pAlphIO, const std::string strCHAlphabetPath, Dasher::CAlphabet * pAlphabet, CPPMPYLanguageModel *pLanguageModel);
 
   virtual void BuildTree(CConvHNode *pRoot);
   
@@ -31,10 +31,6 @@ class CPinYinConversionHelper : public CConversionHelper {
 
   virtual unsigned int GetSumPYProbs(Dasher::CLanguageModel::Context context, SCENode * pPYCandStart,int norm);
 
-  virtual Dasher::CLanguageModel *  GetLanguageModel(){
-    return m_pLanguageModel;
-  }
-
 protected:
   class CPYConvNode : public CConvHNode {
   public:
@@ -52,11 +48,13 @@ protected:
   };
   CPYConvNode *makeNode(CDasherNode *pParent, int iLbnd, int iHbnd, CDasherNode::SDisplayInfo *pDispInfo);
 	
+  virtual CPPMPYLanguageModel *GetLanguageModel() {
+    return static_cast<CPPMPYLanguageModel *>(CConversionHelper::GetLanguageModel());
+  }
  private:
   void TrainChPPM(CSettingsStore *pSettingsStore);
   void ProcessFile(CSettingsStore *pSettingsStore, int index);
 
-  CPPMPYLanguageModel *m_pLanguageModel;     // pointer to the language model
   CAlphabet *m_pCHAlphabet;        // pointer to the Chinese Character alphabet
   CAlphabet *m_pPYAlphabet;        // pointer to the Grouped Super Pin Yin alphabet 
   CPinyinParser *pParser;
diff --git a/Src/DasherCore/Trainer.cpp b/Src/DasherCore/Trainer.cpp
index 6c99579..ad26e90 100644
--- a/Src/DasherCore/Trainer.cpp
+++ b/Src/DasherCore/Trainer.cpp
@@ -3,11 +3,6 @@
 
 #include "Trainer.h"
 #include "DasherInterfaceBase.h"
-#include "LanguageModelling/PPMLanguageModel.h"
-#include "LanguageModelling/WordLanguageModel.h"
-#include "LanguageModelling/DictLanguageModel.h"
-#include "LanguageModelling/MixtureLanguageModel.h"
-#include "LanguageModelling/CTWLanguageModel.h"
 #include "LanguageModelling/PPMPYLanguageModel.h"
 
 using namespace Dasher;
diff --git a/Src/DasherCore/TrainingHelper.cpp b/Src/DasherCore/TrainingHelper.cpp
index fc00868..cf26ffa 100644
--- a/Src/DasherCore/TrainingHelper.cpp
+++ b/Src/DasherCore/TrainingHelper.cpp
@@ -18,7 +18,6 @@
 // along with Dasher; if not, write to the Free Software 
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-#include "AlphabetManagerFactory.h"
 #include "TrainingHelper.h"
 
 #include <cstdio>
diff --git a/Src/MacOSX/Dasher.xcodeproj/project.pbxproj b/Src/MacOSX/Dasher.xcodeproj/project.pbxproj
index 8199d5c..2af7316 100755
--- a/Src/MacOSX/Dasher.xcodeproj/project.pbxproj
+++ b/Src/MacOSX/Dasher.xcodeproj/project.pbxproj
@@ -36,8 +36,6 @@
 		1948BEA60C226CFD001DFA32 /* GroupInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 1948BE000C226CFC001DFA32 /* GroupInfo.h */; };
 		1948BEA80C226CFD001DFA32 /* AlphabetManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1948BE020C226CFC001DFA32 /* AlphabetManager.cpp */; };
 		1948BEA90C226CFD001DFA32 /* AlphabetManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1948BE030C226CFC001DFA32 /* AlphabetManager.h */; };
-		1948BEAA0C226CFD001DFA32 /* AlphabetManagerFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1948BE040C226CFC001DFA32 /* AlphabetManagerFactory.cpp */; };
-		1948BEAB0C226CFD001DFA32 /* AlphabetManagerFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 1948BE050C226CFC001DFA32 /* AlphabetManagerFactory.h */; };
 		1948BEAC0C226CFD001DFA32 /* AutoSpeedControl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1948BE060C226CFC001DFA32 /* AutoSpeedControl.cpp */; };
 		1948BEAD0C226CFD001DFA32 /* AutoSpeedControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 1948BE070C226CFC001DFA32 /* AutoSpeedControl.h */; };
 		1948BEAE0C226CFD001DFA32 /* BasicLog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1948BE080C226CFC001DFA32 /* BasicLog.cpp */; };
@@ -54,8 +52,6 @@
 		1948BEBC0C226CFD001DFA32 /* ConversionHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 1948BE160C226CFC001DFA32 /* ConversionHelper.h */; };
 		1948BEBD0C226CFD001DFA32 /* ConversionManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1948BE170C226CFC001DFA32 /* ConversionManager.cpp */; };
 		1948BEBE0C226CFD001DFA32 /* ConversionManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1948BE180C226CFC001DFA32 /* ConversionManager.h */; };
-		1948BEBF0C226CFD001DFA32 /* ConversionManagerFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1948BE190C226CFC001DFA32 /* ConversionManagerFactory.cpp */; };
-		1948BEC00C226CFD001DFA32 /* ConversionManagerFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 1948BE1A0C226CFC001DFA32 /* ConversionManagerFactory.h */; };
 		1948BEC10C226CFD001DFA32 /* CustomColours.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1948BE1B0C226CFC001DFA32 /* CustomColours.cpp */; };
 		1948BEC20C226CFD001DFA32 /* CustomColours.h in Headers */ = {isa = PBXBuildFile; fileRef = 1948BE1C0C226CFC001DFA32 /* CustomColours.h */; };
 		1948BEC30C226CFD001DFA32 /* DasherButtons.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1948BE1D0C226CFC001DFA32 /* DasherButtons.cpp */; };
@@ -439,8 +435,6 @@
 		1948BE000C226CFC001DFA32 /* GroupInfo.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = GroupInfo.h; sourceTree = "<group>"; };
 		1948BE020C226CFC001DFA32 /* AlphabetManager.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = AlphabetManager.cpp; sourceTree = "<group>"; };
 		1948BE030C226CFC001DFA32 /* AlphabetManager.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AlphabetManager.h; sourceTree = "<group>"; };
-		1948BE040C226CFC001DFA32 /* AlphabetManagerFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = AlphabetManagerFactory.cpp; sourceTree = "<group>"; };
-		1948BE050C226CFC001DFA32 /* AlphabetManagerFactory.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AlphabetManagerFactory.h; sourceTree = "<group>"; };
 		1948BE060C226CFC001DFA32 /* AutoSpeedControl.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = AutoSpeedControl.cpp; sourceTree = "<group>"; };
 		1948BE070C226CFC001DFA32 /* AutoSpeedControl.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AutoSpeedControl.h; sourceTree = "<group>"; };
 		1948BE080C226CFC001DFA32 /* BasicLog.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = BasicLog.cpp; sourceTree = "<group>"; };
@@ -458,8 +452,6 @@
 		1948BE160C226CFC001DFA32 /* ConversionHelper.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ConversionHelper.h; sourceTree = "<group>"; };
 		1948BE170C226CFC001DFA32 /* ConversionManager.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ConversionManager.cpp; sourceTree = "<group>"; };
 		1948BE180C226CFC001DFA32 /* ConversionManager.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ConversionManager.h; sourceTree = "<group>"; };
-		1948BE190C226CFC001DFA32 /* ConversionManagerFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ConversionManagerFactory.cpp; sourceTree = "<group>"; };
-		1948BE1A0C226CFC001DFA32 /* ConversionManagerFactory.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ConversionManagerFactory.h; sourceTree = "<group>"; };
 		1948BE1B0C226CFC001DFA32 /* CustomColours.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CustomColours.cpp; sourceTree = "<group>"; };
 		1948BE1C0C226CFC001DFA32 /* CustomColours.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CustomColours.h; sourceTree = "<group>"; };
 		1948BE1D0C226CFC001DFA32 /* DasherButtons.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DasherButtons.cpp; sourceTree = "<group>"; };
@@ -951,8 +943,6 @@
 				1948BDF80C226CFC001DFA32 /* Alphabet */,
 				1948BE020C226CFC001DFA32 /* AlphabetManager.cpp */,
 				1948BE030C226CFC001DFA32 /* AlphabetManager.h */,
-				1948BE040C226CFC001DFA32 /* AlphabetManagerFactory.cpp */,
-				1948BE050C226CFC001DFA32 /* AlphabetManagerFactory.h */,
 				1948BE060C226CFC001DFA32 /* AutoSpeedControl.cpp */,
 				1948BE070C226CFC001DFA32 /* AutoSpeedControl.h */,
 				1948BE080C226CFC001DFA32 /* BasicLog.cpp */,
@@ -973,8 +963,6 @@
 				1948BE160C226CFC001DFA32 /* ConversionHelper.h */,
 				1948BE170C226CFC001DFA32 /* ConversionManager.cpp */,
 				1948BE180C226CFC001DFA32 /* ConversionManager.h */,
-				1948BE190C226CFC001DFA32 /* ConversionManagerFactory.cpp */,
-				1948BE1A0C226CFC001DFA32 /* ConversionManagerFactory.h */,
 				1948BE1B0C226CFC001DFA32 /* CustomColours.cpp */,
 				1948BE1C0C226CFC001DFA32 /* CustomColours.h */,
 				1948BE1D0C226CFC001DFA32 /* DasherButtons.cpp */,
@@ -1443,7 +1431,6 @@
 				1948BEA50C226CFD001DFA32 /* AlphIO.h in Headers */,
 				1948BEA60C226CFD001DFA32 /* GroupInfo.h in Headers */,
 				1948BEA90C226CFD001DFA32 /* AlphabetManager.h in Headers */,
-				1948BEAB0C226CFD001DFA32 /* AlphabetManagerFactory.h in Headers */,
 				1948BEAD0C226CFD001DFA32 /* AutoSpeedControl.h in Headers */,
 				1948BEAF0C226CFD001DFA32 /* BasicLog.h in Headers */,
 				1948BEB10C226CFD001DFA32 /* CannaConversionHelper.h in Headers */,
@@ -1453,7 +1440,6 @@
 				1948BEB90C226CFD001DFA32 /* ControlManager.h in Headers */,
 				1948BEBC0C226CFD001DFA32 /* ConversionHelper.h in Headers */,
 				1948BEBE0C226CFD001DFA32 /* ConversionManager.h in Headers */,
-				1948BEC00C226CFD001DFA32 /* ConversionManagerFactory.h in Headers */,
 				1948BEC20C226CFD001DFA32 /* CustomColours.h in Headers */,
 				1948BEC40C226CFD001DFA32 /* DasherButtons.h in Headers */,
 				1948BEC60C226CFD001DFA32 /* DasherComponent.h in Headers */,
@@ -1810,7 +1796,6 @@
 				1948BEA20C226CFD001DFA32 /* AlphabetMap.cpp in Sources */,
 				1948BEA40C226CFD001DFA32 /* AlphIO.cpp in Sources */,
 				1948BEA80C226CFD001DFA32 /* AlphabetManager.cpp in Sources */,
-				1948BEAA0C226CFD001DFA32 /* AlphabetManagerFactory.cpp in Sources */,
 				1948BEAC0C226CFD001DFA32 /* AutoSpeedControl.cpp in Sources */,
 				1948BEAE0C226CFD001DFA32 /* BasicLog.cpp in Sources */,
 				1948BEB20C226CFD001DFA32 /* CircleStartHandler.cpp in Sources */,
@@ -1818,7 +1803,6 @@
 				1948BEB60C226CFD001DFA32 /* ColourIO.cpp in Sources */,
 				1948BEB80C226CFD001DFA32 /* ControlManager.cpp in Sources */,
 				1948BEBD0C226CFD001DFA32 /* ConversionManager.cpp in Sources */,
-				1948BEBF0C226CFD001DFA32 /* ConversionManagerFactory.cpp in Sources */,
 				1948BEC10C226CFD001DFA32 /* CustomColours.cpp in Sources */,
 				1948BEC30C226CFD001DFA32 /* DasherButtons.cpp in Sources */,
 				1948BEC50C226CFD001DFA32 /* DasherComponent.cpp in Sources */,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]