Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef FST_SCRIPT_PRUNE_H_
00018 #define FST_SCRIPT_PRUNE_H_
00019
00020 #include <vector>
00021 using std::vector;
00022
00023 #include <fst/script/arg-packs.h>
00024 #include <fst/script/fst-class.h>
00025 #include <fst/script/weight-class.h>
00026 #include <fst/prune.h>
00027 #include <fst/arcfilter.h>
00028
00029 namespace fst {
00030 namespace script {
00031
00032 struct PruneOptions {
00033 WeightClass weight_threshold;
00034 int64 state_threshold;
00035 const vector<WeightClass> *distance;
00036 float delta;
00037
00038 explicit PruneOptions(const WeightClass& w, int64 s,
00039 vector<WeightClass> *d = 0, float e = kDelta)
00040 : weight_threshold(w),
00041 state_threshold(s),
00042 distance(d),
00043 delta(e) {}
00044 private:
00045 PruneOptions();
00046 };
00047
00048
00049
00050
00051
00052
00053 template<class A>
00054 fst::PruneOptions<A, AnyArcFilter<A> > ConvertPruneOptions(
00055 const PruneOptions &opts) {
00056 typedef typename A::Weight Weight;
00057 typedef typename A::StateId StateId;
00058
00059 Weight weight_threshold = *(opts.weight_threshold.GetWeight<Weight>());
00060 StateId state_threshold = opts.state_threshold;
00061 vector<Weight> *distance = 0;
00062
00063 if (opts.distance) {
00064 distance = new vector<Weight>(opts.distance->size());
00065 for (unsigned i = 0; i < opts.distance->size(); ++i) {
00066 (*distance)[i] = *((*opts.distance)[i].GetWeight<Weight>());
00067 }
00068 }
00069
00070 return fst::PruneOptions<A, AnyArcFilter<A> >(
00071 weight_threshold, state_threshold, AnyArcFilter<A>(), distance,
00072 opts.delta);
00073 }
00074
00075
00076 typedef args::Package<MutableFstClass *, const PruneOptions &> PruneArgs1;
00077
00078 template<class Arc>
00079 void Prune(PruneArgs1 *args) {
00080 MutableFst<Arc> *ofst = args->arg1->GetMutableFst<Arc>();
00081
00082 typedef typename Arc::Weight Weight;
00083 typedef typename Arc::StateId StateId;
00084
00085 fst::PruneOptions<Arc, AnyArcFilter<Arc> > opts =
00086 ConvertPruneOptions<Arc>(args->arg2);
00087 Prune(ofst, opts);
00088 delete opts.distance;
00089 }
00090
00091
00092 typedef args::Package<const FstClass &, MutableFstClass *,
00093 const PruneOptions &> PruneArgs2;
00094
00095 template<class Arc>
00096 void Prune(PruneArgs2 *args) {
00097 const Fst<Arc>& ifst = *(args->arg1.GetFst<Arc>());
00098 MutableFst<Arc> *ofst = args->arg2->GetMutableFst<Arc>();
00099
00100 fst::PruneOptions<Arc, AnyArcFilter<Arc> > opts =
00101 ConvertPruneOptions<Arc>(args->arg3);
00102 Prune(ifst, ofst, opts);
00103 delete opts.distance;
00104 }
00105
00106
00107 typedef args::Package<const FstClass &,
00108 MutableFstClass *,
00109 const WeightClass &, int64, float> PruneArgs3;
00110
00111 template<class Arc>
00112 void Prune(PruneArgs3 *args) {
00113 const Fst<Arc>& ifst = *(args->arg1.GetFst<Arc>());
00114 MutableFst<Arc> *ofst = args->arg2->GetMutableFst<Arc>();
00115 typename Arc::Weight w = *(args->arg3.GetWeight<typename Arc::Weight>());
00116
00117 Prune(ifst, ofst, w, args->arg4, args->arg5);
00118 }
00119
00120
00121 typedef args::Package<MutableFstClass *, const WeightClass&,
00122 int64, float> PruneArgs4;
00123 template<class Arc>
00124 void Prune(PruneArgs4 *args) {
00125 MutableFst<Arc> *fst = args->arg1->GetMutableFst<Arc>();
00126 typename Arc::Weight w = *(args->arg2.GetWeight<typename Arc::Weight>());
00127 Prune(fst, w, args->arg3, args->arg4);
00128 }
00129
00130
00131
00132 void Prune(MutableFstClass *fst, const PruneOptions &opts);
00133
00134
00135 void Prune(const FstClass &ifst, MutableFstClass *fst,
00136 const PruneOptions &opts);
00137
00138
00139 void Prune(const FstClass &ifst, MutableFstClass *ofst,
00140 const WeightClass &weight_threshold,
00141 int64 state_threshold = kNoStateId,
00142 float delta = kDelta);
00143
00144
00145 void Prune(MutableFstClass *fst, const WeightClass& weight_threshold,
00146 int64 state_threshold, float delta);
00147
00148 }
00149 }
00150
00151
00152
00153 #endif /// FST_SCRIPT_PRUNE_H_
00154