Evaluates the weight of the given word through the automata.
Preconditions:
w
must be a valid word in the labelset.automaton
must not have spontaneous cycles.import vcsn
a = vcsn.context('lal(ab), b').de_bruijn(2)
a
a.evaluate('b')
a.evaluate('bbabb')
You can also write automaton('word')
to evaluate a word:
a('bbabb')
a = vcsn.Z.expression('(<2>C+c)los(<3>e(s+<4>d)+ing)').standard()
a.shortest(10)
a.evaluate('Closing')
a.evaluate('close') # but not enough
All automaton types are supported, evaluate is not limited to free labelsets. For instance, with word-labeled automata:
a = vcsn.context('law,q').expression('<2>(ab(<3>cd)*(ef))<5>', "associative").automaton()
a
a.evaluate('abcdef')
a.evaluate('abcdcdef')
Polynomials are also supported:
p = vcsn.context('law,q').polynomial('<2>abcdef+abcdcdef')
a.evaluate(p)
Spontaneous transitions are allowed:
%%automaton -s a
context = "wordset<char_letters(abcdef)>, q"
$ -> 0 <2>
0 -> 1 \e
1 -> 1 <3>cd
1 -> 2 \e
2 -> $ <5>
a.evaluate("cd")
a.evaluate("")
Tuplesets are fully supported:
ctx = vcsn.context('lat<lan, lan>, zmin')
a = ctx.expression('(<0>(a|a+b|b))* (<1>[^]|\e + <1>\e|[^] + <2>(a|[^a]+b|[^b])){*}').automaton()
a #Compute the LCS distance between two words
a.evaluate("aaa|ab")
a.evaluate("aba|ab")