Package morfologik.fsa.builders
Class ConstantArcSizeFSA
java.lang.Object
morfologik.fsa.FSA
morfologik.fsa.builders.ConstantArcSizeFSA
- All Implemented Interfaces:
Iterable<ByteBuffer>
An FSA with constant-size arc representation produced directly by
FSABuilder
.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Offset of the address field inside an arc.static final int
Size of a single arc structure.static final int
An arc flag indicating the target node of an arc corresponds to a final state.static final int
An arc flag indicating the arc is last within its state.private final byte[]
FSA data, serialized as a byte array.private final int
An epsilon state.static final int
Offset of the flags field inside an arc.static final int
Size of the flags field (constant for the builder).static final int
Offset of the label field inside an arc.static final int
Size of the label field (constant for the builder).static final int
Size of the target address field (constant for the builder).(package private) static final int
A dummy address of the terminal state. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
getArc
(int node, byte label) byte
getArcLabel
(int arc) private int
getArcTarget
(int arc) Fills the target state address of an arc.int
getEndNode
(int arc) int
getFirstArc
(int node) getFlags()
int
getNextArc
(int arc) int
boolean
isArcFinal
(int arc) private boolean
isArcLast
(int arc) boolean
isArcTerminal
(int arc) Methods inherited from class morfologik.fsa.FSA
getArcCount, getRightLanguageCount, getSequences, getSequences, iterator, read, read, readRemaining, visitAllStates, visitInPostOrder, visitInPostOrder, visitInPreOrder, visitInPreOrder
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
TARGET_ADDRESS_SIZE
public static final int TARGET_ADDRESS_SIZESize of the target address field (constant for the builder).- See Also:
-
FLAGS_SIZE
public static final int FLAGS_SIZESize of the flags field (constant for the builder).- See Also:
-
LABEL_SIZE
public static final int LABEL_SIZESize of the label field (constant for the builder).- See Also:
-
ARC_SIZE
public static final int ARC_SIZESize of a single arc structure.- See Also:
-
FLAGS_OFFSET
public static final int FLAGS_OFFSETOffset of the flags field inside an arc.- See Also:
-
LABEL_OFFSET
public static final int LABEL_OFFSETOffset of the label field inside an arc.- See Also:
-
ADDRESS_OFFSET
public static final int ADDRESS_OFFSETOffset of the address field inside an arc.- See Also:
-
TERMINAL_STATE
static final int TERMINAL_STATEA dummy address of the terminal state.- See Also:
-
BIT_ARC_FINAL
public static final int BIT_ARC_FINALAn arc flag indicating the target node of an arc corresponds to a final state.- See Also:
-
BIT_ARC_LAST
public static final int BIT_ARC_LASTAn arc flag indicating the arc is last within its state.- See Also:
-
epsilon
private final int epsilonAn epsilon state. The first and only arc of this state points either to the root or to the terminal state, indicating an empty automaton. -
data
private final byte[] dataFSA data, serialized as a byte array.
-
-
Constructor Details
-
ConstantArcSizeFSA
ConstantArcSizeFSA(byte[] data, int epsilon) - Parameters:
data
- FSA data. There must be no trailing bytes after the last state.
-
-
Method Details
-
getRootNode
public int getRootNode()- Specified by:
getRootNode
in classFSA
- Returns:
- Returns the identifier of the root node of this automaton. Returns 0 if the start node is also the end node (the automaton is empty).
-
getFirstArc
public int getFirstArc(int node) - Specified by:
getFirstArc
in classFSA
- Parameters:
node
- Identifier of the node.- Returns:
- Returns the identifier of the first arc leaving
node
or 0 if the node has no outgoing arcs.
-
getArc
public int getArc(int node, byte label) -
getNextArc
public int getNextArc(int arc) - Specified by:
getNextArc
in classFSA
- Parameters:
arc
- The arc's identifier.- Returns:
- Returns the identifier of the next arc after
arc
and leavingnode
. Zero is returned if no more arcs are available for the node.
-
getArcLabel
public byte getArcLabel(int arc) - Specified by:
getArcLabel
in classFSA
- Parameters:
arc
- The arc's identifier.- Returns:
- Return the label associated with a given
arc
.
-
getArcTarget
private int getArcTarget(int arc) Fills the target state address of an arc. -
isArcFinal
public boolean isArcFinal(int arc) - Specified by:
isArcFinal
in classFSA
- Parameters:
arc
- The arc's identifier.- Returns:
- Returns
true
if the destination node at the end of thisarc
corresponds to an input sequence created when building this automaton.
-
isArcTerminal
public boolean isArcTerminal(int arc) - Specified by:
isArcTerminal
in classFSA
- Parameters:
arc
- The arc's identifier.- Returns:
- Returns
true
if thisarc
does not have a terminating node (@linkFSA.getEndNode(int)
will throw an exception). ImpliesFSA.isArcFinal(int)
.
-
isArcLast
private boolean isArcLast(int arc) -
getEndNode
public int getEndNode(int arc) - Specified by:
getEndNode
in classFSA
- Parameters:
arc
- The arc's identifier.- Returns:
- Return the end node pointed to by a given
arc
. Terminal arcs (those that point to a terminal state) have no end node representation and throw a runtime exception.
-
getFlags
-