22 std::string
quote(
const std::string& s)
25 || (s.size() == 1 && std::isalnum(s[0])))
30 static auto re = std::regex{
"['\\\\ \\[\\]()+,|<>]"};
31 return std::regex_replace(s, re,
"\\$&");
49 template <
typename Context, direction Dir>
96 for (
const auto& m: p)
106 while (getline(is, buf))
117 while (
auto m = ps.conv_monomial(is))
128 {
"default",
"monomials"},
133 (this->*(
map[format]))(
is);
137 template <direction D = Dir>
139 -> std::enable_if_t<D == direction::forward, automaton_t>
145 template <direction D = Dir>
147 -> std::enable_if_t<D == direction::backward, automaton_t>
160 const auto& ls = *
ctx_.labelset();
162 s =
next_(s, ls.special());
169 res_->add_transition(s,
res_->post(), ls.special(), wgt);
177 assert(ts.size() == 0 || ts.size() == 1);
180 auto d =
res_->new_state();
181 res_->new_transition(s, d, l);
198 template <direction Dir,
typename PolynomialSet>
211 template <
typename PolynomialSet>
213 trie(
const PolynomialSet& ps,
const typename PolynomialSet::value_t& p)
215 auto t = detail::make_trie_builder<direction::forward>(ps);
225 template <
typename PolynomialSet>
226 mutable_automaton<detail::free_context<context_t_of<PolynomialSet>>>
227 cotrie(
const PolynomialSet& ps,
const typename PolynomialSet::value_t& p)
229 auto t = detail::make_trie_builder<direction::backward>(ps);
239 template <
typename PolynomialSet>
243 const auto& p = poly->as<PolynomialSet>();
248 template <
typename PolynomialSet>
252 const auto& p = poly->as<PolynomialSet>();
268 template <
typename PolynomialSet>
269 mutable_automaton<detail::free_context<context_t_of<PolynomialSet>>>
270 trie(
const PolynomialSet& ps, std::istream&
is,
271 const std::string&
format =
"default")
273 auto t = detail::make_trie_builder<direction::forward>(ps);
284 template <
typename PolynomialSet>
285 mutable_automaton<detail::free_context<context_t_of<PolynomialSet>>>
287 const std::string&
format =
"default")
289 auto t = detail::make_trie_builder<direction::backward>(ps);
299 template <
typename Context,
typename Istream,
typename String>
302 const std::string&
format)
304 const auto& c = ctx->as<Context>();
310 template <
typename Context,
typename Istream,
typename String>
313 const std::string&
format)
315 const auto& c = ctx->as<Context>();
typename letterized_traits< LabelSet >::labelset_t letterized_t
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.
trie_builder< free_context< context_t_of< PolynomialSet > >, Dir > make_trie_builder(const PolynomialSet &ps)
Instantiate a trie-builder for this type of polynomialset.
mutable_automaton< detail::free_context< context_t_of< PolynomialSet > > > cotrie(const PolynomialSet &ps, const typename PolynomialSet::value_t &p)
Make a cotrie-like mutable_automaton for a finite series given as a polynomial.
std::shared_ptr< const detail::polynomial_base > polynomial
void add_(const word_t &lbl, const weight_t &wgt)
Add a monomial.
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
work_automaton_t res_
The automaton being built.
std::shared_ptr< detail::mutable_automaton_impl< Context >> mutable_automaton
letter_t_of< context_t > letter_t
Build a trie automaton (prefix-tree-like automaton).
auto result() -> std::enable_if_t< D==direction::backward, automaton_t >
Get the result for a backward trie.
std::shared_ptr< detail::transpose_automaton_impl< Aut >> transpose_automaton
An automaton wrapper that presents the transposed automaton.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
SharedPtr make_shared_ptr(Args &&...args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
An input/output format for valuesets.
Provide a variadic mul on top of a binary mul(), and one().
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
void add(const word_t &l, const weight_t &w=weightset_t::one())
Add a monomial.
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
Aut transpose(const transpose_automaton< Aut > &aut)
void add_words(std::istream &is)
Add all the words (one per line) in this stream.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
constant< type_t::one, Context > one
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
A mapping from strings to Values.
automaton trie_stream(const context &ctx, std::istream &is, const std::string &format)
Bridge (trie).
mutable_automaton< context_t > automaton_t
The type of the result.
const context_t & ctx_
The context of the automaton: letterized.
std::shared_ptr< const detail::context_base > context
A dyn::context.
mutable_automaton< detail::free_context< context_t_of< PolynomialSet > > > trie(const PolynomialSet &ps, const typename PolynomialSet::value_t &p)
Make a trie-like mutable_automaton for a finite series given as a polynomial.
std::shared_ptr< detail::automaton_base > automaton
letterized_t< labelset_t >::value_t padding_
Padding, in case it is needed.
state_t_of< automaton_t > state_t
word_t_of< context_t > word_t
labelset_t_of< context_t > labelset_t
The input labelset, free/letterized or not.
trie_builder(const context_t &c)
std::istringstream is
The input stream: the specification to translate.
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.
void add(const monomial_t &m)
Add a monomial.
typename polynomialset_t::value_t polynomial_t
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
auto make_word_polynomialset(const Ctx &ctx) -> word_polynomialset_t< Ctx >
The polynomialset of words of a labelset (not necessarily on words itself).
static dyn::context ctx(const driver &d)
Get the context of the driver.
void add(const polynomial_t &p)
Add a polynomial.
Container::value_type front(const Container &container)
The first member of this Container.
void add(std::istream &is, const std::string &format)
Add all the monomials in this stream.
typename labelset_t_of< base_t< ValueSet >>::word_t word_t_of
state_t next_(state_t s, letter_t l)
Follow a transition, possibly creating it.
automaton cotrie_stream(const context &ctx, std::istream &is, const std::string &format)
Bridge (cotrie).
typename polynomialset_t::monomial_t monomial_t
typename labelset_t_of< base_t< ValueSet >>::letter_t letter_t_of
void add_monomials(std::istream &is)
Add all the monomials (one per line) in this stream.
std::conditional_t< Dir==direction::forward, automaton_t, transpose_automaton< automaton_t >> work_automaton_t
The type of the automaton we work on.
auto result() -> std::enable_if_t< D==direction::forward, automaton_t >
Get the result for the forward trie.
weightset_t_of< context_t > weightset_t
std::string quote(const std::string &s)
Turn a label into a parsable label: escape special characters.
weight_t_of< context_t > weight_t
free_context< context< LabelSet, WeightSet > > make_free_context(const context< LabelSet, WeightSet > &c)
The free context for c.
auto conv(const ValueSet &vs, const std::string &str, Args &&...args) -> decltype(vs.conv(std::declval< std::istream & >(), std::forward< Args >(args)...))
Parse str via vs.conv.