FreeLing  4.0
dep_treeler.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 
00030 #ifndef _DEP_TREELER
00031 #define _DEP_TREELER
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/tagset.h"
00041 #include "freeling/morfo/dependency_parser.h"
00042 
00043 //#include "treeler/dep/dep-symbols.h"
00044 //#include "treeler/control/script.h"
00045 //#include "treeler/io/io-conll.h"
00046 //#include "treeler/base/label.h"
00047 //#include "treeler/control/models.h"
00048 
00049 #include "treeler/dep/dependency_parser.h"
00050 #include "treeler/srl/srl_parser.h"
00051 
00052 namespace freeling {
00053 
00054 
00056 
00057 class WINDLL dep_treeler : public freeling::dependency_parser {
00058 
00059  public:   
00061   dep_treeler(const std::wstring &);
00063   ~dep_treeler();
00064 
00066   void analyze(freeling::sentence &) const;
00067 
00069   using processor::analyze;
00070     
00071 private:  
00072   //typedef treeler::control::Model<treeler::control::DEP1>::R DEP1_R;
00073   //typedef treeler::Label<DEP1_R> TreelerTree;
00074 
00076   treeler::dependency_parser *dp;
00077   treeler::srl_parser *srl;
00078   // tagset handler
00079   freeling::tagset *tags;
00080 
00081   // predicate detection configuration
00082 
00083   // given a synset, obtain predicate and argument structure
00084   std::map<std::string,map<std::wstring,treeler::srl::PossiblePredArgs> > predicates;
00085   // which PoS are always predicate, even if not in the files
00086   std::set<std::string> always_predicate;
00087   // arguments to expect for predicates not found in the files
00088   std::list<pair<std::string,std::string> > default_args;
00089   // predicate exceptions
00090   std::map<std::string,std::string> pred_exceptions;
00091  
00093   void FL2Treeler(const freeling::sentence& fl_sentence, treeler::dependency_parser::sentence &tl_sentence) const;
00095   void Treeler2FL(freeling::sentence &fl_sentence,
00096                   const treeler::dependency_parser::dep_vector &tl_tree,  
00097                   const treeler::srl_parser::pred_arg_set &tl_roles) const;
00098 
00100   freeling::dep_tree* build_dep_tree(int node_id, 
00101                                      const std::vector<std::list<int> > &sons, 
00102                                      const std::vector<std::string> &labels,
00103                                      std::map<int,freeling::depnode*> &depnods,
00104                                      freeling::sentence &fl_sentence) const;
00105 
00107   void load_options(const std::string &cfg, treeler::Options &opts);
00108 
00109   // compute predicates for SRL
00110   void load_predicate_files(const std::map<std::wstring,std::wstring> &);
00111   void compute_predicates(const treeler::srl_parser::basic_sentence &, const freeling::sentence &, 
00112                           const treeler::srl_parser::dep_vector &, treeler::srl::PossiblePreds &) const;
00113   bool is_pred_exception(const treeler::srl_parser::basic_sentence &, size_t, const treeler::srl_parser::dep_vector &) const;
00114 
00115 };
00116 
00117 }
00118 #endif
00119