[dasher] Make CConversionHelper a subclass of CConversionManager, rather than a delegate.



commit f201d6bdc80a00a278bc27f0551a4b237f561066
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Sat Aug 8 22:25:32 2009 +0200

    Make CConversionHelper a subclass of CConversionManager, rather than a delegate.
    (12-Jul-2009)

 ChangeLog                                   |    2 +
 Src/DasherCore/CannaConversionHelper.cpp    |    3 +-
 Src/DasherCore/CannaConversionHelper.h      |    2 +-
 Src/DasherCore/ConversionHelper.h           |  170 +++++++-----
 Src/DasherCore/ConversionManager.cpp        |  378 +--------------------------
 Src/DasherCore/ConversionManager.h          |   67 +----
 Src/DasherCore/ConversionManagerFactory.cpp |   18 +-
 Src/DasherCore/ConversionManagerFactory.h   |    8 +-
 Src/DasherCore/IMEConversionHelper.cpp      |    3 +-
 Src/DasherCore/IMEConversionHelper.h        |    2 +-
 Src/DasherCore/Makefile.am                  |    1 +
 Src/DasherCore/PinYinConversionHelper.cpp   |   13 +-
 Src/DasherCore/PinYinConversionHelper.h     |    5 +-
 Src/MacOSX/Dasher.xcodeproj/project.pbxproj |    6 +-
 14 files changed, 163 insertions(+), 515 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 81dae25..e87db22 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 2009-08-08  Alan Lawrence <acl33 inf phy cam ac uk>
 
 	* Tidy up ConversionManager and use a single instance per Factory.
+	* Make CConversionHelper a subclass of CConversionManager, rather than a
+	  delegate.
 
 2009-08-07  Alan Lawrence <acl33 inf phy cam ac uk>
 
diff --git a/Src/DasherCore/CannaConversionHelper.cpp b/Src/DasherCore/CannaConversionHelper.cpp
index b818c5a..77704eb 100644
--- a/Src/DasherCore/CannaConversionHelper.cpp
+++ b/Src/DasherCore/CannaConversionHelper.cpp
@@ -12,7 +12,8 @@
 
 #include <iostream>             //For testing 23 June 2005
 
