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 <Automaton 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"
113 {
"zmin",
"standard"},
114 {
"rmin",
"standard"},
115 {
"nmin",
"standard"},
122 template <
typename LS>
125 if (ls.is_special(l))
132 template <
typename Label>
139 template <
typename Label>
154 if (
aut_->dst_of(t) !=
aut_->post())
162 if (
ws_.show_one() || !
ws_.is_one(
aut_->weight_of(t)))
178 || !
ws_.is_one(
aut_->weight_of(inis.front())))
191 std::vector<state_t> states(std::begin(
aut_->states()),
192 std::end(
aut_->states()));
196 return (std::forward_as_tuple(!
aut_->is_initial(l), l)
197 < std::forward_as_tuple(!
aut_->is_initial(r),
r));
221 template <
typename LabelSet,
typename Labels,
typename GetLabel>
223 -> std::enable_if_t<has_generators_mem_fn<LabelSet>{}>
225 for (
auto l : ls.generators())
226 labels.insert(get_label(ls.value(l)));
232 template <
typename LabelSet,
typename Labels,
typename GetLabel>
234 -> std::enable_if_t<!has_generators_mem_fn<LabelSet>{}>
261 template <
typename LabelSet,
typename GetLabel>
262 void print_symbols_(
const std::string& name,
267 using labelset_t = LabelSet;
268 using label_t =
typename labelset_t::value_t;
270 auto labels = std::set<label_t, vcsn::less<labelset_t>>{};
276 labels.insert(get_label(
aut_->label_of(t)));
281 "cat >" << name <<
" <<\\EOFSM\n"
284 for (
const auto& l: labels)
288 os_ <<
'\t' << ++num <<
'\n';
298 print_symbols_impl_(std::false_type)
308 print_symbols_impl_(std::true_type)
311 ls_.template set<0>(),
312 [](
const label_t& l) { return std::get<0>(l); });
314 ls_.template set<1>(),
315 [](
const label_t& l) { return std::get<1>(l); });
326 using is_transducer_t =
327 std::integral_constant<bool,
328 2 <= rank<labelset_t_of<automaton_t>>::value>;
333 is_transducer ?
"$medir/isymbols.txt" :
"$medir/symbols.txt";
336 is_transducer ?
"$medir/osymbols.txt" :
"$medir/symbols.txt";
344 template <Automaton Aut>
const weightset_t & ws_
Short-hand to the weightset.
const labelset_t_of< automaton_t > & ls_
Short-hand to the labelset.
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.
const char * isymbols_
File name for input tape symbols.
void print_label_(const Label &l, std::true_type) const
Two-tape automaton.
std::ostream & os_
Output stream.
void print_label_(const LS &ls, const typename LS::value_t &l) const
typename super_t::label_t label_t
const is_transducer_t is_transducer
static constexpr size_t value
Format automaton to EFSM format, based on FSM format.
Print as is. For instance, don't try to escape labels.
transition_t_of< automaton_t > transition_t
weightset_mixin< detail::r_impl > r
Provide a variadic mul on top of a binary mul(), and one().
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
A mapping from strings to Values.
void print_state_(const state_t s)
Output transitions, sorted lexicographically on (Label, Dest).
auto add_alphabet_(const LabelSet &ls, Labels &labels, GetLabel get_label) -> std::enable_if_t< has_generators_mem_fn< LabelSet >
Fill labels with the gensets of ls.
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.
auto transitions(const Aut &aut) -> decltype(all_transitions(aut, is_special_t< Aut >
All the transition indexes between visible states.
auto add_alphabet_(const LabelSet &, Labels &, GetLabel) -> std::enable_if_t<!has_generators_mem_fn< LabelSet >
Fill ls with the letters.
void operator()()
Actually output aut_ on os_.
automaton_t aut_
The automaton we have to output.
const char * osymbols_
File name for output tape symbols.
std::ostream & efsm(const Aut &aut, std::ostream &out)
Format automaton to EFSM format, based on FSM format.
state_t_of< automaton_t > state_t
auto sort(const Aut &a) -> permutation_automaton< Aut >
auto final_transitions(const Aut &aut) -> decltype(aut->all_in(aut->post()))
Indexes of transitions from (visible) final states.
std::string arc_type_() const
The OpenFST name that corresponds to our weightset.
void print_label_(const Label &l, std::false_type) const
Acceptor.
typename super_t::state_t state_t
label_t_of< automaton_t > label_t
typename super_t::transition_t transition_t
Factor common bits in automaton formatting.
void print_transition_(const transition_t t) const override
void print_transitions_()
Output all the transitions, and final states.