context.cotrie(data="", format="default", filename="")

Generate a "cotrie" automaton from a finite series, given as a file of (weighted) words.

Arguments:

  • data: a string containing the list of words
  • format:
    • "default": same as "monomials"
    • "monomials": each line contains a weighted word in the monomials syntax: <2>foo
    • "words": each line contains a single word: foo. In this case <2>foo is read as a five-letter word.

Postconditions:

  • Result.is_codeterministic()

See also:

Examples

Words (finite language)

In [1]:
import vcsn
vcsn.B.cotrie('''foo
bar
fubar''')
Out[1]:
%3 I3 3 3 I3->3 I6 6 6 I6->6 I8 8 8 I8->8 F0 0 0 0->F0 1 1 1->0 o 2 2 2->1 o 3->2 f 4 4 4->0 r 5 5 5->4 a 6->5 b 7 7 7->6 u 8->7 f
In [2]:
%%file words
hello
world
hell
word
Overwriting words
In [3]:
vcsn.B.cotrie('words')
Out[3]:
%3 I5 5 5 I5->5 F0 0 0 0->F0 1 1 1->0 s 2 2 2->1 d 3 3 3->2 r 4 4 4->3 o 5->4 w

Weighted words (finite series)

In [4]:
vcsn.Q.cotrie('''one
<20>twenty
<30>thirty
<40>fourty
<50>fifty''')
Out[4]:
%3 I3 3 3 I3->3 I9 9 9 I9->9 ⟨20⟩ I13 13 13 I13->13 ⟨30⟩ I16 16 16 I16->16 ⟨40⟩ I19 19 19 I19->19 ⟨50⟩ F0 0 0 0->F0 1 1 1->0 e 2 2 2->1 n 3->2 o 4 4 4->0 y 5 5 5->4 t 6 6 6->5 n 7 7 7->6 e 8 8 8->7 w 9->8 t 10 10 10->5 r 11 11 11->10 i 12 12 12->11 h 13->12 t 14 14 14->10 u 15 15 15->14 o 16->15 f 17 17 17->5 f 18 18 18->17 i 19->18 f

Tuples of words

In [5]:
vcsn.context('lat<law_char, law_char>, q').cotrie('''
<1>one|un
<2>two|deux
<3>three|trois
<4>four|quatre
<14>forteen|quatorze
<40>forty|quarante
''')
Out[5]:
%3 I3 3 3 I3->3 I7 7 7 I7->7 ⟨2⟩ I12 12 12 I12->12 ⟨3⟩ I18 18 18 I18->18 ⟨4⟩ I26 26 26 I26->26 ⟨14⟩ I34 34 34 I34->34 ⟨40⟩ F0 0 0 0->F0 1 1 1->0 e|n 2 2 2->1 n|u 3->2 o|ε 4 4 4->0 o|x 5 5 5->4 w|u 6 6 6->5 t|e 7->6 ε|d 8 8 8->0 e|s 9 9 9->8 e|i 10 10 10->9 r|o 11 11 11->10 h|r 12->11 t|t 13 13 13->0 r|e 14 14 14->13 u|r 15 15 15->14 o|t 16 16 16->15 f|a 17 17 17->16 ε|u 18->17 ε|q 19 19 19->0 n|e 20 20 20->19 e|z 21 21 21->20 e|r 22 22 22->21 t|o 23 23 23->22 r|t 24 24 24->23 o|a 25 25 25->24 f|u 26->25 ε|q 27 27 27->0 y|e 28 28 28->27 t|t 29 29 29->28 r|n 30 30 30->29 o|a 31 31 31->30 f|r 32 32 32->31 ε|a 33 33 33->32 ε|u 34->33 ε|q