FreeLing  4.0
dep_txala.h
Go to the documentation of this file.
00001 
00002 //
00003 //    FreeLing - Open Source Language Analyzers
00004 //
00005 //    Copyright (C) 2014   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 Affero 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 //    Affero General Public License for more details.
00017 //
00018 //    You should have received a copy of the GNU Affero 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 _DEP_TXALA
00030 #define _DEP_TXALA
00031 
00032 #include <string>
00033 #include <map>
00034 #include <set>
00035 #include <vector>
00036 
00037 #include "freeling/windll.h"
00038 #include "freeling/morfo/language.h"
00039 #include "freeling/morfo/processor.h"
00040 #include "freeling/morfo/semdb.h"
00041 #include "freeling/morfo/dep_rules.h"
00042 #include "freeling/morfo/dependency_parser.h"
00043 
00044 namespace freeling {
00045 
00049 
00050   class dep_txala_status : public processor_status {
00051   public:
00054     std::map<std::wstring,parse_tree::iterator> last;
00055 
00057     std::set<std::wstring> active_flags;
00058   };
00059 
00060 
00069 
00070   class WINDLL dep_txala : public dependency_parser {
00071 
00072   private:
00073     // Root symbol used by the chunk parser when the tree is not complete.
00074     std::wstring start;
00076     std::map<std::pair<std::wstring,std::wstring>,std::list<completer_rule> > chgram;
00077     // set of labeller rules
00078     std::map<std::wstring, std::list<labeler_rule> > rules;
00079     // "unique" labels for labeller
00080     std::set<std::wstring> unique;
00081     // semantic database to check for semantic conditions in rules
00082     semanticDB * semdb;
00083     // semantic classes for words, declared in CLASS section
00084     std::set<std::wstring> wordclasses;  // items are class#lemma
00085     // semantic classes for words, declared in CLASS section
00086     std::set<std::wstring> pairclasses;  // items are class#lemma1#lemma2
00087 
00089 
00091     void load_classes(const std::wstring &, const std::wstring &, 
00092                       const std::wstring &, std::set<std::wstring> &);
00094     void extract_conds(std::wstring &, matching_condition &) const;
00095     void create_subexpression(const std::wstring &node, const std::wstring &func, 
00096                               const std::wstring &value, bool negated, rule_expression &re) const;
00097     void add_subexpression(const std::wstring &condition, rule_expression &re) const;
00099     void load_rule(const std::wstring &line, completer_rule &r);
00100     // parse a line containing a labeller rule, and fill labeler_rule instance
00101     void load_rule(const std::wstring &line, labeler_rule &r);
00102 
00103 
00105 
00107     completer_rule find_grammar_rule(const std::vector<parse_tree *> &, const size_t, dep_txala_status*) const;
00109     parse_tree * applyRule(const completer_rule &, int, parse_tree*, parse_tree*, dep_txala_status*) const;
00111     void extract_attrib(const std::wstring &attr, const std::list<parse_tree::const_iterator> &nds, std::list<std::wstring> &val) const;
00113     void locate_node(const std::vector<parse_tree *> &trees, const size_t chk, 
00114                      const std::wstring &node, std::list<parse_tree::const_iterator> &res) const;
00116     bool match_condition(parse_tree::const_iterator, const matching_condition &) const;
00118     bool matching_context(const std::vector<parse_tree *> &, const size_t, const completer_rule &) const;
00120     bool matching_operation(const std::vector<parse_tree *> &, const size_t, const completer_rule &, dep_txala_status*) const;
00122     bool matching_pair(const std::vector<parse_tree *> &trees, const size_t chk, const completer_rule &r) const;
00124     bool match_side(const int, const std::vector<parse_tree *> &, const size_t, const std::vector<matching_condition> &) const;
00126     bool enabled_rule(const completer_rule &, dep_txala_status*) const;
00128     parse_tree complete(parse_tree &, const std::wstring &, dep_txala_status*) const;
00129 
00131 
00133     void label(dep_tree*, dep_tree::iterator) const;
00135     void label(dep_tree*) const;
00136 
00138     static dep_tree* dependencies(parse_tree::iterator, parse_tree::iterator);
00139 
00140   public:   
00142     dep_txala(const std::wstring &, const std::wstring &);
00144     ~dep_txala();
00145 
00147     void complete_parse_tree(sentence &) const;
00149     void complete_parse_tree(std::list<sentence> &) const;
00151     void complete_parse_tree(document &) const;
00153     static dep_tree* parse2dep(parse_tree &);
00154 
00156     void analyze(sentence &) const;
00157 
00159     using processor::analyze;
00160    
00161   };
00162 
00163 } // namespace
00164 
00165 #endif
00166