-CCannaConversionHelper::CCannaConversionHelper(int Type, int Order) {
+CCannaConversionHelper::CCannaConversionHelper(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet, int Type, int Order)
+: CConversionHelper(pNCManager, pAlphabet) {
 
   int ret;
   char *buf;
diff --git a/Src/DasherCore/CannaConversionHelper.h b/Src/DasherCore/CannaConversionHelper.h
index 030a1b6..7c03bb6 100644
--- a/Src/DasherCore/CannaConversionHelper.h
+++ b/Src/DasherCore/CannaConversionHelper.h
@@ -11,7 +11,7 @@
 /// @{
 class CCannaConversionHelper : public CConversionHelper {
  public:
-  CCannaConversionHelper(int Type, int Order);
+  CCannaConversionHelper(CNodeCreationManager pNCManager, CAlphabet *pAlphabet, int Type, int Order);
   ~CCannaConversionHelper();
 
   virtual bool Convert(const std::string &strSource, SCENode ** pRoot, int * childCount, int CMid);
diff --git a/Src/DasherCore/ConversionHelper.h b/Src/DasherCore/ConversionHelper.h
index 3f634be..59be54f 100644
--- a/Src/DasherCore/ConversionHelper.h
+++ b/Src/DasherCore/ConversionHelper.h
@@ -21,6 +21,7 @@
 #ifndef __CONVERSION_HELPER_H__
 #define __CONVERSION_HELPER_H__
 
+#include "ConversionManager.h"
 #include <string>
 #include <vector>
 #include "SCENode.h"
@@ -28,10 +29,8 @@
 #include "LanguageModelling/PPMLanguageModel.h"
 
 
-//trial change
 namespace Dasher{
-  class CDasherNode;  //trial forward declaration
-}
+	class CDasherNode;  //forward declaration
 
 /// \ingroup Model
 /// @{
@@ -42,74 +41,107 @@ namespace Dasher{
 /// well as assigning weights to each of the predictions. See
 /// CConversionManager for further details of the conversion process.
 ///
-class CConversionHelper {
- public:
-  CConversionHelper() {
-    // TODO: Move all this further up the class hierarchy
-    colourStore[0][0]=66;//light blue
-    colourStore[0][1]=64;//very light green
-    colourStore[0][2]=62;//light yellow
-    colourStore[1][0]=78;//light purple
-    colourStore[1][1]=81;//brownish
-    colourStore[1][2]=60;//red
-  };
-
-  /// Convert a given string to a lattice of candidates. Sizes for
-  /// candidates aren't assigned at this point. The input string
-  /// should be UTF-8 encoded.
-  ///
-  /// @param strSource UTF-8 encoded input string.
-  /// @param pRoot Used to return the root of the conversion lattice.
-  /// @param childCount Unsure - document this.
-  /// @param CMid A unique identifier for the conversion helper 'context'.
-  ///
-  /// @return True if conversion succeeded, false otherwise
-  virtual bool Convert(const std::string &strSource, SCENode ** pRoot) = 0;
-
-  /// Assign sizes to the children of a given conversion node. This
-  /// happens when the conversion manager populates the children of
-  /// the Dasher node so as to avoid unnecessary computation.
-  ///
-  /// @param pStart The parent of the nodes to be sized.
-  /// @param context Unsure - document this, shouldn't be in general class (include userdata pointer).
-  /// @param normalization Normalisation constant for the child sizes (TODO: check that this is a sensible value, ie the same as Dasher normalisation).
-  /// @param uniform Unsure - document this.
-  /// @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.
-  ///
-  /// @param parentClr 
-  /// @param pNode 
-  /// @param childIndex 
-  ///
-  /// @return 
-  /// 
-  virtual int AssignColour(int parentClr, SCENode * pNode, int childIndex) {
-    int which = -1;
+  class CConversionHelper : public CConversionManager {
+  public:
+	CConversionHelper(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet);
+	
+	/// Convert a given string to a lattice of candidates. Sizes for
+	/// candidates aren't assigned at this point. The input string
+	/// should be UTF-8 encoded.
+	///
+	/// @param strSource UTF-8 encoded input string.
+	/// @param pRoot Used to return the root of the conversion lattice.
+	/// @param childCount Unsure - document this.
+	/// @param CMid A unique identifier for the conversion helper 'context'.
+	///
+	/// @return True if conversion succeeded, false otherwise
+	virtual bool Convert(const std::string &strSource, SCENode ** pRoot) = 0;
+	
+	/// Assign sizes to the children of a given conversion node. This
+	/// happens when the conversion manager populates the children of
+	/// the Dasher node so as to avoid unnecessary computation.
+	///
+	/// @param pStart The parent of the nodes to be sized.
+	/// @param context Unsure - document this, shouldn't be in general class (include userdata pointer).
+	/// @param normalization Normalisation constant for the child sizes (TODO: check that this is a sensible value, ie the same as Dasher normalisation).
+	/// @param uniform Unsure - document this.
+	/// @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.
+	///
+	/// @param parentClr 
+	/// @param pNode 
+	/// @param childIndex 
+	///
+	/// @return 
+	/// 
+	virtual int AssignColour(int parentClr, SCENode * pNode, int childIndex) {
+		int which = -1;
+		
+		for (int i=0; i<2; i++)
+			for(int j=0; j<3; j++)
+				if (parentClr == colourStore[i][j])
+					which = i;
+		
+		if(which == -1)
+			return colourStore[0][childIndex%3];
+		else if(which == 0)
+			return colourStore[1][childIndex%3];
+		else 
+			return colourStore[0][childIndex%3]; 
+	};
+	
+    ///
+    /// Get a new root node owned by this manager
+    ///
+	
+    virtual CDasherNode *GetRoot(CDasherNode *pParent, int iLower, int iUpper, void *pUserData);
+	
+    ///
+    /// Calculate sizes for each of the children - default
+    /// implementation assigns decending probabilities in a power law
+    /// fashion (so assumes ordering), but specific subclasses are
+    /// free to implement their own behaviour. The only restriction is
+    /// that sizes should be posivive and sum to the appropriate
+    /// normalisation constant
+    ///
     
-    for (int i=0; i<2; i++)
-      for(int j=0; j<3; j++)
-	if (parentClr == colourStore[i][j])
-	  which = i;
+    virtual void AssignChildSizes(SCENode **pNode, CLanguageModel::Context context, int iNChildren);
+	
+	///
+    /// Provide children for the supplied node
+    ///
+	
+    virtual void PopulateChildren( CDasherNode *pNode );
+    	
+	virtual void SetFlag(CDasherNode *pNode, int iFlag, bool bValue);
+
+private:
+	
+    /// 
+    /// Build the conversion tree (lattice) for the given string -
+    /// evaluated late to prevent unnecessary conversions when the
+    /// children of the root node are never instantiated
+    ///
     
-    if(which == -1)
-      return colourStore[0][childIndex%3];
-    else if(which == 0)
-      return colourStore[1][childIndex%3];
-    else 
-      return colourStore[0][childIndex%3]; 
+    void BuildTree(CDasherNode *pRoot);
+	
+    ///
+    /// Language model (TODO: We don't need to know about this, surely)
+    ///
+	
+    CLanguageModel *m_pLanguageModel;
+	
+    CLanguageModel::Context m_iLearnContext;
+	
+	int colourStore[2][3]; 
   };
-  
-  std::vector<std::vector<std::vector<std::vector<std::vector<std::vector<int> > > > > >vContextData;
-
- private:
-  int colourStore[2][3]; 
-};
 /// @}
+}
 #endif
diff --git a/Src/DasherCore/ConversionManager.cpp b/Src/DasherCore/ConversionManager.cpp
index d9ed54f..5b3b6f0 100644
--- a/Src/DasherCore/ConversionManager.cpp
+++ b/Src/DasherCore/ConversionManager.cpp
@@ -26,6 +26,7 @@
 #include "Event.h"
 #include "EventHandler.h"
 #include "NodeCreationManager.h"
+#include "DasherModel.h"
 
 #include <iostream>
 #include <cstring>
@@ -38,22 +39,11 @@
 
 using namespace Dasher;
 
-CConversionManager::CConversionManager(CNodeCreationManager *pNCManager, CConversionHelper *pHelper, CAlphabet *pAlphabet) 
+CConversionManager::CConversionManager(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet) 
   : CNodeManager(2) {
 
   m_pNCManager = pNCManager;
-  m_pHelper = pHelper;
   m_pAlphabet = pAlphabet;
-   
-  //DOESN'T SEEM INTRINSIC
-  //and check why pHelper may be empty
-  if(pHelper)
-    m_pLanguageModel = pNCManager->GetLanguageModel();
-  else
-    m_pLanguageModel = NULL;
-
-  if(m_pLanguageModel)
-    m_iLearnContext = m_pLanguageModel->CreateEmptyContext();
 
   m_iRefCount = 1;
 
@@ -95,130 +85,13 @@ CDasherNode *CConversionManager::GetRoot(CDasherNode *pParent, int iLower, int i
   pNodeUserData->bisRoot = true;
   pNodeUserData->iOffset = iOffset + 1;
 
-  if(m_pHelper)
-    pNodeUserData->pLanguageModel = m_pLanguageModel;
-  else
-    pNodeUserData->pLanguageModel = NULL;
+  pNodeUserData->pLanguageModel = NULL;
   
-  if(m_pLanguageModel) {
-    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); 
-    }
-    else{
-    CLanguageModel::Context iContext;
-    iContext = m_pLanguageModel->CreateEmptyContext();
-    pNodeUserData->iContext = iContext;
-    }
-  }
-
-  
-
   pNodeUserData->pSCENode = 0;
 
   return pNewNode;
 }
 
-// TODO: This function needs to be significantly tidied up
-// TODO: get rid of pSizes
-
-void CConversionManager::AssignChildSizes(SCENode **pNode, CLanguageModel::Context context, int iNChildren) {
-  DASHER_ASSERT(m_pHelper);
-
-    // Calculate sizes for the children. Note that normalisation is
-    // done additiviely rather than multiplicatively, so it's not
-    // quite what was originally planned (but I don't think this is
-    // much of a problem). More serious is the fact that the ordering
-    // is being lost when the tree is created, as nodes begininning
-    // with the same character are merged. This needs to be though
-    // out, but the probabilities should probably be done at the time
-    // of construction of the candidate tree rather than the Dasher
-    // tree (aside - is there any real point having two separate trees
-    // - surely we should just create Dasher nodes right away?).
-    //
-    // The algorithm should also allow for the possibility of the
-    // conversion engine returning probabilities itself, which should
-    // be used in preference to the values infered from the ordering
-    //
-    // Finally, maybe the choices should be presented in lexographic
-    // order, rather than in order returned (really not sure about
-    // this - it needs to be thought through).
-
-
-    //    std::cout << "b" << std::endl;
-
-    //TESTING FOR CALCULATESCORE STAGE 1
-    //int test;
-    //test = CalculateScore(pNode, 1);
-    //std::cout<<"current character"<<pCurrentSCENode->pszConversion<<std::endl;
-    //std::cout<<"the score for the second candidate is"<<test<<std::endl;
-
-
-
-    //ASSIGNING SCORES AND CALCULATING NODE SIZE
-    //Ph: feel free to edit this part to make it more structured
-//     int iSize[pCurrentSCEChild->IsHeadAndCandNum];
-//     int score[pCurrentSCEChild->IsHeadAndCandNum];
-//     int total =0;
-//     int max = 0;
-//     int CandNum = pCurrentSCEChild -> IsHeadAndCandNum;
-
-// CHANGE    int iRemaining(m_pNCManager->GetLongParameter(LP_NORMALIZATION));
-
-    // Thoughts on the general idea here - this is very close to being
-    // a fully fledged language model, so I think we should go with
-    // that idea, but maybe we need something mode flexible. I'd
-    // imagine:
-    //
-    // 1. Probabilities provided directly with translation? Maybe hard
-    // 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.
-    //
-    // Tempted to assume (1) and (2) can be implemented together, with
-    // a second call to the library at node creation time, and (3) can
-    // be implemented as a fallback if that doesn't work.
-    //
-    // 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];
-  //       if(i!=0)
-  // 	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;
-  }
-
-  //  std::cout<<"iNChildren: "<<iNChildren<<std::endl;
-  m_pHelper->AssignSizes(pNode, context, m_pNCManager->GetLongParameter(LP_NORMALIZATION), m_pNCManager->GetLongParameter(LP_UNIFORM), iNChildren);
-
-  
-}
 
 void CConversionManager::PopulateChildren( CDasherNode *pNode ) {
   DASHER_ASSERT(m_pNCManager);
@@ -230,194 +103,20 @@ void CConversionManager::PopulateChildren( CDasherNode *pNode ) {
   // alphabet root. This should only happen in error cases, and the
   // user should have been warned here.
   //
-  if(!m_pHelper) {
-    int iLbnd(0);
-    int iHbnd(m_pNCManager->GetLongParameter(LP_NORMALIZATION)); 
-    
-
-    CAlphabetManager::SRootData oRootData;
-    oRootData.szContext = NULL;
-    oRootData.iOffset = pCurrentDataNode->iOffset + 1;
-
-    pNewNode = m_pNCManager->GetRoot(0, pNode, iLbnd, iHbnd, &oRootData);
-    pNewNode->SetFlag(NF_SEEN, false);
-    
-    pNode->Children().push_back(pNewNode);
-
-    return;
-  }
-
-  // Do the conversion and build the tree (lattice) if it hasn't been
-  // done already.
-  //
-  
-
-  if(pCurrentDataNode->bisRoot) {
-    BuildTree(pNode);
-  }
-
-  SCENode *pCurrentSCEChild;
-
-  if(pCurrentDataNode->pSCENode){
-    
-    //    RecursiveDumpTree(pCurrentDataNode->pSCENode, 1);
-    pCurrentSCEChild = pCurrentDataNode->pSCENode->GetChild();
-
-  }
-  else {
-    //    if(m_pRoot && !pCurrentDataNode->bType)
-    //  pCurrentSCEChild = m_pRoot[0];
-    //else
-      pCurrentSCEChild = 0;
-  }
-  
-  if(pCurrentSCEChild) {
-    //    std::cout<<"Populating character nodes!"<<std::endl;
-    //    std::cout << "Current SCE Child: " << pCurrentSCEChild << std::endl;
-
-    // TODO: Reimplement (in subclass) -----
+  int iLbnd(0);
+  int iHbnd(m_pNCManager->GetLongParameter(LP_NORMALIZATION)); 
     
-//     if(m_iHZCount>1)
-//       if(!m_bPhrasesProcessed[pCurrentSCEChild->AcCharCount-1])
-//    	if(pCurrentSCEChild->AcCharCount<m_iHZCount)
-// 	  ProcessPhrase(pCurrentSCEChild->AcCharCount-1);
 
-    // -----
-
-    //int *iSize;
-    
-    //    iSize = new int[pCurrentSCEChild->IsHeadAndCandNum];
+  CAlphabetManager::SRootData oRootData;
+  oRootData.szContext = NULL;
+  oRootData.iOffset = pCurrentDataNode->iOffset + 1;
 
+  pNewNode = m_pNCManager->GetRoot(0, pNode, iLbnd, iHbnd, &oRootData);
+  pNewNode->SetFlag(NF_SEEN, false);
     
+  pNode->Children().push_back(pNewNode);
 
-    
-    AssignChildSizes(&pCurrentSCEChild, pCurrentDataNode->iContext, pCurrentSCEChild->IsHeadAndCandNum);
-
-    int iIdx(0);
-    int iCum(0);
-  
-    //    int parentClr = pNode->Colour();
-    // TODO: Fixme
-    int parentClr = 0;
-
-    // Finally loop through and create the children
-
-    do {
-      //      std::cout << "Current scec: " << pCurrentSCEChild << std::endl;
-
-      int iLbnd(iCum);
-      int iHbnd(iCum + pCurrentSCEChild->NodeSize);
-		//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 = m_pHelper->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();
-
-      SConversionData *pNodeUserData = new SConversionData;
-      pNodeUserData->bisRoot = false;
-      pNodeUserData->pSCENode = pCurrentSCEChild;
-      pNodeUserData->pLanguageModel = pCurrentDataNode->pLanguageModel;
-      pNodeUserData->iOffset = pCurrentDataNode->iOffset + 1;
-
-      if(pCurrentDataNode->pLanguageModel) {
-	CLanguageModel::Context iContext;
-	iContext = pCurrentDataNode->pLanguageModel->CloneContext(pCurrentDataNode->iContext);
-	
-	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();
-      ++iIdx;
-    }while(pCurrentSCEChild);
-
-  }
-
-  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)); 
-      
-      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);
-      //}
-    /* What do the following code do?
-    else {
-
-      std::cout<<"DOES IT EVER COME TO HERE?"<<std::endl;
-      int iLbnd(0);
-      int iHbnd(m_pNCManager->GetLongParameter(LP_NORMALIZATION)); 
-
-      CDasherNode::SDisplayInfo *pDisplayInfo = new CDasherNode::SDisplayInfo;
-      pDisplayInfo->iColour = m_pHelper->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();
-
-      SConversionData *pNodeUserData = new SConversionData;
-      pNodeUserData->bType = true;
-      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);
-    }
-    */
-  }
+  return;
 }
 
 void CConversionManager::ClearNode( CDasherNode *pNode ) {
@@ -451,34 +150,6 @@ void CConversionManager::RecursiveDumpTree(SCENode *pCurrent, unsigned int iDept
   */
 }
 
-void CConversionManager::BuildTree(CDasherNode *pRoot) {
-  DASHER_ASSERT(m_pHelper);
-
-  std::string strCurrentString; 
-
-  //Find the pinyin (roman) text (stored in Display text) of the previous alphabet node
-
-    CAlphabetManager::SAlphabetData *pRootAlphabetData = static_cast<CAlphabetManager::SAlphabetData *>(pRoot->m_pUserData);
-
-    //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;
-    bool ConversionSuccess = m_pHelper->Convert(strCurrentString, &pStartTemp); 
-    
-    
-    SConversionData *pRootConversionData = static_cast<CConversionManager::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 CConversionManager::Output( CDasherNode *pNode, Dasher::VECTOR_SYMBOL_PROB* pAdded, int iNormalization) {
   // TODO: Reimplement this
   //  m_pNCManager->m_bContextSensitive = true; 
@@ -529,28 +200,3 @@ void CConversionManager::Undo( CDasherNode *pNode ) {
     }
   }
 }
-
-void CConversionManager::SetFlag(CDasherNode *pNode, int iFlag, bool bValue) {
-  switch(iFlag) {
-  case NF_COMMITTED:
-    if(bValue){
-      //Blanked out for new Mandarin Dasher, if we want to have the language model learn as one types, need to work on this part
-
-      /*
-      CLanguageModel * pLan =  static_cast<SConversionData *>(pNode->m_pUserData)->pLanguageModel;
-
-      SCENode * pSCENode = static_cast<SConversionData *>(pNode->m_pUserData)->pSCENode; 
-
-      if(!pSCENode)
-	return;
-
-      symbol s =pSCENode ->Symbol;
-    
-     
-      if((s!=-1) && m_pLanguageModel)
-	pLan->LearnSymbol(m_iLearnContext, s);
-      */
-    }
-    break;
-  }
-}
diff --git a/Src/DasherCore/ConversionManager.h b/Src/DasherCore/ConversionManager.h
index f53e8f8..7a1463c 100644
--- a/Src/DasherCore/ConversionManager.h
+++ b/Src/DasherCore/ConversionManager.h
@@ -21,16 +21,12 @@
 #ifndef __conversion_manager_h__
 #define __conversion_manager_h__
 
-#include "ConversionHelper.h"
 #include "AlphabetManager.h"
-#include "DasherModel.h"
 #include "DasherTypes.h"
 #include "LanguageModelling/LanguageModel.h" // Urgh - we really shouldn't need to know about language models here
 #include "NodeManager.h"
 #include "SCENode.h"
 
-#include <vector>
-
 // TODO: Conversion manager needs to deal with offsets and contexts - Will: See Phil for an explanation.
 
 namespace Dasher {
@@ -64,7 +60,7 @@ namespace Dasher {
   class CConversionManager : public CNodeManager {
   public:
     // TODO: We shouldn't need to know about this stuff, but the code is somewhat in knots at the moment
-    CConversionManager(CNodeCreationManager *pNCManager, CConversionHelper *pHelper, CAlphabet *pAlphabet);
+    CConversionManager(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet);
 
     ///
     /// Increment reference count
@@ -97,17 +93,6 @@ namespace Dasher {
     virtual CDasherNode *GetRoot(CDasherNode *pParent, int iLower, int iUpper, void *pUserData);
 
     ///
-    /// Calculate sizes for each of the children - default
-    /// implementation assigns decending probabilities in a power law
-    /// fashion (so assumes ordering), but specific subclasses are
-    /// free to implement their own behaviour. The only restriction is
-    /// that sizes should be posivive and sum to the appropriate
-    /// normalisation constant
-    ///
-    
-    virtual void AssignChildSizes(SCENode **pNode, CLanguageModel::Context context, int iNChildren);
-
-    ///
     /// Provide children for the supplied node
     ///
 
@@ -152,8 +137,6 @@ namespace Dasher {
       return 0;
     }
 
-    virtual void SetFlag(CDasherNode *pNode, int iFlag, bool bValue);
-
     //TODO: REVISE
     struct SConversionData {
       symbol iSymbol;
@@ -165,50 +148,24 @@ namespace Dasher {
       int iOffset;
       //int iGameOffset;
     };
+	  
+  protected:
+	CNodeCreationManager *m_pNCManager;
+	CAlphabet *m_pAlphabet;
+	
   private:
 
     /// 
-    /// Build the conversion tree (lattice) for the given string -
-    /// evaluated late to prevent unnecessary conversions when the
-    /// children of the root node are never instantiated
-    ///
-    
-    void BuildTree(CDasherNode *pRoot);
-
-    /// 
     /// Dump tree to stdout (debug)
     ///
     
     void RecursiveDumpTree(SCENode *pCurrent, unsigned int iDepth);
-
-    ///
-    /// Dasher model (TODO: We ideally shouldn't need to know about this)
-    ///
-    
-    CNodeCreationManager *m_pNCManager;
-
-    ///
-    /// Language model (TODO: We don't need to know about this, surely)
-    ///
-
-    CLanguageModel *m_pLanguageModel;
-
-    ///
-    /// Conversion helper
-    ///
-    
-    CConversionHelper *m_pHelper;
-
-    CAlphabet *m_pAlphabet;
-
-    ///
-    /// Reference count 
-    ///
-
-
-    CLanguageModel::Context m_iLearnContext;
-
-    
+	  
+	///
+	/// Reference count 
+	///
+	  
+	  
     int m_iRefCount;
 
     ///
diff --git a/Src/DasherCore/ConversionManagerFactory.cpp b/Src/DasherCore/ConversionManagerFactory.cpp
index 3398af5..a61be32 100644
--- a/Src/DasherCore/ConversionManagerFactory.cpp
+++ b/Src/DasherCore/ConversionManagerFactory.cpp
@@ -2,7 +2,6 @@
 #include <config.h>
 #endif
 
-#include "ConversionManager.h"
 #include "ConversionManagerFactory.h"
 #include "DasherModel.h"
 
@@ -30,8 +29,7 @@ CConversionManagerFactory::CConversionManagerFactory(Dasher::CEventHandler *pEve
   m_pAlphabet = pAlphabet;
 
   // TODO: Need to deal with the case of GetHelper returning NULL
-  CConversionHelper *pHelper = GetHelper(pEventHandler, pSettingsStore, iID, pCAlphIO);
-  m_pMgr = new CConversionManager(m_pNCManager, pHelper, m_pAlphabet);
+  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
@@ -49,16 +47,16 @@ CConversionManagerFactory::~CConversionManagerFactory() {
 
 // TODO: Japanese/Chinese are currently disabled in Win32 - see 'exclude from build' on individual files' property pages, plus preprocessor defines
 
-CConversionHelper *CConversionManagerFactory::GetHelper(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, int iID, Dasher::CAlphIO *pCAlphIO) {
+CConversionManager *CConversionManagerFactory::GetHelper(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, int iID, Dasher::CAlphIO *pCAlphIO) {
   switch(iID) {
   case 0: // No conversion required (shouldn't really be called)
-    return NULL;
+	return NULL; //or, new CConversionManager(m_pNCManager, pHelper, m_pAlphabet); ??
   case 1: // Japanese
 #ifdef JAPANESE
 #ifdef WIN32
     return new CIMEConversionHelper;
 #else
-    return new CCannaConversionHelper(pSettingsStore->GetLongParameter(LP_CONVERSION_TYPE), pSettingsStore->GetLongParameter(LP_CONVERSION_ORDER));
+    return new CCannaConversionHelper(m_pNCManager, m_pAlphabet, pSettingsStore->GetLongParameter(LP_CONVERSION_TYPE), pSettingsStore->GetLongParameter(LP_CONVERSION_ORDER));
 #endif
 #else
     return NULL;
@@ -67,17 +65,17 @@ CConversionHelper *CConversionManagerFactory::GetHelper(Dasher::CEventHandler *p
     return GetHelperChinese(pEventHandler, pSettingsStore, pCAlphIO);
   default:
     // TODO: Error reporting here
-    return NULL;
+    return new CConversionManager(m_pNCManager, m_pAlphabet);
   }
 }
 
-CConversionHelper *CConversionManagerFactory::GetHelperChinese(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, Dasher::CAlphIO *pCAlphIO) {
+CConversionManager *CConversionManagerFactory::GetHelperChinese(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, Dasher::CAlphIO *pCAlphIO) {
 #ifdef CHINESE
   std::string strCHAlphabetPath = pSettingsStore->GetStringParameter(SP_SYSTEM_LOC);
   strCHAlphabetPath += "/alphabet.chineseRuby.xml";
 
-  return new CPinYinConversionHelper(pEventHandler,pSettingsStore, pCAlphIO, strCHAlphabetPath, m_pAlphabet, m_pNCManager->GetLanguageModel());
+  return new CPinYinConversionHelper(m_pNCManager, pEventHandler,pSettingsStore, pCAlphIO, strCHAlphabetPath, m_pAlphabet);
 #else
-  return NULL;
+  return NULL; //or, new ConversionManager(m_pNCManager, m_pAlphabet); ??
 #endif
 }
diff --git a/Src/DasherCore/ConversionManagerFactory.h b/Src/DasherCore/ConversionManagerFactory.h
index 1cccb21..a07db8a 100644
--- a/Src/DasherCore/ConversionManagerFactory.h
+++ b/Src/DasherCore/ConversionManagerFactory.h
@@ -1,16 +1,14 @@
 #ifndef __conversion_manager_factory_h__
 #define __conversion_manager_factory_h__
 
-#include "ConversionHelper.h"
 #include "ConversionManager.h"
-//#include "DasherModel.h"
 #include "LanguageModelling/LanguageModel.h" // Urgh - we really shouldn't need to know about language models here
+#include "alphabet/AlphIO.h"
 
 #include <map>
 
 namespace Dasher {
   class CDasherModel; // Forward declaraion
-  class CConversionManager;
 
   /// \ingroup Model
   /// @{
@@ -21,9 +19,9 @@ namespace Dasher {
     ~CConversionManagerFactory();
 	  
   private:
-    CConversionHelper *GetHelper(Dasher::CEventHandler *pEventHandler,  CSettingsStore *pSettingsStore, int iID, Dasher::CAlphIO *pCAlphIO);
+    CConversionManager *GetHelper(Dasher::CEventHandler *pEventHandler,  CSettingsStore *pSettingsStore, int iID, Dasher::CAlphIO *pCAlphIO);
 
-    CConversionHelper *GetHelperChinese(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, Dasher::CAlphIO *pCAlphIO);
+    CConversionManager *GetHelperChinese(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, Dasher::CAlphIO *pCAlphIO);
 
     CNodeCreationManager *m_pNCManager;
     CConversionManager *m_pMgr;
diff --git a/Src/DasherCore/IMEConversionHelper.cpp b/Src/DasherCore/IMEConversionHelper.cpp
index ff4d350..3e40373 100644
--- a/Src/DasherCore/IMEConversionHelper.cpp
+++ b/Src/DasherCore/IMEConversionHelper.cpp
@@ -7,7 +7,8 @@
 
 #include <iostream>             //For testing 23 June 2005
 
-CIMEConversionHelper::CIMEConversionHelper() {
+CIMEConversionHelper::CIMEConversionHelper(Dasher::CNodeCreationManager *pNCManager, Dasher::CAlphabet *pAlphabet)
+ : CConversionHelper(pNCManager, pAlphabet) {
   IsInit = 0;
   hIMC = ImmCreateContext();
   IsInit = 1;
diff --git a/Src/DasherCore/IMEConversionHelper.h b/Src/DasherCore/IMEConversionHelper.h
index 3e8df94..3f47aea 100644
--- a/Src/DasherCore/IMEConversionHelper.h
+++ b/Src/DasherCore/IMEConversionHelper.h
@@ -9,7 +9,7 @@
 /// \{
 class CIMEConversionHelper : public CConversionHelper {
  public:
-  CIMEConversionHelper();
+  CIMEConversionHelper(CNodeCreationManager *pNCManager, CAlphabet *pAlphabet);
   ~CIMEConversionHelper();
 
   virtual bool Convert(const std::string &strSource, std::vector<std::vector<std::string> > &vResult);
diff --git a/Src/DasherCore/Makefile.am b/Src/DasherCore/Makefile.am
index 74ffecb..df79cff 100644
--- a/Src/DasherCore/Makefile.am
+++ b/Src/DasherCore/Makefile.am
@@ -35,6 +35,7 @@ libdashercore_a_SOURCES = \
 		ColourIO.h \
 		ControlManager.cpp \
 		ControlManager.h \
+		ConversionHelper.cpp \
 		ConversionHelper.h \
 		ConversionManager.cpp \
 		ConversionManager.h \
diff --git a/Src/DasherCore/PinYinConversionHelper.cpp b/Src/DasherCore/PinYinConversionHelper.cpp
index 379f2a4..0cec404 100644
--- a/Src/DasherCore/PinYinConversionHelper.cpp
+++ b/Src/DasherCore/PinYinConversionHelper.cpp
@@ -16,10 +16,11 @@
 
 using namespace Dasher;
 
-CPinYinConversionHelper::CPinYinConversionHelper(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, Dasher::CAlphIO *pCAlphIO, const std::string strCHAlphabetPath, CAlphabet * pAlphabet, CLanguageModel * pLanguageModel){
+CPinYinConversionHelper::CPinYinConversionHelper(CNodeCreationManager *pNCManager, Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, Dasher::CAlphIO *pCAlphIO, const std::string strCHAlphabetPath, CAlphabet * pAlphabet)
+: CConversionHelper(pNCManager,pAlphabet) {
 
   m_pPYAlphabet = pAlphabet;
-  m_pLanguageModel = static_cast<CPPMPYLanguageModel *>(pLanguageModel);
+  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)";
@@ -231,5 +232,9 @@ void CPinYinConversionHelper::AssignSizes(SCENode **pStart, Dasher::CLanguageMod
     //    std::cout<<"Not equal! sum is "<<sumSize<<std::endl;
 //  }
 
-
-
+void CPinYinConversionHelper::SetFlag(CDasherNode *pNode, int iFlag, bool bValue)
+{
+	//Blanked out for new Mandarin Dasher, if we want to have the language model learn as one types, need to work on this part
+	if (iFlag == NF_COMMITTED && bValue) return;
+	CConversionHelper::SetFlag(pNode, iFlag, bValue);
+}
\ No newline at end of file
diff --git a/Src/DasherCore/PinYinConversionHelper.h b/Src/DasherCore/PinYinConversionHelper.h
index 196816d..073d361 100644
--- a/Src/DasherCore/PinYinConversionHelper.h
+++ b/Src/DasherCore/PinYinConversionHelper.h
@@ -18,7 +18,7 @@ namespace Dasher {
 class CPinYinConversionHelper : public CConversionHelper {
  public:
 
-  CPinYinConversionHelper(Dasher::CEventHandler *pEventHandler,  CSettingsStore *pSettingsStore, Dasher::CAlphIO *pAlphIO, const std::string strCHAlphabetPath, Dasher::CAlphabet * pAlphabet, Dasher::CLanguageModel * pLanguageModel);
+  CPinYinConversionHelper(CNodeCreationManager *pNCManager, Dasher::CEventHandler *pEventHandler,  CSettingsStore *pSettingsStore, Dasher::CAlphIO *pAlphIO, const std::string strCHAlphabetPath, Dasher::CAlphabet * pAlphabet);
   
   virtual bool Convert(const std::string &strSource, SCENode ** pRoot);
 
@@ -32,6 +32,9 @@ class CPinYinConversionHelper : public CConversionHelper {
     return m_pLanguageModel;
   }
 
+  //override to blank out learn-as-write for Mandarin Dasher
+  virtual void SetFlag(CDasherNode *pNode, int iFlag, bool bValue);
+	
  private:
      
   void TrainChPPM(CSettingsStore *pSettingsStore);
diff --git a/Src/MacOSX/Dasher.xcodeproj/project.pbxproj b/Src/MacOSX/Dasher.xcodeproj/project.pbxproj
index a69b8ee..6f3b68d 100755
--- a/Src/MacOSX/Dasher.xcodeproj/project.pbxproj
+++ b/Src/MacOSX/Dasher.xcodeproj/project.pbxproj
@@ -360,6 +360,7 @@
 		3306E1F80FFE6CAD0017324C /* Trainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3306E1F60FFE6CAD0017324C /* Trainer.h */; };
 		3306E33D0FFFB9880017324C /* MandarinAlphMgr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3306E33B0FFFB9880017324C /* MandarinAlphMgr.cpp */; };
 		3306E33E0FFFB9880017324C /* MandarinAlphMgr.h in Headers */ = {isa = PBXBuildFile; fileRef = 3306E33C0FFFB9880017324C /* MandarinAlphMgr.h */; };
+		335901B41009E5A900821255 /* ConversionHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 335901B31009E5A900821255 /* ConversionHelper.cpp */; };
 		335DB0FB100B332C006DB155 /* alphabet.spyDict.xml in Resources */ = {isa = PBXBuildFile; fileRef = 335DB0FA100B332C006DB155 /* alphabet.spyDict.xml */; };
 		335DB101100B3358006DB155 /* training_spyDict.txt in Resources */ = {isa = PBXBuildFile; fileRef = 335DB100100B3358006DB155 /* training_spyDict.txt */; };
 		335DB122100B3606006DB155 /* PinYinConversionHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1948BE760C226CFD001DFA32 /* PinYinConversionHelper.cpp */; };
@@ -780,9 +781,10 @@
 		3306E1F60FFE6CAD0017324C /* Trainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Trainer.h; sourceTree = "<group>"; };
 		3306E33B0FFFB9880017324C /* MandarinAlphMgr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MandarinAlphMgr.cpp; sourceTree = "<group>"; };
 		3306E33C0FFFB9880017324C /* MandarinAlphMgr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MandarinAlphMgr.h; sourceTree = "<group>"; };
+		335901B31009E5A900821255 /* ConversionHelper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConversionHelper.cpp; sourceTree = "<group>"; };
 		335DB0FA100B332C006DB155 /* alphabet.spyDict.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = alphabet.spyDict.xml; sourceTree = "<group>"; };
 		335DB100100B3358006DB155 /* training_spyDict.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = training_spyDict.txt; sourceTree = "<group>"; };
-		33ABFEC40FC379EA00EA2BA5 /* ButtonMultiPress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ButtonMultiPress.cpp; sourceTree = "<group>"; };
+		33ABFEC40FC379EA00EA2BA5 /* ButtonMultiPress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ButtonMultiPress.cpp; path = ../DasherCore/ButtonMultiPress.cpp; sourceTree = SOURCE_ROOT; };
 		33ABFEC50FC379EA00EA2BA5 /* ButtonMultiPress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ButtonMultiPress.h; sourceTree = "<group>"; };
 		33E173A70F3E0B6400D19B38 /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Makefile.am; sourceTree = "<group>"; };
 		33E173A80F3E0B6400D19B38 /* training_albanian_SQ.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = training_albanian_SQ.txt; sourceTree = "<group>"; };
@@ -954,6 +956,7 @@
 				1948BE110C226CFC001DFA32 /* ColourIO.h */,
 				1948BE120C226CFC001DFA32 /* ControlManager.cpp */,
 				1948BE130C226CFC001DFA32 /* ControlManager.h */,
+				335901B31009E5A900821255 /* ConversionHelper.cpp */,
 				1948BE160C226CFC001DFA32 /* ConversionHelper.h */,
 				1948BE170C226CFC001DFA32 /* ConversionManager.cpp */,
 				1948BE180C226CFC001DFA32 /* ConversionManager.h */,
@@ -1864,6 +1867,7 @@
 				3306E1F70FFE6CAD0017324C /* Trainer.cpp in Sources */,
 				3306E33D0FFFB9880017324C /* MandarinAlphMgr.cpp in Sources */,
 				335DB122100B3606006DB155 /* PinYinConversionHelper.cpp in Sources */,
+				335901B41009E5A900821255 /* ConversionHelper.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};



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