Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

LanguageModel.cpp

Go to the documentation of this file.
00001 // LanguageModel.cpp
00002 //
00004 //
00005 // Copyright (c) 2001-2002 David Ward
00006 //
00008 
00009 #include "LanguageModel.h"
00010 
00011 using namespace Dasher;
00012 using namespace std;
00013 
00014 // I have removed the following as it doesn't seem to compile in gcc:
00015 
00016 // using CLanguageModel::CNodeContext;
00017 
00019 
00020 CLanguageModel::CLanguageModel(CAlphabet* Alphabet, int Normalization)
00021         : m_Alphabet(Alphabet), m_iNorm(Normalization)
00022 {
00023         m_iModelChars = m_Alphabet->GetNumberSymbols();
00024 }
00025 
00026 
00028 
00029 void CLanguageModel::EnterText(CNodeContext* NodeContext, string TheText)
00030 {
00031         vector<symbol> Symbols;
00032         m_Alphabet->GetSymbols(&Symbols, &TheText, false);
00033         for (unsigned int i=0; i<Symbols.size(); i++)
00034                 EnterSymbol((CContext*) NodeContext, (modelchar) Symbols[i]);
00035 }
00036 
00038 
00039 void CLanguageModel::LearnText(CNodeContext* NodeContext, string* TheText, bool IsMore)
00040 {
00041         vector<symbol> Symbols;
00042         
00043         m_Alphabet->GetSymbols(&Symbols, TheText, IsMore);
00044         
00045         for (unsigned int i=0; i<Symbols.size(); i++)
00046                 LearnSymbol((CContext*) NodeContext, (modelchar) Symbols[i]);
00047 }
00048 
00050 
00051 bool CLanguageModel::GetNodeProbs(CNodeContext* Context, vector<symbol> &NewSymbols,
00052                 vector<unsigned int> &Groups, vector<unsigned int> &Probs, double AddProb)
00053 {
00054         // make sure it is a valid context
00055         if (Context) {
00056                 int s = m_Alphabet->GetNumberSymbols();
00057                 NewSymbols.resize(s);
00058                 Groups.resize(s);
00059                 for (int i=0;i<s;i++) {
00060                         NewSymbols[i]=i; // This will be replaced by something that works out valid nodes for this context
00061                         Groups[i]=m_Alphabet->get_group(i);
00062                 }
00063                 GetProbs((CContext*) Context,Probs,AddProb);
00064                 return true;
00065         }
00066         return false;
00067 }
00068 
00069 int CLanguageModel::GetColour(int character)
00070 {
00071   std::string colour=m_Alphabet->GetColour(character);
00072   if (colour!="") {
00073     return atoi(colour.c_str());
00074   } else {
00075     return 0;
00076   }
00077 }

Generated on Sat Nov 5 16:16:00 2005 for OPIE by  doxygen 1.4.2