FreeLing
3.1
|
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 _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 00065 00066 class completer { 00067 private: 00069 std::map<std::pair<std::wstring,std::wstring>,std::list<completerRule> > chgram; 00070 // semantic classes for words, declared in CLASS section 00071 std::set<std::wstring> wordclasses; // items are class#lemma 00072 00074 completerRule find_grammar_rule(const std::vector<parse_tree *> &, const size_t, dep_txala_status*) const; 00076 parse_tree * applyRule(const completerRule &, int, parse_tree*, parse_tree*, dep_txala_status*) const; 00078 bool match_condition(parse_tree::iterator, const matching_condition &) const; 00080 bool matching_context(const std::vector<parse_tree *> &, const size_t, const completerRule &) const; 00082 bool matching_operation(const std::vector<parse_tree *> &, const size_t, const completerRule &, dep_txala_status*) const; 00084 bool match_side(const int, const std::vector<parse_tree *> &, const size_t, const std::vector<matching_condition> &) const; 00086 void extract_conds(std::wstring &, matching_condition &) const; 00088 bool enabled_rule(const completerRule &, dep_txala_status*) const; 00089 00090 public: 00092 completer(const std::wstring &); 00094 parse_tree complete(parse_tree &, const std::wstring &, dep_txala_status*) const; 00095 00097 static void load_classes(const std::wstring &, const std::wstring &, 00098 const std::wstring &, std::set<std::wstring> &); 00099 00100 }; 00101 00102 00108 00109 class depLabeler { 00110 00111 private: 00112 // set of rules 00113 std::map<std::wstring, std::list<ruleLabeler> > rules; 00114 // "unique" labels 00115 std::set<std::wstring> unique; 00116 // semantic database to check for semantic conditions in rules 00117 semanticDB * semdb; 00118 // parse a condition and create checkers. 00119 rule_expression* build_expression(const std::wstring &) const; 00120 // semantic classes for words, declared in CLASS section 00121 std::set<std::wstring> wordclasses; // items are class#lemma 00122 00123 public: 00125 depLabeler(const std::wstring &); 00127 ~depLabeler(); 00129 void label(dep_tree*) const; 00131 void label(dep_tree*, dep_tree::iterator) const; 00132 }; 00133 00134 00135 00144 00145 class WINDLL dep_txala : public dependency_parser { 00146 00147 private: 00149 completer comp; 00151 depLabeler labeler; 00152 // Root symbol used by the chunk parser when the tree is not complete. 00153 std::wstring start; 00155 dep_tree* dependencies(parse_tree::iterator, parse_tree::iterator) const; 00156 00157 public: 00159 dep_txala(const std::wstring &, const std::wstring &); 00160 00162 void analyze(sentence &) const; 00163 00165 using processor::analyze; 00166 }; 00167 00168 } // namespace 00169 00170 #endif 00171