17 #ifndef AWALI_ALGOS_LETTERIZE_HH
18 #define AWALI_ALGOS_LETTERIZE_HH
23 #include<unordered_map>
34 template <
typename Aut,
typename Labelset>
39 return copy(aut, keep_history);
44 template <
typename Aut,
typename L>
57 std::unordered_map<state_t,state_t> state_map;
58 for(
auto s : aut->states()) {
59 state_map[s]=ret->add_state();
61 state_map[ret->pre()]=aut->pre();
62 state_map[ret->post()]=aut->post();
63 for(
auto tr: aut->all_transitions()) {
64 const auto& w=aut->label_of(tr);
66 new_epsilon_trans(ret, state_map[aut->src_of(tr)], state_map[aut->dst_of(tr)], aut->weight_of(tr));
67 else if (w.length()==1)
68 ret->new_transition(state_map[aut->src_of(tr)], state_map[aut->dst_of(tr)], w[0], aut->weight_of(tr));
70 state_t dst=state_map[aut->dst_of(tr)];
71 for(
unsigned i=w.length()-1; i>0;i--) {
73 ret->new_transition(src, dst, w[i]);
76 ret->new_transition(state_map[aut->src_of(tr)], dst, w[0], aut->weight_of(tr));
80 auto history = std::make_shared<single_history<automaton_t>>(aut);
81 for(
auto p : state_map) {
82 history->add_state(p.second,p.first);
83 if(aut->has_name(p.first)) {
84 ret->set_state_name(p.second, aut->get_state_name(p.first));
87 ret->set_history(history);
94 template<
typename Aut>
carries the algebraic settings of automata
Definition: context.hh:40
context(const context &that)
Definition: context.hh:67
Implementation of labels are words.
Definition: wordset.hh:35
weightset_description weightset(const std::string &k)
auto get_nullableset(const L &labelset) -> typename labelset_trait< L >::nullable_t
Definition: traits.hh:246
auto get_letterset(const L &labelset) -> typename labelset_trait< L >::letterset_t
Definition: traits.hh:225
typename internal::labelset_t_of_impl< internal::base_t< ValueSet > >::type labelset_t_of
Helper to retrieve the type of the labelset of a value set.
Definition: traits.hh:76
auto letterize(const Aut &aut, bool keep_history=true) -> typename internal::letterizer< Aut, labelset_t_of< Aut >>::ret_automaton_t
Definition: letterize.hh:95
AutOut copy(const AutIn &input, Pred keep_state, bool keep_history=true, bool transpose=false)
A copy of input keeping only its states that are accepted by keep_state.
Definition: copy.hh:189
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
Definition: mutable_automaton.hh:915
transition_t new_epsilon_trans(Aut a, state_t src, state_t dst, weight_t_of< Aut > w)
Helper to create a new epsilon transition.
Definition: add_epsilon_trans.hh:165
std::shared_ptr< internal::mutable_automaton_impl< Context > > mutable_automaton
Definition: mutable_automaton.hh:45
typename internal::weightset_t_of_impl< internal::base_t< ValueSet > >::type weightset_t_of
Helper to retrieve the type of the weightset of a value set.
Definition: traits.hh:86
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
Aut automaton_t
Definition: letterize.hh:46
typename labelset_trait< labelset_t >::letterset_t letterset_t
Definition: letterize.hh:49
static ret_automaton_t letterize(const automaton_t &aut, bool keep_history)
Definition: letterize.hh:54
weightset_t_of< Aut > weightset_t
Definition: letterize.hh:48
labelset_t_of< Aut > labelset_t
Definition: letterize.hh:47
typename labelset_trait< letterset_t >::nullable_t nletterset_t
Definition: letterize.hh:50
mutable_automaton< ret_context_t > ret_automaton_t
Definition: letterize.hh:52
Definition: letterize.hh:35
static ret_automaton_t letterize(const Aut &aut, bool keep_history)
Definition: letterize.hh:38
Aut ret_automaton_t
Definition: letterize.hh:36
L nullable_t
Definition: traits.hh:35
L letterset_t
Definition: traits.hh:37