~ubuntu-branches/ubuntu/oneiric/dasher/oneiric

« back to all changes in this revision

Viewing changes to Src/DasherCore/AlphabetManager.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2010-04-23 07:56:20 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100423075620-qpr1ousiruyxs1fb
Tags: 4.11-1
* New upstream release:
  + debian/control.in:
    - Update build dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef __alphabetmanager_h__
22
22
#define __alphabetmanager_h__
23
23
 
24
 
#include "NodeManager.h"
25
24
#include "LanguageModelling/LanguageModel.h"
26
 
 
 
25
#include "DasherNode.h"
27
26
#include "Parameters.h"
28
27
 
29
28
class CNodeCreationManager;
32
31
namespace Dasher {
33
32
 
34
33
  class CDasherInterfaceBase;
35
 
 
 
34
  
36
35
  /// \ingroup Model
37
36
  /// @{
38
37
 
41
40
  /// to the appropriate alphabet file, with sizes given by the
42
41
  /// language model.
43
42
  ///
44
 
  class CAlphabetManager : public CNodeManager {
45
 
  public:
46
 
 
47
 
    CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel, CLanguageModel::Context iLearnContext);
48
 
 
49
 
    ///
50
 
    /// Does nothing - alphabet manager isn't reference counted.
51
 
    ///
52
 
 
53
 
    virtual void Ref() {};
54
 
    
55
 
    ///
56
 
    /// Does nothing - alphabet manager isn't reference counted.
57
 
    ///
58
 
    
59
 
    virtual void Unref() {};
60
 
 
 
43
  class CAlphabetManager {
 
44
  public:
 
45
 
 
46
    CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, CLanguageModel *pLanguageModel);
 
47
 
 
48
  protected:
 
49
    class CGroupNode;
 
50
    class CAlphNode : public CDasherNode {
 
51
    public:
 
52
      int mgrId() {return 0;}
 
53
      CAlphNode(CDasherNode *pParent, int iLbnd, int iHbnd, CDasherNode::SDisplayInfo *pDispInfo, CAlphabetManager *pMgr);
 
54
      CLanguageModel::Context iContext;
 
55
      ///
 
56
      /// Delete any storage alocated for this node
 
57
      ///      
 
58
      virtual ~CAlphNode();
 
59
      virtual CLanguageModel::Context CloneAlphContext(CLanguageModel *pLanguageModel);
 
60
      CDasherNode *RebuildParent(int iNewOffset);
 
61
      ///Have to call this from CAlphabetManager, and from CGroupNode on a _different_ CAlphNode, hence public...
 
62
      virtual std::vector<unsigned int> *GetProbInfo();
 
63
      virtual int ExpectedNumChildren();
 
64
      CAlphabetManager *m_pMgr;
 
65
      virtual CDasherNode *RebuildSymbol(CAlphNode *pParent, symbol iSymbol, unsigned int iLbnd, unsigned int iHbnd)=0;
 
66
      virtual CGroupNode *RebuildGroup(CAlphNode *pParent, SGroupInfo *pInfo, unsigned int iLbnd, unsigned int iHbnd)=0;
 
67
    private:
 
68
      std::vector<unsigned int> *m_pProbInfo;
 
69
    };
 
70
    class CSymbolNode : public CAlphNode {
 
71
    public:
 
72
      CSymbolNode(CDasherNode *pParent, int iLbnd, int iHbnd, CDasherNode::SDisplayInfo *pDispInfo, CAlphabetManager *pMgr, symbol iSymbol);
 
73
      
 
74
      ///
 
75
      /// Provide children for the supplied node
 
76
      ///
 
77
 
 
78
      virtual void PopulateChildren();
 
79
      virtual CDasherNode *RebuildParent();
 
80
      virtual void Output(Dasher::VECTOR_SYMBOL_PROB* pAdded, int iNormalization);
 
81
      virtual void Undo();
 
82
 
 
83
      virtual void SetFlag(int iFlag, bool bValue);
 
84
 
 
85
      virtual bool GameSearchNode(std::string strTargetUtf8Char);
 
86
      virtual void GetContext(CDasherInterfaceBase *pInterface, std::vector<symbol> &vContextSymbols, int iOffset, int iLength);
 
87
      virtual symbol GetAlphSymbol();
 
88
      const symbol iSymbol;
 
89
      virtual CDasherNode *RebuildSymbol(CAlphNode *pParent, symbol iSymbol, unsigned int iLbnd, unsigned int iHbnd);
 
90
      virtual CGroupNode *RebuildGroup(CAlphNode *pParent, SGroupInfo *pInfo, unsigned int iLbnd, unsigned int iHbnd);
 
91
    };
 
92
 
 
93
    class CGroupNode : public CAlphNode {
 
94
    public:
 
95
      CGroupNode(CDasherNode *pParent, int iLbnd, int iHbnd, CDasherNode::SDisplayInfo *pDispInfo, CAlphabetManager *pMgr, SGroupInfo *pGroup);
 
96
      
 
97
      ///
 
98
      /// Provide children for the supplied node
 
99
      ///
 
100
      virtual CDasherNode *RebuildParent();
 
101
      virtual void PopulateChildren();
 
102
      virtual int ExpectedNumChildren();
 
103
      virtual bool GameSearchNode(std::string strTargetUtf8Char);
 
104
      virtual CDasherNode *RebuildSymbol(CAlphNode *pParent, symbol iSymbol, unsigned int iLbnd, unsigned int iHbnd);
 
105
      virtual CGroupNode *RebuildGroup(CAlphNode *pParent, SGroupInfo *pInfo, unsigned int iLbnd, unsigned int iHbnd);
 
106
      std::vector<unsigned int> *GetProbInfo();
 
107
    private:
 
108
      SGroupInfo *m_pGroup;
 
109
    };
 
110
    
 
111
  public:
61
112
    ///
62
113
    /// Get a new root node owned by this manager
63
 
