FreeLing
3.1
|
00001 00002 // 00003 // FreeLing - Open Source Language Analyzers 00004 // 00005 // Copyright (C) 2004 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 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 // General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU 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 _CHART 00030 #define _CHART 00031 00032 #include <list> 00033 #include <vector> 00034 #include <string> 00035 00036 #include "freeling/morfo/language.h" 00037 #include "freeling/morfo/grammar.h" 00038 00039 namespace freeling { 00040 00044 00045 class edge : public rule { 00046 00047 private: 00049 std::list<std::wstring> matched; 00050 // list of cells that matched the currently solved part of the edge. 00051 // (-1,-1) stands for unary rules producing cell self-references. 00052 std::list<std::pair<int,int> > backpath; 00053 00054 public: 00056 edge(const std::wstring&, const std::list<std::wstring> &, const int posgov); 00057 edge(); 00058 // edge(const edge &e); 00059 // edge & operator=(const edge &e); 00060 00062 const std::list<std::wstring> get_matched() const; 00064 const std::list<std::pair<int,int> > get_backpath() const; 00066 bool active() const; 00068 void shift(int,int); 00069 00070 }; 00071 00075 00076 class cell : public std::list<edge> {}; 00077 00078 00083 00084 class chart : std::vector<cell> { 00085 00086 private: 00087 00089 int size; 00090 const grammar *gram; 00091 00093 bool better_edge(const edge &, const edge&) const; 00095 std::list<std::pair<int,int> > cover (int a, int b) const; 00097 int index(int i, int j) const; 00100 bool can_extend(const std::wstring &, int, int) const; 00103 void find_all_rules(const edge &, cell &, int, int) const; 00105 bool check_match(const std::wstring &, const std::wstring &) const; 00106 00107 void dump() const; 00108 00109 public: 00111 chart(); 00112 00114 int get_size() const; 00116 cell get_cell(int, int) const; 00117 00119 void load_sentence(const sentence &, int k=0); 00120 00122 void set_grammar(const grammar &); 00123 00125 void parse(); 00126 00128 parse_tree get_tree(int, int, const std::wstring & =L"") const; 00129 }; 00130 00131 } // namespace 00132 00133 #endif 00134