FreeLing  3.1
dep_rules.h
Go to the documentation of this file.
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 _DEPRULES
00030 #define _DEPRULES
00031 
00032 #include <sstream>
00033 #include <iostream>
00034 #include <set>
00035 #include <list>
00036 
00037 #include "freeling/regexp.h"
00038 #include "freeling/morfo/language.h"
00039 #include "freeling/morfo/semdb.h"
00040 
00041 namespace freeling {
00042 
00046 
00047   class matching_attrib {
00048   public:
00050     std::wstring type;
00052     std::wstring value;
00054     freeling::regexp re;
00055 
00057     matching_attrib();
00059     matching_attrib(const matching_attrib &);
00061     ~matching_attrib();     
00062   };
00063 
00069 
00070   class matching_condition {
00071   public:
00072     bool neg;
00073     std::wstring label;
00074     std::list<matching_attrib> attrs;
00075   };
00076 
00083 
00084   class completerRule {
00085  
00086   public:
00089     int line;
00090 
00092     std::wstring leftChk;
00093     std::wstring rightChk;
00095     matching_condition leftConds;
00096     matching_condition rightConds;
00098     std::wstring newNode1;
00099     std::wstring newNode2;
00101     matching_condition matchingCond;
00103     std::wstring operation;
00105     std::vector<matching_condition> leftContext;
00106     std::vector<matching_condition> rightContext;
00108     bool context_neg;
00110     int weight;
00111 
00113     std::set<std::wstring> enabling_flags;
00115     std::set<std::wstring> flags_toggle_on;
00117     std::set<std::wstring> flags_toggle_off;
00118 
00119    
00121     completerRule();
00122     completerRule(const std::wstring &, const std::wstring &, const std::wstring&);
00123     completerRule( const completerRule &);
00125     completerRule & operator=( const completerRule &);
00126    
00128     int operator<(const completerRule & a ) const;
00129   };
00130 
00131 
00139   class rule_expression {
00140 
00141   private:
00142     void parse_node_ref(std::wstring, dep_tree::iterator, std::list<dep_tree::iterator> &) const;
00143 
00144   protected:
00145     // node the expression has to be checked against (p/d)
00146     std::wstring node;
00147     // set of values (if any) to check against.
00148     std::set<std::wstring> valueList;
00149     // obtain the iterator to the nodes to be checked 
00150     // and the operation AND/OR to perform
00151     bool nodes_to_check(dep_tree::iterator, dep_tree::iterator, std::list<dep_tree::iterator> &) const;
00152     // virtual, evaluate expression
00153     virtual bool eval(dep_tree::iterator) const;
00154 
00155   public:
00156     // constructors and destructors
00157     rule_expression();
00158     rule_expression(const std::wstring &,const std::wstring &);
00159     virtual ~rule_expression() {}
00160     // search a value in expression list
00161     bool find(const std::wstring &) const;
00162     bool find_match(const std::wstring &) const;
00163     bool match(const std::wstring &) const;
00164     bool find_any(const std::list<std::wstring> &) const;
00165     bool find_any_match(const std::list<std::wstring> &) const;
00166     // virtual, evaluate expression
00167     virtual bool check(dep_tree::iterator, dep_tree::iterator) const;
00168   };
00169 
00170 
00184 
00188 
00189   class check_and : public rule_expression {
00190   private:
00191     std::list<rule_expression *> check_list;
00192   public:
00193     void add(rule_expression *);
00194     bool check(dep_tree::iterator, dep_tree::iterator) const;
00195   };
00196 
00197 
00201 
00202   class check_not : public rule_expression {
00203   private:
00204     rule_expression * check_op;
00205   public:
00206     check_not(rule_expression *);
00207     bool check(dep_tree::iterator, dep_tree::iterator) const;
00208   };
00209 
00210 
00214 
00215   class check_side : public rule_expression {
00216   public:
00217     check_side(const std::wstring &,const std::wstring &);
00218     bool check(dep_tree::iterator, dep_tree::iterator) const;
00219   };
00220 
00221 
00225 
00226   class check_lemma : public rule_expression {
00227   public:
00228     check_lemma(const std::wstring &,const std::wstring &);
00229     bool eval(dep_tree::iterator) const;
00230   };
00231 
00235 
00236   class check_pos : public rule_expression {
00237   public:
00238     check_pos(const std::wstring &,const std::wstring &);
00239     bool eval(dep_tree::iterator) const;
00240   };
00241 
00242 
00246 
00247   class check_category :public rule_expression {
00248   public:
00249     check_category(const std::wstring &,const std::wstring &);
00250     bool eval(dep_tree::iterator) const;
00251   };
00252 
00253 
00257 
00258   class check_wordclass : public rule_expression { 
00259   private: 
00260     const std::set<std::wstring> *wordclasses; // word class set from labeler we belong to.
00261   public:
00262     check_wordclass(const std::wstring &, const std::wstring &, const std::set<std::wstring> *);
00263     bool eval(dep_tree::iterator) const;
00264   };
00265 
00269 
00270   class check_tonto : public rule_expression { 
00271   private: 
00272     semanticDB &semdb;
00273   public:    
00274     check_tonto(semanticDB &, const std::wstring &, const std::wstring &);
00275     bool eval(dep_tree::iterator) const;
00276   };
00277 
00281 
00282   class check_semfile : public rule_expression { 
00283   private: 
00284     semanticDB &semdb;
00285   public:    
00286     check_semfile(semanticDB &, const std::wstring &, const std::wstring &);
00287     bool eval(dep_tree::iterator) const;
00288   };
00289 
00293 
00294   class check_synon : public rule_expression { 
00295   private: 
00296     semanticDB &semdb;
00297   public:    
00298     check_synon(semanticDB &, const std::wstring &, const std::wstring &);
00299     bool eval(dep_tree::iterator) const;
00300   };
00301 
00305 
00306   class check_asynon : public rule_expression { 
00307   private: 
00308     semanticDB &semdb;
00309   public:    
00310     check_asynon(semanticDB &, const std::wstring &, const std::wstring &);
00311     bool eval(dep_tree::iterator) const;
00312   };
00313 
00314 
00318 
00319   class ruleLabeler {
00320 
00321   public:
00322     std::wstring label;
00323     rule_expression * re;
00324     std::wstring ancestorLabel;
00326     int line;
00327 
00328     ruleLabeler(void);
00329     ruleLabeler(const std::wstring &, rule_expression *);
00330     bool check(dep_tree::iterator, dep_tree::iterator) const;
00331   };
00332 
00333 } // namespace
00334 
00335 #endif