FreeLing
4.0
|
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 _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(); 00059 00061 const std::list<std::wstring> get_matched() const; 00063 const std::list<std::pair<int,int> > get_backpath() const; 00065 bool active() const; 00067 void shift(int,int); 00068 00069 }; 00070 00074 00075 typedef std::list<edge> cell; 00076 00077 00082 00083 class chart { 00084 00085 private: 00086 00088 std::vector<cell> table; 00090 int size; 00092 const grammar &gram; 00093 00095 bool better_edge(const edge &, const edge&) const; 00097 std::list<std::pair<int,int> > cover (int a, int b) const; 00099 int index(int i, int j) const; 00102 bool can_extend(const std::wstring &, int, int) const; 00105 void find_all_rules(const edge &, cell &, int, int) const; 00107 bool check_match(const std::wstring &, const std::wstring &) const; 00108 00109 void dump() const; 00110 00111 public: 00113 chart(const grammar &); 00115 ~chart(); 00116 00118 int get_size() const; 00119 00121 void load_sentence(const sentence &, int k=0); 00122 00124 void parse(); 00125 00127 parse_tree get_tree(int, int, const std::wstring & =L"") const; 00128 }; 00129 00130 } // namespace 00131 00132 #endif 00133