FreeLing  3.0
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 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 _DEP_TXALA
00031 #define _DEP_TXALA
00032 
00033 #include <string>
00034 #include <map>
00035 #include <set>
00036 #include <vector>
00037 
00038 #include "freeling/windll.h"
00039 #include "freeling/morfo/language.h"
00040 #include "freeling/morfo/processor.h"
00041 #include "freeling/morfo/semdb.h"
00042 #include "freeling/morfo/dep_rules.h"
00043 #include "freeling/morfo/dependency_parser.h"
00044 
00045 
00053 
00054 class completer {
00055  private:
00057   std::map<std::pair<std::wstring,std::wstring>,std::list<completerRule> > chgram;
00059   std::set<std::wstring> active_flags;
00061   completerRule find_grammar_rule(const std::vector<parse_tree *> &, const size_t);
00063   parse_tree * applyRule(const completerRule &, parse_tree *, parse_tree *);
00065   bool matching_condition(parse_tree::iterator, const std::list<std::wstring> &, boost::u32regex &) const;
00067   bool matching_context(const std::vector<parse_tree *> &, const size_t, const completerRule &) const;
00069   bool matching_operation(const std::vector<parse_tree *> &, const size_t, completerRule &) const;
00071   bool match_side(const int, const std::vector<parse_tree *> &, const size_t, const std::vector<std::wstring> &, const size_t) const;
00073   void extract_conds(std::wstring &, std::list<std::wstring> &, boost::u32regex &) const;
00075   bool match_pattern(parse_tree::iterator, const std::wstring &) const;
00077   bool enabled_rule(const completerRule &) const;
00078 
00079  public:  
00081   completer(const std::wstring &);
00083   parse_tree complete(parse_tree &, const std::wstring &);
00084 
00085 };
00086 
00087 
00093 
00094 class depLabeler {
00095 
00096  private:
00097   // set of rules
00098   std::map<std::wstring, std::list<ruleLabeler> > rules;
00099   // "unique" labels
00100   std::set<std::wstring> unique;
00101   // semantic database to check for semantic conditions in rules
00102   semanticDB * semdb;
00103   // parse a condition and create checkers.
00104   rule_expression* build_expression(const std::wstring &);
00105 
00106  public:
00108   depLabeler(const std::wstring &);
00110   ~depLabeler();
00112   void label(dep_tree*);
00114   void label(dep_tree*, dep_tree::iterator);
00115 };
00116 
00117 
00118 
00127 
00128 class WINDLL dep_txala : public dependency_parser {
00129 
00130  private:
00132   completer comp; 
00134   depLabeler labeler;
00135   // Root symbol used by the chunk parser when the tree is not complete.
00136   std::wstring start;
00138   dep_tree* dependencies(parse_tree::iterator, parse_tree::iterator);
00139 
00140  public:   
00142   dep_txala(const std::wstring &, const std::wstring &);
00143 
00145   void analyze(sentence &);
00147   void analyze(std::list<sentence> &);
00149   sentence analyze(const sentence &);
00151   std::list<sentence> analyze(const std::list<sentence> &);
00152 };
00153 
00154 #endif
00155