FreeLing  4.0
idioma.h
Go to the documentation of this file.
00001 
00002 //
00003 //    Copyright (C) 2014   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 Affero General Public License
00008 //    (GNU AGPL) 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 //    Affero General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU Affero 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 #include "freeling/morfo/smoothingLD.h"
00046 
00047 namespace freeling {
00048 
00053 
00054   class idioma {  
00055 
00056   private:
00057     // language code
00058     std::wstring LangCode;
00059 
00061     std::map<std::wstring,double> count;
00062 
00064     wchar_t phantom;
00066     int order;
00068     double threshold;
00069 
00070     // smoother for ngram probabilities
00071     smoothingLD<std::wstring,wchar_t> *smooth;
00072 
00074     static std::wstring to_writable(wchar_t c);
00076     static std::wstring to_writable(const std::wstring &);
00077 
00079     static void initial_ngram(std::wistream &f, std::wstring &ngram, wchar_t &z, int ord, wchar_t ph);
00081     static void next_ngram(std::wistream &f, std::wstring &ngram, wchar_t &z);
00082  
00083   public:
00085     idioma(const std::wstring &);
00086     ~idioma();
00087 
00089     double sequence_probability(std::wistream &, size_t &) const;
00091     double compute_perplexity(const std::wstring &) const; 
00092 
00094     static void create_model(const std::wstring &modelFile,
00095                              std::wistream &f, 
00096                              const std::wstring &code, 
00097                              int order, 
00098                              wchar_t phantom);
00099       
00100 
00102     std::wstring get_language_code() const;
00104     double get_threshold() const;
00105   };
00106 
00107 } // namespace
00108 
00109 #endif