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 _GRAMMAR 00030 #define _GRAMMAR 00031 00032 #include <string> 00033 #include <list> 00034 #include <map> 00035 #include <set> 00036 00037 namespace freeling { 00038 00042 00043 class rule { 00044 protected: 00046 std::wstring head; 00048 std::list<std::wstring> right; 00050 int gov; 00051 00052 public: 00054 rule(const std::wstring &, const std::list<std::wstring> &, const int); 00055 rule(const rule & r); 00056 rule(); 00057 rule & operator=(const rule&); 00058 00060 void set_governor(const int); 00062 unsigned int get_governor(void) const; 00064 std::wstring get_head() const; 00066 std::list<std::wstring> get_right() const; 00067 }; 00068 00073 00074 class grammar : public std::multimap<std::wstring,rule> { 00075 00076 private: 00078 std::set<std::wstring> nonterminal; 00080 std::multimap<std::wstring,rule> wild; 00082 std::multimap<std::wstring,std::wstring> filemap; 00084 std::map<std::wstring,int> prior; 00086 std::set<std::wstring> hidden; 00088 std::set<std::wstring> flat; 00090 std::set<std::wstring> notop; 00092 std::set<std::wstring> onlytop; 00094 std::wstring start; 00096 void new_rule(const std::wstring &, const std::list<std::wstring> &, bool, const int rgov); 00097 00098 public: 00099 00100 // no-governor mark 00101 static const unsigned int NOGOV; 00102 // default governor (first element in rule) 00103 static const unsigned int DEFGOV; 00104 00106 grammar(const std::wstring &); 00107 00108 // obtain the specificity of a terminal symbol 00109 int get_specificity(const std::wstring &) const; 00110 // obtain the priority of a non-terminal symbol 00111 int get_priority(const std::wstring &) const; 00113 std::wstring get_start_symbol() const; 00115 bool is_hidden(const std::wstring &) const; 00117 bool is_flat(const std::wstring &) const; 00119 bool is_notop(const std::wstring &) const; 00121 bool is_onlytop(const std::wstring &) const; 00123 bool is_terminal(const std::wstring &) const; 00125 std::list<rule> get_rules_right(const std::wstring &) const; 00127 std::list<rule> get_rules_right_wildcard(const std::wstring &) const; 00129 bool in_filemap(const std::wstring &, const std::wstring &) const; 00130 }; 00131 00132 } // namespace 00133 00134 #endif