tagging release
[dasher.git] / trunk / Src / DasherCore / ConversionHelper.h
blobdd956fa59ad1f2336a44d68a6ab6ae47d77dd041
1 // ConversionHelper.h
2 //
3 // Copyright (c) 2007 The Dasher Team
4 //
5 // This file is part of Dasher.
6 //
7 // Dasher is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // Dasher is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with Dasher; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef __CONVERSION_HELPER_H__
22 #define __CONVERSION_HELPER_H__
24 #include <string>
25 #include <vector>
26 #include "SCENode.h"
27 #include "LanguageModelling/LanguageModel.h"
28 #include "LanguageModelling/PPMLanguageModel.h"
30 //THESE DEFINITIONS ARE SHARED BETWEEN PYCONVERSIONHELPER AND CONVERSIONMANAGER
31 #define MAX_CARE_CAND 100
32 #define MAX_CARE_PHRASE 20
33 #define MAX_HZ_NUM 50
34 #define MAX_CM_NUM 10
36 //trial change
37 namespace Dasher{
38 class CDasherNode; //trial forward declaration
41 /// \ingroup Model
42 /// @{
44 /// The CConversionHelper class represents the language specific
45 /// aspect of the conversion process. Each CConversionManager
46 /// references one helper, which performs the conversion itself, as
47 /// well as assigning weights to each of the predictions. See
48 /// CConversionManager for further details of the conversion process.
49 ///
50 class CConversionHelper {
51 public:
52 CConversionHelper() {
53 // TODO: Move all this further up the class hierarchy
54 colourStore[0][0]=66;//light blue
55 colourStore[0][1]=64;//very light green
56 colourStore[0][2]=62;//light yellow
57 colourStore[1][0]=78;//light purple
58 colourStore[1][1]=81;//brownish
59 colourStore[1][2]=60;//red
62 /// Convert a given string to a lattice of candidates. Sizes for
63 /// candidates aren't assigned at this point. The input string
64 /// should be UTF-8 encoded.
65 ///
66 /// @param strSource UTF-8 encoded input string.
67 /// @param pRoot Used to return the root of the conversion lattice.
68 /// @param childCount Unsure - document this.
69 /// @param CMid A unique identifier for the conversion helper 'context'.
70 ///
71 /// @return True if conversion succeeded, false otherwise
72 virtual bool Convert(const std::string &strSource, SCENode ** pRoot, int * childCount, int CMid) = 0;
74 /// Assign sizes to the children of a given conversion node. This
75 /// happens when the conversion manager populates the children of
76 /// the Dasher node so as to avoid unnecessary computation.
77 ///
78 /// @param pStart The parent of the nodes to be sized.
79 /// @param context Unsure - document this, shouldn't be in general class (include userdata pointer).
80 /// @param normalization Normalisation constant for the child sizes (TODO: check that this is a sensible value, ie the same as Dasher normalisation).
81 /// @param uniform Unsure - document this.
82 /// @param iNChildren The number of children to be expected (more efficient than iterating linked list).
83 ///
84 virtual void AssignSizes(SCENode ** pStart, Dasher::CLanguageModel::Context context, long normalization, int uniform, int iNChildren)=0;
86 //TODO: figure out why this function cannot return a CLanguageModel
87 virtual Dasher::CLanguageModel * GetLanguageModel()=0;
89 /* virtual bool GetPhraseList(int HZIndex, SCENode ** psOutput, int CMid)=0; */
90 /* virtual void BuildDataBase()=0; */
92 /// Clear any data associated with a given conversion context (not sure whether this is necessary any more)
93 ///
94 /// @param CMid The conversion context ID to clear
95 ///
96 virtual void ClearData(int CMid)=0;
98 /* virtual std::vector<std::vector<std::vector<std::vector<std::vector<int> > > > > * GetDP(int CMid)=0;//get data pointer */
100 /// Assign colours to the children of a given conversion node.
101 /// This function needs a rethink.
103 /// @param parentClr
104 /// @param pNode
105 /// @param childIndex
107 /// @return
108 ///
109 virtual int AssignColour(int parentClr, SCENode * pNode, int childIndex) {
110 int which = -1;
112 for (int i=0; i<2; i++)
113 for(int j=0; j<3; j++)
114 if (parentClr == colourStore[i][j])
115 which = i;
117 if(which == -1)
118 return colourStore[0][childIndex%3];
119 else if(which == 0)
120 return colourStore[1][childIndex%3];
121 else
122 return colourStore[0][childIndex%3];
125 std::vector<std::vector<std::vector<std::vector<std::vector<std::vector<int> > > > > >vContextData;
127 private:
128 int colourStore[2][3];
130 /// @}
131 #endif