6 #include <boost/range/algorithm/sort.hpp>
23 template <
typename LabelSet>
26 static constexpr
size_t value = 1;
29 template <
typename... LabelSet>
32 static constexpr
size_t value =
sizeof...(LabelSet);
40 template <
typename Aut>
57 using super_t::super_t;
65 "me=$(basename \"$0\")\n"
66 "medir=$(mktemp -d \"/tmp/$me.XXXXXX\") || exit 1\n"
78 "cat >$medir/transitions.fsm <<\\EOFSM";
92 "fstcompile" << (
is_transducer ?
"" :
" --acceptor") <<
" \\\n"
93 " --arc_type=$arc_type \\\n"
94 " --keep_isymbols --isymbols=" <<
isymbols_ <<
" \\\n"
95 " --keep_osymbols --osymbols=" <<
osymbols_ <<
" \\\n"
96 " $medir/transitions.fsm \"$@\"\n"
108 auto map = std::map<std::string, std::string>
111 {
"zmin",
"standard"},
112 {
"rmin",
"standard"},
113 {
"nmin",
"standard"},
119 template <
typename LS>
122 if (ls.is_special(l))
129 template <
typename Label>
136 template <
typename Label>
151 if (
aut_->dst_of(t) !=
aut_->post())
159 if (
ws_.show_one() || !
ws_.is_one(
aut_->weight_of(t)))
173 auto inis =
aut_->initial_transitions();
175 || !
ws_.is_one(
aut_->weight_of(inis.front())))
188 std::vector<state_t> states(std::begin(
aut_->states()),
189 std::end(
aut_->states()));
193 return (std::forward_as_tuple(!
aut_->is_initial(l), l)
194 < std::forward_as_tuple(!
aut_->is_initial(r),
r));
199 for (
auto t :
aut_->final_transitions())
218 template <
typename LabelSet,
typename Labels,
typename GetLabel>
222 for (
auto l : ls.genset())
223 labels.insert(get_label(ls.value(l)));
229 template <
typename LabelSet,
typename Labels,
typename GetLabel>
258 template <
typename LabelSet,
typename GetLabel>
259 void output_symbols_(
const std::string& name,
264 using labelset_t = LabelSet;
265 using label_t =
typename labelset_t::value_t;
267 auto labels = std::set<label_t, vcsn::less<labelset_t>>{};
272 for (
auto t :
aut_->transitions())
273 labels.insert(get_label(
aut_->label_of(t)));
278 "cat >" << name <<
" <<\\EOFSM\n"
281 for (
const auto& l: labels)
285 os_ <<
'\t' << ++num <<
'\n';
295 output_symbols_impl_(std::false_type)
305 output_symbols_impl_(std::true_type)
308 ls_.template set<0>(),
309 [](
const label_t& l) { return std::get<0>(l); });
311 ls_.template set<1>(),
312 [](
const label_t& l) { return std::get<1>(l); });
323 using is_transducer_t =
324 std::integral_constant<bool,
325 2 <= rank<labelset_t_of<automaton_t>>::value>;
330 is_transducer ?
"$medir/isymbols.txt" :
"$medir/symbols.txt";
333 is_transducer ?
"$medir/osymbols.txt" :
"$medir/symbols.txt";
341 template <
typename Aut>
343 efsm(
const Aut& aut, std::ostream& out)
automaton_t aut_
The automaton we have to output.
const char * isymbols_
File name for input tape symbols.
weightset_mixin< detail::r_impl > r
auto map(const std::tuple< Ts...> &ts, Fun f) -> decltype(map_tuple_(f, ts, make_index_sequence< sizeof...(Ts)>()))
Map a function on a tuple, return tuple of the results.
static constexpr size_t value
C::mapped_type getargs(const std::string &kind, const C &map, const std::string &key)
Find a correspondance in a map.
typename super_t::label_t label_t
typename std::enable_if< Cond, T >::type enable_if_t
void output_label_(const Label &l, std::true_type) const
Two-tape automaton.
label_t_of< automaton_t > label_t
void output_label_(const LS &ls, const typename LS::value_t &l) const
Print as is. For instance, don't try to escape labels.
void operator()()
Actually output aut_ on os_.
auto add_alphabet_(const LabelSet &ls, Labels &labels, GetLabel get_label) -> enable_if_t< has_genset_mem_fn< LabelSet >
Fill labels with the gensets of ls.
const is_transducer_t is_transducer
state_t_of< automaton_t > state_t
const char * osymbols_
File name for output tape symbols.
Provide a variadic mul on top of a binary mul(), and one().
void output_transition_(const transition_t t) const override
Format automaton to EFSM format, based on FSM format.
std::string arc_type_() const
The OpenFST name that corresponds to our weightset.
typename super_t::state_t state_t
void output_label_(const Label &l, std::false_type) const
Acceptor.
const weightset_t & ws_
Short-hand to the weightset.
auto add_alphabet_(const LabelSet &, Labels &, GetLabel) -> enable_if_t<!has_genset_mem_fn< LabelSet >
Fill ls with the letters.
const labelset_t_of< automaton_t > & ls_
Short-hand to the labelset.
std::ostream & os_
Output stream.
std::ostream & efsm(const Aut &aut, std::ostream &out)
Format automaton to EFSM format, based on FSM format.
void output_state_(const state_t s)
Output transitions, sorted lexicographically on (Label, Dest).
transition_t_of< automaton_t > transition_t
void output_transitions_()
Output all the transitions, and final states.
typename super_t::transition_t transition_t
Factor common bits in automaton formatting.
auto sort(const Aut &a) -> permutation_automaton< Aut >