Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

mootFSMRWTH.h

Go to the documentation of this file.
00001 /*-*- Mode: C++ -*-*/
00002 
00003 /*
00004    libmootm : moocow's morphology library:
00005    Copyright (C) 2005 by Bryan Jurish <moocow@ling.uni-potsdam.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011    
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016    
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with this library; if not, write to the Free Software
00019    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00020 */
00021 
00022 /*----------------------------------------------------------------------
00023  * Name: mootFSMRWTH.h
00024  * Author: Bryan Jurish <moocow@ling.uni-potsdam.de>
00025  * Description:
00026  *   + mootm FSMs: RWTH libFsa
00027  *----------------------------------------------------------------------*/
00032 #ifndef _moot_FSM_RWTH_H
00033 #define _moot_FSM_RWTH_H
00034 
00035 #ifdef HAVE_CONFIG_H
00036 # include <mootmUnConfig.h>
00037 # include <mootmConfig.h>
00038 #endif
00039 
00040 #if defined(USE_FSM_RWTH)
00041 
00042 #include <mootFSMBase.h>
00043 
00044 #include <Fsa/Automaton.hh>
00045 #include <Fsa/Basic.hh>
00046 #include <Fsa/Static.hh>
00047 #include <Fsa/Types.hh>
00048 #include <Fsa/Input.hh>
00049 
00050 #include <vector>
00051 #include <string>
00052 #include <set>
00053 
00054 #include <sstream>
00055 
00056 
00057 namespace mootm {
00058   using namespace std;
00059   using namespace moot;
00060   using namespace Fsa;
00061 
00062 
00063   /*------------------------------------------------------------------------
00064    * Types
00065    */
00066 
00068   typedef class mootFSMRWTH mootFSM;
00069 
00070 
00072   typedef std::vector<LabelId> LabelVector;
00073 
00075   class WeightedLabelVectorPair {
00076   public:
00077     Weight      weight;
00078     LabelVector in;
00079     LabelVector out;
00080 
00081     WeightedLabelVectorPair(void) {};
00082 
00083     WeightedLabelVectorPair(const Weight w_)
00084       : weight(w_)
00085     {};
00086 
00087     WeightedLabelVectorPair(const Weight w_, const LabelVector &in_)
00088       : weight(w_), in(in_)
00089     {};
00090 
00091     WeightedLabelVectorPair(const Weight w_, const LabelVector &in_, const LabelVector &out_)
00092       : weight(w_), in(in_), out(out_) {};
00093 
00094     WeightedLabelVectorPair(const WeightedLabelVectorPair &p)
00095       : weight(p.weight), in(p.in), out(p.out)
00096     {};
00097 
00098     WeightedLabelVectorPair(const WeightedLabelVectorPair &p,
00099                             const Weight arc_weight, const LabelId arc_in, const LabelId arc_out,
00100                             ConstSemiringRef sr = TropicalSemiring)
00101       : weight(p.weight), in(p.in), out(p.out)
00102     {
00103       weight = sr->extend(weight, arc_weight);
00104       if (arc_in  != Epsilon) in.push_back(arc_in);
00105       if (arc_out != Epsilon) out.push_back(arc_out);
00106     };
00107 
00108     ~WeightedLabelVectorPair(void) {};
00109 
00110 
00111     bool operator<(const WeightedLabelVectorPair &w2) const
00112     { return weight < w2.weight || in < w2.in || out < w2.out; };
00113 
00114     bool operator==(const WeightedLabelVectorPair &w2) const
00115     { return weight == w2.weight && in == w2.in && out == w2.out; };
00116   }; //-- class WeightedLabelVectorPair
00117 
00118 
00119   /*----------------------------------------------------------------------
00120    * Local Functions
00121    */
00123   bool automatonLabelVectors(ConstAutomatonRef a,
00124                              set<WeightedLabelVectorPair> &paths,
00125                              bool cycle_test=true);
00126 
00128   bool _automatonLabelVectors_guts(ConstAutomatonRef             a,
00129                                    set<WeightedLabelVectorPair> &result,
00130                                    StateId                       stateid,
00131                                    WeightedLabelVectorPair      &path
00132                                    );
00133 
00135   bool labelVector2String(const LabelVector& v, std::string &s, ConstAlphabetRef abet, bool warnings=true);
00136 
00137 
00138 
00139   /*----------------------------------------------------------------------
00140    * FSM Wrapper: RWTH Fsa
00141    */
00142 
00146   class mootFSMRWTH : public mootFSMBase {
00147   protected:
00148     /*------------------------------------------------------------
00149      * protected data
00150      */
00151     //StorageAutomaton  *mfst;   /**< Underlying morphological transducer */
00152     ConstAutomatonRef mfstr;     
00155     istringstream      iss;             
00156     ConstAutomatonRef result;           
00157     set<WeightedLabelVectorPair> paths; 
00160   public:
00161     /*------------------------------------------------------------
00162      * public methods
00163      */
00165     mootFSMRWTH(void) {};
00166 
00168     virtual ~mootFSMRWTH(void)
00169     {};
00170 
00174     virtual bool load(const string &fstfile, const string &symfile="");
00175 
00177     virtual bool valid(void) const
00178     { return mfstr; }
00179 
00183     virtual mootToken& analyze_token(mootToken &tok, bool want_avm=true, bool want_warnings=true);
00184 
00185   }; //-- class mootFSMRWTH
00186 
00187 
00188 
00189 }; //-- namespace mootm
00190 
00191 
00192 #endif /* defined(USE_FSM_RWTH) */
00193 
00194 
00195 #ifdef HAVE_CONFIG_H
00196 # include <mootmUnConfig.h>
00197 #endif
00198 
00199 
00200 #endif /* _moot_FSM_RWTH_H */

Generated on Fri Dec 2 18:14:56 2005 for libmootm by  doxygen 1.4.3-20050530