Introduction¶
Todo
- explain how to use the library
- demonstrating in particular the various ways to build noise-tolerant FSA’s (silent transitions, default transitions, global and state max_noise),
- explaining the notion of token,
- explaining the role of finish(), and why a token on a final state may not immediately return a match;
- the structure of tokens (as returned by feed() and feed_all();
- some of the design choices of the library,
- especially why an empty sequence is never a match, even if the ‘start’ state is marked as terminal.
Bits and pieces¶
Greedy matches¶
Automata will try to return the longest possible matches for a given stream.
This means that a match will not be detected as soon as it is detected,
as it may later yield a longer match.
To ensure that all pending matches are returned,
one must use the finish() method.
For example, in the following FSA,
a match will not be returned immediately after a is received.
If the stream is abbbc (or abbb and then finish()),
the only match will be abbb.
This greedy behaviour must however be described more precisely: a match A will inhibit another match B if: * the sequence of events of B is a prefix of the sequence of events of A, and * the terminal state of B has been reached at some point by A.
Hence, in the two following FSA fed with abbbc, the only match will be abbb,
even if allow_ovelap is set to true.
However, in the following FSA fed with abbbc and configured with allow_overlap set to true,
two matches a and abbb will be returned,
as the former has a terminal state that was never reached by the latter.
Overriding matches¶
The noise-torelant FSM below, fed with
ababab, will only yieldaaaiffsa.allow_overrideis set to false, but it will yieldaaaandbbbif it is set to true. Note that, if fed withacaca, withfsa.allow_overrideset to true, it will yieldaaaandcca, where the lastaparticipates in both matches.
![]()
Note however that automata work in a greedy way, so the automaton above is fed with
ccaawill only yieldccaa, it will never yieldcca, regardless offsa.allow_override.This notion of “greedyness” (greed?) can be tricky... It can be summed up