    ///
64
 
 
65
 
    virtual CDasherNode *GetRoot(CDasherNode *pParent, int iLower, int iUpper, void *pUserData);
66
 
 
67
 
    ///
68
 
    /// Provide children for the supplied node
69
 
    ///
70
 
 
71
 
    virtual void PopulateChildren( CDasherNode *pNode );
72
 
    void PopulateChildrenWithSymbol( CDasherNode *pNode, int iExistingSymbol, CDasherNode *pExistingChild );
73
 
 
74
 
    ///
75
 
    /// Delete any storage alocated for this node
76
 
    ///
77
 
 
78
 
    virtual void ClearNode( CDasherNode *pNode );
79
 
 
80
 
    virtual void Output( CDasherNode *pNode, Dasher::VECTOR_SYMBOL_PROB* pAdded, int iNormalization);
81
 
    virtual void Undo( CDasherNode *pNode );
82
 
 
83
 
    virtual CDasherNode *RebuildParent(CDasherNode *pNode);
84
 
 
85
 
    virtual void SetFlag(CDasherNode *pNode, int iFlag, bool bValue);
86
 
 
87
 
    struct SRootData {
88
 
      char *szContext;
89
 
      int iOffset;
90
 
    };
91
 
 
92
 
 
93
 
    struct SAlphabetData {
94
 
      symbol iSymbol;
95
 
      int iPhase;
96
 
      CLanguageModel *pLanguageModel;
97
 
      CLanguageModel::Context iContext;
98
 
      int iGameOffset;
99
 
      int iOffset;
100
 
    };
101
 
 
102
 
 
103
 
  private:
104
 
    
105
 
    void BuildContext(std::string strContext, bool bRoot, CLanguageModel::Context &oContext, symbol &iSymbol);
106
 
 
107
 
    void RecursiveIterateGroup(CDasherNode *pParent, SGroupInfo *pInfo, std::vector<symbol> *pSymbols, std::vector<unsigned int> *pCProb, int iMin, int iMax, symbol iExistingSymbol, CDasherNode *pExistingChild);
108
 
 
109
 
    CDasherNode *CreateGroupNode(CDasherNode *pParent, SGroupInfo *pInfo, std::vector<unsigned int> *pCProb, unsigned int iStart, unsigned int iEnd, unsigned int iMin, unsigned int iMax);
110
 
    CDasherNode *CreateSymbolNode(CDasherNode *pParent, symbol iSymbol, std::vector<unsigned int> *pCProb, unsigned int iStart, unsigned int iEnd, unsigned int iMin, unsigned int iMax, symbol iExistingSymbol, CDasherNode *pExistingChild);
111
 
 
 
114
    /// bEnteredLast - true if this "root" node should be considered as entering the preceding symbol
 
115
    /// Offset is the index of the character which _child_ nodes (i.e. between which this root allows selection)
 
116
    /// will enter. (Also used to build context for preceding characters.)
 
117
    virtual CAlphNode *GetRoot(CDasherNode *pParent, int iLower, int iUpper, bool bEnteredLast, int iOffset);
 
118
 
 
119
  protected:
 
120
    ///
 
121
    /// Factory method for CAlphNode construction, so subclasses can override.
 
122
    ///
 
123
    virtual CSymbolNode *makeSymbol(CDasherNode *pParent, int iLbnd, int iHbnd, CDasherNode::SDisplayInfo *pDispInfo, symbol iSymbol);
 
124
    virtual CGroupNode *makeGroup(CDasherNode *pParent, int iLbnd, int iHbnd, CDasherNode::SDisplayInfo *pDispInfo, SGroupInfo *pGroup);
 
125
    
 
126
    virtual CDasherNode *CreateSymbolNode(CAlphNode *pParent, symbol iSymbol, unsigned int iLbnd, unsigned int iHbnd);
 
127
    virtual CLanguageModel::Context CreateSymbolContext(CAlphNode *pParent, symbol iSymbol);
 
128
    virtual CGroupNode *CreateGroupNode(CAlphNode *pParent, SGroupInfo *pInfo, unsigned int iLbnd, unsigned int iHbnd);
 
129
    
112
130
    CLanguageModel *m_pLanguageModel;
113
131
    CNodeCreationManager *m_pNCManager;
 
132
 
 
133
  private:
 
134
    
 
135
    void IterateChildGroups(CAlphNode *pParent, SGroupInfo *pParentGroup, CAlphNode *buildAround);
 
136
 
114
137
    CLanguageModel::Context m_iLearnContext;
115
138
    CDasherInterfaceBase *m_pInterface;
116
 
 
 
139
    
117
140
  };
118
 
  /// @}
 
141
/// @}
119
142
 
120
143
}
121
144