FreeLing  4.0
foma_FSM.h
Go to the documentation of this file.
00001 
00002 //
00003 //    FreeLing - Open Source Language Analyzers
00004 //
00005 //    Copyright (C) 2014   TALP Research Center
00006 //                         Universitat Politecnica de Catalunya
00007 //
00008 //    This library is free software; you can redistribute it and/or
00009 //    modify it under the terms of the GNU Affero General Public
00010 //    License as published by the Free Software Foundation; either
00011 //    version 3 of the License, or (at your option) any later version.
00012 //
00013 //    This library is distributed in the hope that it will be useful,
00014 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //    Affero General Public License for more details.
00017 //
00018 //    You should have received a copy of the GNU Affero General Public
00019 //    License along with this library; if not, write to the Free Software
00020 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00021 //
00022 //    contact: Lluis Padro (padro@lsi.upc.es)
00023 //             TALP Research Center
00024 //             despatx C6.212 - Campus Nord UPC
00025 //             08034 Barcelona.  SPAIN
00026 //
00028 
00029 #ifndef _FOMA_FSM_H
00030 #define _FOMA_FSM_H
00031 
00032 #include <sstream>
00033 #include <string>
00034 
00035 #ifndef _Bool
00036 typedef bool _Bool;
00037 #endif
00038 
00039 
00040 #include "foma/fomalib.h"
00041 
00042 
00043 namespace freeling {
00044 
00050 
00051   class WINDLL foma_FSM {
00052   private:
00054     struct fsm *fsa;
00056     struct apply_med_handle *h_fsa;
00057 
00059     struct fsm* load_dictionary_file(const std::wstring &fname) const;
00061     struct fsm* load_dictionary_buffer(std::wistream &buff) const;
00063     void load_cost_matrix(const std::wstring &mcost);
00065     void create_compound_FSA(const std::list<std::wstring> &joins);
00066 
00067     // Auxiliary for constructors: initialize FSM for minimum edit distance searches
00068     void init_MED();
00070     void complete_alphabet(const std::wstring &);
00071     // Auxiliary for constructor: Update FSM alphabet by composing it with Sigma* 
00072     void update_FSM_alphabet(const std::set<std::wstring> &);
00073 
00074   public:
00076     foma_FSM(const std::wstring &, const std::wstring &mcost=L"", 
00077              const std::list<std::wstring> &joins=std::list<std::wstring>());
00079     foma_FSM(std::wistream &, const std::wstring &mcost=L"", 
00080              const std::list<std::wstring> &joins=std::list<std::wstring>());
00082     ~foma_FSM();
00083 
00085     void get_similar_words(const std::wstring &, std::list<std::pair<std::wstring,int> > &) const;    
00087     void set_cutoff_threshold(int);
00089     void set_num_matches(int);
00091     void set_basic_operation_cost(int);
00093     void set_operation_cost(const std::wstring &, const std::wstring &, int);
00095     std::set<std::wstring> get_alphabet();
00096   };
00097 
00098 }
00099 
00100 #endif