|
FreeLing
3.0
|
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 00030 #ifndef _DEPRULES 00031 #define _DEPRULES 00032 00033 #include <sstream> 00034 #include <iostream> 00035 #include <set> 00036 #include <list> 00037 #include <boost/regex/icu.hpp> 00038 00039 #include "freeling/morfo/language.h" 00040 #include "freeling/morfo/semdb.h" 00041 00048 00049 class completerRule { 00050 00051 public: 00053 std::wstring leftChk; 00054 std::wstring rightChk; 00056 std::list<std::wstring> leftConds; 00057 std::list<std::wstring> rightConds; 00059 boost::u32regex leftRE; 00060 boost::u32regex rightRE; 00062 std::wstring newNode1; 00063 std::wstring newNode2; 00065 std::wstring operation; 00067 std::wstring context; 00069 bool context_neg; 00071 int weight; 00073 parse_tree::iterator last; 00074 00076 std::set<std::wstring> enabling_flags; 00078 std::set<std::wstring> flags_toggle_on; 00080 std::set<std::wstring> flags_toggle_off; 00081 00083 int line; 00084 00086 completerRule(); 00087 completerRule(const std::wstring &, const std::wstring &, const std::wstring&); 00088 completerRule( const completerRule &); 00090 completerRule & operator=( const completerRule &); 00091 00093 int operator<(const completerRule & a ) const; 00094 }; 00095 00096 00104 class rule_expression { 00105 00106 private: 00107 void parse_node_ref(std::wstring, dep_tree::iterator, std::list<dep_tree::iterator> &) const; 00108 00109 protected: 00110 // node the expression has to be checked against (p/d) 00111 std::wstring node; 00112 // set of values (if any) to check against. 00113 std::set<std::wstring> valueList; 00114 // obtain the iterator to the nodes to be checked 00115 // and the operation AND/OR to perform 00116 bool nodes_to_check(dep_tree::iterator, dep_tree::iterator, std::list<dep_tree::iterator> &) const; 00117 // virtual, evaluate expression 00118 virtual bool eval(dep_tree::iterator) const; 00119 00120 public: 00121 // constructors and destructors 00122 rule_expression(); 00123 rule_expression(const std::wstring &,const std::wstring &); 00124 virtual ~rule_expression() {} 00125 // search a value in expression list 00126 bool find(const std::wstring &) const; 00127 bool find_match(const std::wstring &) const; 00128 bool match(const std::wstring &) const; 00129 bool find_any(const std::list<std::wstring> &) const; 00130 bool find_any_match(const std::list<std::wstring> &) const; 00131 // virtual, evaluate expression 00132 virtual bool check(dep_tree::iterator, dep_tree::iterator) const; 00133 }; 00134 00135 00149 00153 00154 class check_and : public rule_expression { 00155 private: 00156 std::list<rule_expression *> check_list; 00157 public: 00158 void add(rule_expression *); 00159 bool check(dep_tree::iterator, dep_tree::iterator) const; 00160 }; 00161 00162 00166 00167 class check_not : public rule_expression { 00168 private: 00169 rule_expression * check_op; 00170 public: 00171 check_not(rule_expression *); 00172 bool check(dep_tree::iterator, dep_tree::iterator) const; 00173 }; 00174 00175 00179 00180 class check_side : public rule_expression { 00181 public: 00182 check_side(const std::wstring &,const std::wstring &); 00183 bool check(dep_tree::iterator, dep_tree::iterator) const; 00184 }; 00185 00186 00190 00191 class check_lemma : public rule_expression { 00192 public: 00193 check_lemma(const std::wstring &,const std::wstring &); 00194 bool eval(dep_tree::iterator) const; 00195 }; 00196 00200 00201 class check_pos : public rule_expression { 00202 public: 00203 check_pos(const std::wstring &,const std::wstring &); 00204 bool eval(dep_tree::iterator) const; 00205 }; 00206 00207 00211 00212 class check_category :public rule_expression { 00213 public: 00214 check_category(const std::wstring &,const std::wstring &); 00215 bool eval(dep_tree::iterator) const; 00216 }; 00217 00218 00222 00223 class check_wordclass : public rule_expression { 00224 public: 00225 static std::set<std::wstring> wordclasses; // items are class#verbLemma 00226 check_wordclass(const std::wstring &, const std::wstring &); 00227 bool eval(dep_tree::iterator) const; 00228 }; 00229 00233 00234 class check_tonto : public rule_expression { 00235 private: 00236 semanticDB &semdb; 00237 public: 00238 check_tonto(semanticDB &, const std::wstring &, const std::wstring &); 00239 bool eval(dep_tree::iterator) const; 00240 }; 00241 00245 00246 class check_semfile : public rule_expression { 00247 private: 00248 semanticDB &semdb; 00249 public: 00250 check_semfile(semanticDB &, const std::wstring &, const std::wstring &); 00251 bool eval(dep_tree::iterator) const; 00252 }; 00253 00257 00258 class check_synon : public rule_expression { 00259 private: 00260 semanticDB &semdb; 00261 public: 00262 check_synon(semanticDB &, const std::wstring &, const std::wstring &); 00263 bool eval(dep_tree::iterator) const; 00264 }; 00265 00269 00270 class check_asynon : public rule_expression { 00271 private: 00272 semanticDB &semdb; 00273 public: 00274 check_asynon(semanticDB &, const std::wstring &, const std::wstring &); 00275 bool eval(dep_tree::iterator) const; 00276 }; 00277 00278 00282 00283 class ruleLabeler { 00284 00285 public: 00286 std::wstring label; 00287 rule_expression * re; 00288 std::wstring ancestorLabel; 00290 int line; 00291 00292 ruleLabeler(void); 00293 ruleLabeler(const std::wstring &, rule_expression *); 00294 bool check(dep_tree::iterator, dep_tree::iterator) const; 00295 }; 00296 00297 00298 #endif
1.7.6.1