FreeLing  3.0
idioma.h
Go to the documentation of this file.
00001 
00002 //
00003 //    Copyright (C) 2006   TALP Research Center
00004 //                         Universitat Politecnica de Catalunya
00005 //
00006 //    This library is free software; you can redistribute it and/or
00007 //    modify it under the terms of the GNU General Public License
00008 //    (GNU GPL) as published by the Free Software Foundation; either
00009 //    version 3 of the License, or (at your option) any later version.
00010 //
00011 //    This library is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00014 //    General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License 
00017 //    along with this library; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019 //
00020 //    contact: Muntsa Padro (mpadro@lsi.upc.edu)
00021 //             TALP Research Center
00022 //             despatx Omega.S107 - Campus Nord UPC
00023 //             08034 Barcelona.  SPAIN
00024 //
00026 
00027 // /////////////////////////////////
00028 //
00029 //  idioma.h
00030 //
00031 //  Class that implements a Visible Markov Model 
00032 //  to compute the probability that a text is 
00033 //  written in a certain language.
00034 // 
00035 // /////////////////////////////////
00036 
00037 #ifndef _IDIOMA_H
00038 #define _IDIOMA_H
00039 
00040 #include <map>
00041 #include <list>
00042 #include <vector>
00043 #include <string>
00044 
00045 
00048 
00049 class idioma {  
00050 
00051  private:
00052   // language code
00053   std::wstring LangCode;
00055   std::map<std::wstring,double> pa_nom;
00057   std::map<std::wstring,double> ppi_nom;
00058 
00060   std::map<std::wstring,double> pi,A;
00062   std::map<std::pair<std::wstring,std::wstring>,double> B;
00064   size_t nf;
00065 
00067   std::wstring from_writable(const std::wstring &) const;
00069   std::wstring to_writable(const std::wstring &) const;
00071   double ProbA(const std::wstring &, const std::wstring &) const;
00073   double ProbPi(const std::wstring &) const; 
00075   void increment(std::map<std::wstring,double> &, const std::wstring &);
00077   void increment(std::map<std::pair<std::wstring,std::wstring>,double> &, const std::wstring &, const std::wstring &);
00079   void initial_trigram(std::wistream &, wchar_t &, wchar_t &, wchar_t &) const;
00081   std::wstring trigram(wchar_t, wchar_t, wchar_t) const;
00083   void create_model(std::wistream &f);
00085   void save_model(const std::wstring &) const;
00086  
00087  public:
00089   idioma();
00091   idioma(const std::wstring &);
00093   double sequence_probability(std::wistream &, size_t &) const;
00095   double compute_probability(const std::wstring &, double s=1.0) const; 
00098   void train(const std::wstring &, const std::wstring &, const std::wstring&);
00099   void train(std::wistream &f, const std::wstring &, const std::wstring&);
00101   std::wstring get_language_code() const;
00102 };
00103 
00104 
00105 #endif