FreeLing  3.1
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 
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 // 
00036 
00037 #ifndef _IDIOMA_H
00038 #define _IDIOMA_H
00039 
00040 #include <map>
00041 #include <list>
00042 #include <vector>
00043 #include <string>
00044 
00045 namespace freeling {
00046 
00051 
00052   class idioma {  
00053 
00054   private:
00055     // language code
00056     std::wstring LangCode;
00058     std::map<std::wstring,double> pa_nom;
00060     std::map<std::wstring,double> ppi_nom;
00061 
00063     std::map<std::wstring,double> pi,A;
00065     std::map<std::pair<std::wstring,std::wstring>,double> tB,bB,uB;
00066 
00069     double scale;
00070 
00072     std::wstring from_writable(const std::wstring &) const;
00074     std::wstring to_writable(const std::wstring &) const;
00076     double ProbA(const std::wstring &, wchar_t) const;
00078     double ProbPi(const std::wstring &) const; 
00080     void increment(std::map<std::wstring,double> &, const std::wstring &, double n=1.0);
00082     void increment(std::map<std::pair<std::wstring,std::wstring>,double> &, const std::wstring &, const std::wstring &, double n=1.0);
00084     void initial_trigram(std::wistream &, wchar_t &, wchar_t &, wchar_t &) const;
00086     std::wstring trigram(wchar_t, wchar_t, wchar_t) const;
00088     void create_model(std::wistream &f);
00090     void save_model(const std::wstring &) const;
00091  
00092   public:
00094     idioma();
00096     idioma(const std::wstring &);
00098     double sequence_probability(std::wistream &, size_t &) const;
00100     double compute_probability(const std::wstring &, double s=1.0) const; 
00103     void train(const std::wstring &, const std::wstring &, const std::wstring&);
00104     void train(std::wistream &f, const std::wstring &, const std::wstring&);
00106     std::wstring get_language_code() const;
00107   };
00108 
00109 } // namespace
00110 
00111 #endif