public final class FSA5Serializer extends java.lang.Object implements FSASerializer
FSA graphs to a binary format compatible with
Jan Daciuk's fsa's package FSA5 format.
It is possible to serialize the automaton with numbers required for perfect
hashing. See withNumbers() method.
FSA5,
FSA.read(java.io.InputStream)| Modifier and Type | Field and Description |
|---|---|
byte |
annotationByte |
byte |
fillerByte |
private static java.util.EnumSet<FSAFlags> |
flags
Supported flags.
|
private static int |
MAX_ARC_SIZE
Maximum number of bytes for a serialized arc.
|
private static int |
MAX_NODE_DATA_SIZE
Maximum number of bytes for per-node data.
|
private com.carrotsearch.hppc.IntIntHashMap |
numbers
A hash map of [state, right-language-count] pairs.
|
private com.carrotsearch.hppc.IntIntHashMap |
offsets
A hash map of [state, offset] pairs.
|
private static int |
SIZEOF_FLAGS
Number of bytes for the arc's flags header (arc representation without the
goto address).
|
private boolean |
withNumbers
true if we should serialize with numbers. |
| Constructor and Description |
|---|
FSA5Serializer() |
| Modifier and Type | Method and Description |
|---|---|
private int |
emitArc(java.nio.ByteBuffer bb,
java.io.OutputStream os,
int gtl,
int flags,
byte label,
int targetOffset) |
private boolean |
emitArcs(FSA fsa,
java.io.OutputStream os,
int[] linearized,
int gtl,
int nodeDataLength)
Update arc offsets assuming the given goto length.
|
private int |
emitNodeData(java.nio.ByteBuffer bb,
java.io.OutputStream os,
int nodeDataLength,
int number) |
java.util.Set<FSAFlags> |
getFlags()
Return supported flags.
|
private int[] |
linearize(FSA fsa)
Linearization of states.
|
<T extends java.io.OutputStream> |
serialize(FSA fsa,
T os)
Serialize root state
s to an output stream in
FSA5 format. |
FSA5Serializer |
withAnnotationSeparator(byte annotationSeparator)
Sets the annotation separator (only if
FSASerializer.getFlags() returns
FSAFlags.SEPARATORS). |
FSA5Serializer |
withFiller(byte filler)
Sets the filler separator (only if
FSASerializer.getFlags() returns
FSAFlags.SEPARATORS). |
FSA5Serializer |
withNumbers()
Serialize the automaton with the number of right-language sequences in each
node.
|
private static final int MAX_ARC_SIZE
private static final int MAX_NODE_DATA_SIZE
private static final int SIZEOF_FLAGS
private static final java.util.EnumSet<FSAFlags> flags
public byte fillerByte
FSA5.fillerpublic byte annotationByte
FSA5.annotationprivate boolean withNumbers
true if we should serialize with numbers.withNumbers()private com.carrotsearch.hppc.IntIntHashMap offsets
private com.carrotsearch.hppc.IntIntHashMap numbers
public FSA5Serializer withNumbers()
withNumbers in interface FSASerializerpublic FSA5Serializer withFiller(byte filler)
FSASerializer.getFlags() returns
FSAFlags.SEPARATORS).withFiller in interface FSASerializerfiller - The filler separator byte.this for call chaining.public FSA5Serializer withAnnotationSeparator(byte annotationSeparator)
FSASerializer.getFlags() returns
FSAFlags.SEPARATORS).withAnnotationSeparator in interface FSASerializerannotationSeparator - The filler separator byte.this for call chaining.public <T extends java.io.OutputStream> T serialize(FSA fsa, T os) throws java.io.IOException
s to an output stream in
FSA5 format.serialize in interface FSASerializerT - A subclass of OutputStream, returned for chaining.fsa - The automaton to serialize.os - The output stream to serialize to.os for chaining.java.io.IOException - Rethrown if an I/O error occurs.withNumbers()public java.util.Set<FSAFlags> getFlags()
getFlags in interface FSASerializerprivate int[] linearize(FSA fsa)
private boolean emitArcs(FSA fsa, java.io.OutputStream os, int[] linearized, int gtl, int nodeDataLength) throws java.io.IOException
java.io.IOExceptionprivate int emitArc(java.nio.ByteBuffer bb,
java.io.OutputStream os,
int gtl,
int flags,
byte label,
int targetOffset)
throws java.io.IOException
java.io.IOExceptionprivate int emitNodeData(java.nio.ByteBuffer bb,
java.io.OutputStream os,
int nodeDataLength,
int number)
throws java.io.IOException
java.io.IOException