chart.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 #ifndef _CHART
00030 #define _CHART
00031 
00032 #include <list>
00033 #include <vector>
00034 #include <string>
00035 
00036 #include "fries/language.h"
00037 #include "freeling/grammar.h"
00038 
00042 
00043 class edge : public rule {
00044 
00045  private:
00047   std::list<std::string> matched;
00048   // list of cells that matched the currently solved part of the edge.
00049   // (-1,-1) stands for unary rules producing cell self-references.
00050   std::list<std::pair<int,int> > backpath;
00051 
00052  public:
00054    edge(const std::string&, const std::list<std::string> &, const int posgov);
00055    edge();
00056    //  edge(const edge &e);
00057    // edge & operator=(const edge &e);
00058 
00060    const std::list<std::string> get_matched() const;
00062    const std::list<std::pair<int,int> > get_backpath() const;
00064    bool active() const;
00066    void shift(int,int);
00067    
00068 };
00069 
00073 
00074 class cell : public std::list<edge> {}; 
00075 
00076 
00081 
00082 class chart : std::vector<cell> {
00083 
00084  private:
00085 
00087    int size;
00088    const grammar *gram;
00089 
00091    bool better_edge(const edge &, const edge&) const;
00093    std::list<std::pair<int,int> > cover (int a, int b) const;
00095    int index(int i, int j) const;
00098    bool can_extend(const std::string &, int, int) const;
00101    void find_all_rules(const edge &, cell &, int, int) const;
00103    bool check_match(const std::string &, const std::string &) const;
00104 
00105    void dump() const;
00106 
00107  public:
00109    chart();
00110 
00112    int get_size() const;
00114    cell get_cell(int, int) const;
00115 
00117    void load_sentence(const sentence &);
00118 
00120    void set_grammar(const grammar &);
00121 
00123    void parse();
00124 
00126    parse_tree get_tree(int, int, const std::string & ="") const;
00127 };
00128 
00129 #endif
00130 
00131 
00132 
00133 
00134 
Generated on Tue Jul 27 16:29:25 2010 for FreeLing by  doxygen 1.6.3