public abstract class FSA extends Object implements Iterable<ByteBuffer>
Concrete subclasses (implementations) provide varying tradeoffs and features: traversal speed vs. memory size, for example.
FSABuilder
Constructor and Description |
---|
FSA() |
Modifier and Type | Method and Description |
---|---|
abstract int |
getArc(int node,
byte label) |
int |
getArcCount(int node)
Calculates the number of arcs of a given node.
|
abstract byte |
getArcLabel(int arc)
Return the label associated with a given
arc . |
abstract int |
getEndNode(int arc)
Return the end node pointed to by a given
arc . |
abstract int |
getFirstArc(int node) |
abstract Set<FSAFlags> |
getFlags()
Returns a set of flags for this FSA instance.
|
abstract int |
getNextArc(int arc) |
int |
getRightLanguageCount(int node) |
abstract int |
getRootNode() |
Iterable<ByteBuffer> |
getSequences()
|
Iterable<ByteBuffer> |
getSequences(int node)
Returns an iterator over all binary sequences starting at the given FSA
state (node) and ending in final nodes.
|
abstract boolean |
isArcFinal(int arc)
Returns
true if the destination node at the end of this
arc corresponds to an input sequence created when building
this automaton. |
abstract boolean |
isArcTerminal(int arc)
Returns
true if this arc does not have a
terminating node (@link getEndNode(int) will throw an
exception). |
Iterator<ByteBuffer> |
iterator()
Returns an iterator over all binary sequences starting from the initial
FSA state (node) and ending in final nodes.
|
static FSA |
read(File fsa) |
static <T extends FSA> |
read(InputStream in)
A factory for reading automata in any of the supported versions.
|
<T extends StateVisitor> |
visitAllStates(T v)
Visit all states.
|
<T extends StateVisitor> |
visitInPostOrder(T v)
Same as
visitInPostOrder(StateVisitor, int) ,
starting from root automaton node. |
<T extends StateVisitor> |
visitInPostOrder(T v,
int node)
Visits all states reachable from
node in postorder. |
<T extends StateVisitor> |
visitInPreOrder(T v)
Same as
visitInPreOrder(StateVisitor, int) , starting from root automaton node. |
<T extends StateVisitor> |
visitInPreOrder(T v,
int node)
Visits all states in preorder.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public abstract int getRootNode()
public abstract int getFirstArc(int node)
node
or 0 if the node has no outgoing arcs.public abstract int getNextArc(int arc)
arc
and
leaving node
. Zero is returned if no more arcs are
available for the node.public abstract int getArc(int node, byte label)
node
and
labeled with label
. An identifier equal to 0 means
the node has no outgoing arc labeled label
.public abstract byte getArcLabel(int arc)
arc
.public abstract boolean isArcFinal(int arc)
true
if the destination node at the end of this
arc
corresponds to an input sequence created when building
this automaton.public abstract boolean isArcTerminal(int arc)
true
if this arc
does not have a
terminating node (@link getEndNode(int)
will throw an
exception). Implies isArcFinal(int)
.public abstract int getEndNode(int arc)
arc
. Terminal arcs
(those that point to a terminal state) have no end node representation
and throw a runtime exception.public int getArcCount(int node)
for (int arc = fsa.getFirstArc(node); arc != 0; arc = fsa.getNextArc(arc)) { }
public int getRightLanguageCount(int node)
FSAFlags.NUMBERS
. The size of
the right language of the state, in other words.UnsupportedOperationException
- If the automaton was not compiled with
FSAFlags.NUMBERS
. The value can then be computed by manual count
of getSequences(int)
.public Iterable<ByteBuffer> getSequences(int node)
The returned iterator is a ByteBuffer
whose contents changes on
each call to Iterator.next()
. The keep the contents between calls
to Iterator.next()
, one must copy the buffer to some other
location.
Important. It is guaranteed that the returned byte buffer is backed by a byte array and that the content of the byte buffer starts at the array's index 0.
Iterable
public final Iterable<ByteBuffer> getSequences()
public final Iterator<ByteBuffer> iterator()
ByteBuffer
whose contents changes on each call to
Iterator.next()
. The keep the contents between calls to
Iterator.next()
, one must copy the buffer to some other location.
Important. It is guaranteed that the returned byte buffer is backed by a byte array and that the content of the byte buffer starts at the array's index 0.
iterator
in interface Iterable<ByteBuffer>
Iterable
public <T extends StateVisitor> T visitAllStates(T v)
StateVisitor.accept(int)
immediately terminates the traversal.public <T extends StateVisitor> T visitInPostOrder(T v)
visitInPostOrder(StateVisitor, int)
,
starting from root automaton node.public <T extends StateVisitor> T visitInPostOrder(T v, int node)
node
in postorder.
Returning false from StateVisitor.accept(int)
immediately terminates the traversal.public <T extends StateVisitor> T visitInPreOrder(T v)
visitInPreOrder(StateVisitor, int)
, starting from root automaton node.public <T extends StateVisitor> T visitInPreOrder(T v, int node)
StateVisitor.accept(int)
skips traversal of all sub-states of a given state.public static <T extends FSA> T read(InputStream in) throws IOException
IOException
FSA5.FSA5(InputStream)
public static FSA read(File fsa) throws IOException
IOException
Copyright © 2016. All rights reserved.