import vcsn
from IPython.display import display
vcsn.context('lan_char, b').expression('a[bc]d').thompson()

vcsn.context('law_char, b').expression("'aa'[bc]'dd'").thompson()

"""
Explanation: expression.thompson
Generate the Thompson automaton from an expression.
Caveats:
- it is not guaranteed that Result.is_valid()
- the context of the result might be different from the original context: spontaneous-transition support is required.
Properties:
- Result.proper().is_isomorphic(r.standard())
See also:
- expression.automaton
Examples
The Thompson procedure generates an automaton with spontaneous-transitions, which requires a labelset that feature a "one" label.  The nullableset and wordset labelsets (and their compositions) does support a "one" label.
End of explanation
"""


vcsn.context('lal_char, b').expression("a").thompson().context()

"""
Explanation: You may, however, use a labelset which does not feature a "one", in which case the context of the automaton will be different from the one of the expression.
End of explanation
"""


r = vcsn.context('lan_char(abc), q').expression('(<1/6>a*+<1/3>b*)*')
r

t = r.thompson()
t

t.proper()

r.standard()

"""
Explanation: Weights
Weights are supported.
End of explanation
"""


t = vcsn.context('lan_char(abc), q').expression('\e*').thompson()
t

t.is_valid()

"""
Explanation: Note however that you may generate invalid automata:
End of explanation
"""


