dependencies.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 _DEP_TXALA
00031 #define _DEP_TXALA
00032 
00033 #include "fries/language.h"
00034 #include "freeling/dep_rules.h"
00035 #include "freeling/semdb.h"
00036 #include "freeling/dependency_parser.h"
00037 
00038 #include <string>
00039 #include <map>
00040 #include <set>
00041 #include <vector>
00042 
00043 
00051 
00052 class completer {
00053   private:
00055     std::map<std::pair<std::string,std::string>,std::list<completerRule> > chgram;
00057     std::set<std::string> active_flags;
00059     completerRule find_grammar_rule(const std::vector<parse_tree *> &, const size_t);
00061     parse_tree * applyRule(const completerRule &, parse_tree *, parse_tree *);
00063     bool matching_condition(parse_tree::iterator, const std::list<std::string> &, RegEx &) const;
00065     bool matching_context(const std::vector<parse_tree *> &, const size_t, const completerRule &) const;
00067     bool matching_operation(const std::vector<parse_tree *> &, const size_t, completerRule &) const;
00069     bool match_side(const int, const std::vector<parse_tree *> &, const size_t, const std::vector<std::string> &, const size_t) const;
00071     void extract_conds(std::string &, std::list<std::string> &, RegEx &) const;
00073     bool match_pattern(parse_tree::iterator, const std::string &) const;
00075     bool enabled_rule(const completerRule &) const;
00076 
00077   public:  
00079     completer(const std::string &);
00081     parse_tree complete(parse_tree &, const std::string &);
00082 
00083 };
00084 
00085 
00091 
00092 class depLabeler {
00093 
00094   private:
00095     // set of rules
00096     std::map<std::string, std::list<ruleLabeler> > rules;
00097     // "unique" labels
00098     std::set<std::string> unique;
00099     // semantic database to check for semantic conditions in rules
00100     semanticDB * semdb;
00101     // parse a condition and create checkers.
00102     rule_expression* build_expression(const std::string &);
00103 
00104   public:
00106     depLabeler(const std::string &);
00108     ~depLabeler();
00110     void label(dep_tree*);
00112     void label(dep_tree*, dep_tree::iterator);
00113 };
00114 
00115 
00116 
00125 
00126 class dep_txala : public dependency_parser {
00127 
00128  private:
00130    completer comp; 
00132    depLabeler labeler;
00133    // Root symbol used by the chunk parser when the tree is not complete.
00134    std::string start;
00136    dep_tree* dependencies(parse_tree::iterator, parse_tree::iterator);
00137 
00138  public:   
00140    dep_txala(const std::string &, const std::string &);
00142    void analyze(std::list<sentence> &);
00144    std::list<sentence> analyze(const std::list<sentence> &);
00145 };
00146 
00147 #endif
00148 
Generated on Tue Jul 27 16:29:25 2010 for FreeLing by  doxygen 1.6.3