Package org.apache.lucene.util.fst
Class FST<T>
- java.lang.Object
 - 
- org.apache.lucene.util.fst.FST<T>
 
 
- 
public final class FST<T> extends java.lang.ObjectRepresents an finite state machine (FST), using a compact byte[] format.The format is similar to what's used by Morfologik (http://sourceforge.net/projects/morfologik).
See the
package documentationfor some simple examples. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFST.Arc<T>Represents a single arc.static classFST.BytesReaderReads bytes stored in an FST.static classFST.INPUT_TYPESpecifies allowed range of each int input label for this FST. 
- 
Field Summary
Fields Modifier and Type Field Description longarcCountlongarcWithOutputCountstatic intDEFAULT_MAX_BLOCK_BITSstatic intEND_LABELIf arc has this label then that arc is final/acceptedFST.INPUT_TYPEinputTypelongnodeCountOutputs<T>outputs 
- 
Constructor Summary
Constructors Constructor Description FST(DataInput in, Outputs<T> outputs)Load a previously saved FST.FST(DataInput in, Outputs<T> outputs, int maxBlockBits)Load a previously saved FST; maxBlockBits allows you to control the size of the byte[] pages used to hold the FST bytes. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FST.Arc<T>findTargetArc(int labelToMatch, FST.Arc<T> follow, FST.Arc<T> arc, FST.BytesReader in)Finds an arc leaving the incoming arc, replacing the arc in place.longgetArcCount()longgetArcWithOutputCount()FST.BytesReadergetBytesReader()Returns aFST.BytesReaderfor this FST, positioned at position 0.TgetEmptyOutput()FST.Arc<T>getFirstArc(FST.Arc<T> arc)Fills virtual 'start' arc, ie, an empty incoming arc to the FST's start nodeFST.INPUT_TYPEgetInputType()longgetNodeCount()static <T> FST<T>read(java.io.File file, Outputs<T> outputs)Reads an automaton from a file.FST.Arc<T>readFirstRealTargetArc(long node, FST.Arc<T> arc, FST.BytesReader in)FST.Arc<T>readFirstTargetArc(FST.Arc<T> follow, FST.Arc<T> arc, FST.BytesReader in)Follow thefollowarc and read the first arc of its target; this changes the providedarc(2nd arg) in-place and returns it.FST.Arc<T>readLastTargetArc(FST.Arc<T> follow, FST.Arc<T> arc, FST.BytesReader in)Follows thefollowarc and reads the last arc of its target; this changes the providedarc(2nd arg) in-place and returns it.FST.Arc<T>readNextArc(FST.Arc<T> arc, FST.BytesReader in)In-place read; returns the arc.intreadNextArcLabel(FST.Arc<T> arc, FST.BytesReader in)Peeks at next arc's label; does not alter arc.FST.Arc<T>readNextRealArc(FST.Arc<T> arc, FST.BytesReader in)Never returns null, but you should never call this if arc.isLast() is true.voidreadRootArcs(FST.Arc<T>[] arcs)voidsave(java.io.File file)Writes an automaton to a file.voidsave(DataOutput out)longsizeInBytes()Returns bytes used to represent the FSTstatic <T> booleantargetHasArcs(FST.Arc<T> arc)returns true if the node at this address has any outgoing arcs 
 - 
 
- 
- 
Field Detail
- 
inputType
public final FST.INPUT_TYPE inputType
 
- 
nodeCount
public long nodeCount
 
- 
arcCount
public long arcCount
 
- 
arcWithOutputCount
public long arcWithOutputCount
 
- 
END_LABEL
public static final int END_LABEL
If arc has this label then that arc is final/accepted- See Also:
 - Constant Field Values
 
 
- 
DEFAULT_MAX_BLOCK_BITS
public static final int DEFAULT_MAX_BLOCK_BITS
 
 - 
 
- 
Method Detail
- 
getInputType
public FST.INPUT_TYPE getInputType()
 
- 
sizeInBytes
public long sizeInBytes()
Returns bytes used to represent the FST 
- 
readRootArcs
public void readRootArcs(FST.Arc<T>[] arcs) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
getEmptyOutput
public T getEmptyOutput()
 
- 
save
public void save(DataOutput out) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
save
public void save(java.io.File file) throws java.io.IOExceptionWrites an automaton to a file.- Throws:
 java.io.IOException
 
- 
read
public static <T> FST<T> read(java.io.File file, Outputs<T> outputs) throws java.io.IOException
Reads an automaton from a file.- Throws:
 java.io.IOException
 
- 
targetHasArcs
public static <T> boolean targetHasArcs(FST.Arc<T> arc)
returns true if the node at this address has any outgoing arcs 
- 
getFirstArc
public FST.Arc<T> getFirstArc(FST.Arc<T> arc)
Fills virtual 'start' arc, ie, an empty incoming arc to the FST's start node 
- 
readLastTargetArc
public FST.Arc<T> readLastTargetArc(FST.Arc<T> follow, FST.Arc<T> arc, FST.BytesReader in) throws java.io.IOException
Follows thefollowarc and reads the last arc of its target; this changes the providedarc(2nd arg) in-place and returns it.- Returns:
 - Returns the second argument
 (
arc). - Throws:
 java.io.IOException
 
- 
readFirstTargetArc
public FST.Arc<T> readFirstTargetArc(FST.Arc<T> follow, FST.Arc<T> arc, FST.BytesReader in) throws java.io.IOException
Follow thefollowarc and read the first arc of its target; this changes the providedarc(2nd arg) in-place and returns it.- Returns:
 - Returns the second argument (
arc). - Throws:
 java.io.IOException
 
- 
readFirstRealTargetArc
public FST.Arc<T> readFirstRealTargetArc(long node, FST.Arc<T> arc, FST.BytesReader in) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
readNextArc
public FST.Arc<T> readNextArc(FST.Arc<T> arc, FST.BytesReader in) throws java.io.IOException
In-place read; returns the arc.- Throws:
 java.io.IOException
 
- 
readNextArcLabel
public int readNextArcLabel(FST.Arc<T> arc, FST.BytesReader in) throws java.io.IOException
Peeks at next arc's label; does not alter arc. Do not call this if arc.isLast()!- Throws:
 java.io.IOException
 
- 
readNextRealArc
public FST.Arc<T> readNextRealArc(FST.Arc<T> arc, FST.BytesReader in) throws java.io.IOException
Never returns null, but you should never call this if arc.isLast() is true.- Throws:
 java.io.IOException
 
- 
findTargetArc
public FST.Arc<T> findTargetArc(int labelToMatch, FST.Arc<T> follow, FST.Arc<T> arc, FST.BytesReader in) throws java.io.IOException
Finds an arc leaving the incoming arc, replacing the arc in place. This returns null if the arc was not found, else the incoming arc.- Throws:
 java.io.IOException
 
- 
getNodeCount
public long getNodeCount()
 
- 
getArcCount
public long getArcCount()
 
- 
getArcWithOutputCount
public long getArcWithOutputCount()
 
- 
getBytesReader
public FST.BytesReader getBytesReader()
Returns aFST.BytesReaderfor this FST, positioned at position 0. 
 - 
 
 -