|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmorfologik.fsa.FSA
public abstract class FSA
This is a top abstract class for handling finite state automata. These automata are arc-based, a design described in Jan Daciuk's Incremental Construction of Finite-State Automata and Transducers, and Their Use in the Natural Language Processing (PhD thesis, Technical University of Gdansk).
Concrete subclasses (implementations) provide varying tradeoffs and features: traversal speed vs. memory size, for example.
FSABuilder
Constructor Summary | |
---|---|
FSA()
|
Method Summary | ||
---|---|---|
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 java.util.Set<FSAFlags> |
getFlags()
Returns a set of flags for this FSA instance. |
|
abstract int |
getNextArc(int arc)
|
|
int |
getRightLanguageCount(int node)
|
|
abstract int |
getRootNode()
|
|
java.lang.Iterable<java.nio.ByteBuffer> |
getSequences()
An alias of calling iterator() directly (FSA is also
Iterable ). |
|
java.lang.Iterable<java.nio.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). |
|
java.util.Iterator<java.nio.ByteBuffer> |
iterator()
Returns an iterator over all binary sequences starting from the initial FSA state (node) and ending in final nodes. |
|
static
|
read(java.io.InputStream in)
A factory for reading automata in any of the supported versions. |
|
|
visitAllStates(T v)
Visit all states. |
|
|
visitInPostOrder(T v)
Same as visitInPostOrder(StateVisitor, int) ,
starting from root automaton node. |
|
|
visitInPostOrder(T v,
int node)
Visits all states reachable from node in postorder. |
|
|
visitInPreOrder(T v)
Same as visitInPreOrder(StateVisitor, int) , starting from root automaton node. |
|
|
visitInPreOrder(T v,
int node)
Visits all states in preorder. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FSA()
Method Detail |
---|
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 abstract java.util.Set<FSAFlags> getFlags()
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.
java.lang.UnsupportedOperationException
- If the automaton was not compiled with
FSAFlags.NUMBERS
. The value can then be computed by manual count
of getSequences(int)
.public java.lang.Iterable<java.nio.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 java.lang.Iterable<java.nio.ByteBuffer> getSequences()
iterator()
directly (FSA
is also
Iterable
).
public final java.util.Iterator<java.nio.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 java.lang.Iterable<java.nio.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(java.io.InputStream in) throws java.io.IOException
java.io.IOException
FSA5.FSA5(InputStream)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |