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 2.1 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 
00038 #include "fries/language.h"
00039 #include "freeling/semdb.h"
00040 #include "regexp-pcre++.h"
00041 
00048 
00049 class completerRule {
00050  
00051  public:
00053    std::string leftChk;
00054    std::string rightChk;
00056    std::list<std::string> leftConds;
00057    std::list<std::string> rightConds;
00059    RegEx leftRE;
00060    RegEx rightRE;
00062    std::string newNode1;
00063    std::string newNode2;
00065    std::string operation;
00067    std::string context;  
00069    bool context_neg;
00071    int weight;
00073    parse_tree::iterator last;
00074 
00076    std::set<std::string> enabling_flags;
00078    std::set<std::string> flags_toggle_on;
00080    std::set<std::string> flags_toggle_off;
00081 
00083    int line;
00084    
00086    completerRule();
00087    completerRule(const std::string &, const std::string &, const std::string&);
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     dep_tree::iterator parse_node_ref(std::string, dep_tree::iterator) const;
00108 
00109   protected:
00110     // node the expression has to be checked against (p/d)
00111     std::string node;
00112     // set of values (if any) to check against.
00113     std::set<std::string> 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::string &,const std::string &);
00124     virtual ~rule_expression() {}
00125     // search a value in expression list
00126     bool find(const std::string &) const;
00127     bool find_match(const std::string &) const;
00128     bool match(const std::string &) const;
00129     bool find_any(const std::list<std::string> &) const;
00130     bool find_any_match(const std::list<std::string> &) 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::string &,const std::string &);
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::string &,const std::string &);
00194     bool eval(dep_tree::iterator) const;
00195 };
00196 
00200 
00201 class check_pos : public rule_expression {
00202   public:
00203     check_pos(const std::string &,const std::string &);
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::string &,const std::string &);
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::string> wordclasses; // items are class#verbLemma
00226     check_wordclass(const std::string &, const std::string &);
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::string &, const std::string &);
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::string &, const std::string &);
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::string &, const std::string &);
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::string &, const std::string &);
00275     bool eval(dep_tree::iterator) const;
00276 };
00277 
00278 
00282 
00283 class ruleLabeler {
00284 
00285   public:
00286    std::string label;
00287    rule_expression * re;
00288    std::string ancestorLabel;
00290    int line;
00291 
00292    ruleLabeler(void);
00293    ruleLabeler(const std::string &, rule_expression *);
00294    bool check(dep_tree::iterator, dep_tree::iterator) const;
00295 };
00296 
00297 
00298 #endif
Generated on Tue Jul 27 16:29:25 2010 for FreeLing by  doxygen 1.6.3