Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FST_LIB_ARCFILTER_H__
00022 #define FST_LIB_ARCFILTER_H__
00023
00024 #include <fst/fst.h>
00025 #include <fst/util.h>
00026
00027 namespace fst {
00028
00029
00030 template <class A>
00031 class AnyArcFilter {
00032 public:
00033 bool operator()(const A &arc) const { return true; }
00034 };
00035
00036
00037
00038 template <class A>
00039 class EpsilonArcFilter {
00040 public:
00041 bool operator()(const A &arc) const {
00042 return arc.ilabel == 0 && arc.olabel == 0;
00043 }
00044 };
00045
00046
00047
00048 template <class A>
00049 class InputEpsilonArcFilter {
00050 public:
00051 bool operator()(const A &arc) const {
00052 return arc.ilabel == 0;
00053 }
00054 };
00055
00056
00057
00058 template <class A>
00059 class OutputEpsilonArcFilter {
00060 public:
00061 bool operator()(const A &arc) const {
00062 return arc.olabel == 0;
00063 }
00064 };
00065
00066
00067
00068
00069 template <class A>
00070 class MultiLabelArcFilter {
00071 public:
00072 typedef typename A::Label Label;
00073
00074 MultiLabelArcFilter(bool match_input = true, bool keep_match = true)
00075 : match_input_(match_input),
00076 keep_match_(keep_match) {}
00077
00078
00079 bool operator()(const A &arc) const {
00080 Label label = match_input_ ? arc.ilabel : arc.olabel;
00081 bool match = labels_.Find(label) != labels_.End();
00082 return keep_match_ ? match : !match;
00083 }
00084
00085 void AddLabel(Label label) {
00086 labels_.Insert(label);
00087 }
00088
00089 private:
00090 CompactSet<Label, kNoLabel> labels_;
00091 bool match_input_;
00092 bool keep_match_;
00093 };
00094
00095 }
00096
00097 #endif /// FST_LIB_ARCFILTER_H__
00098