00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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 };
00117
00118
00119
00120
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
00141
00142
00146 class mootFSMRWTH : public mootFSMBase {
00147 protected:
00148
00149
00150
00151
00152 ConstAutomatonRef mfstr;
00155 istringstream iss;
00156 ConstAutomatonRef result;
00157 set<WeightedLabelVectorPair> paths;
00160 public:
00161
00162
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 };
00186
00187
00188
00189 };
00190
00191
00192 #endif
00193
00194
00195 #ifdef HAVE_CONFIG_H
00196 # include <mootmUnConfig.h>
00197 #endif
00198
00199
00200 #endif