Package org.apache.lucene.util.fst
Class FST<T>
java.lang.Object
org.apache.lucene.util.fst.FST<T>
Represents 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
documentation for some simple examples.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents a single arc.static classReads bytes stored in an FST.static enumSpecifies allowed range of each int input label for this FST. -
Field Summary
FieldsModifier and TypeFieldDescriptionlonglongstatic final intstatic final intIf arc has this label then that arc is final/acceptedfinal FST.INPUT_TYPElong -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindTargetArc(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.longlongReturns aFST.BytesReaderfor this FST, positioned at position 0.getFirstArc(FST.Arc<T> arc) Fills virtual 'start' arc, ie, an empty incoming arc to the FST's start nodelongstatic <T> FST<T> Reads an automaton from a file.readFirstRealTargetArc(long node, FST.Arc<T> arc, FST.BytesReader in) 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.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.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.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) voidWrites an automaton to a file.voidsave(DataOutput out) longReturns 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 Details
-
inputType
-
outputs
-
nodeCount
public long nodeCount -
arcCount
public long arcCount -
arcWithOutputCount
public long arcWithOutputCount -
END_LABEL
public static final int END_LABELIf arc has this label then that arc is final/accepted- See Also:
-
DEFAULT_MAX_BLOCK_BITS
public static final int DEFAULT_MAX_BLOCK_BITS
-
-
Constructor Details
-
FST
Load a previously saved FST.- Throws:
IOException
-
FST
Load a previously saved FST; maxBlockBits allows you to control the size of the byte[] pages used to hold the FST bytes.- Throws:
IOException
-
-
Method Details
-
getInputType
-
sizeInBytes
public long sizeInBytes()Returns bytes used to represent the FST -
readRootArcs
- Throws:
IOException
-
getEmptyOutput
-
save
- Throws:
IOException
-
save
Writes an automaton to a file.- Throws:
IOException
-
read
Reads an automaton from a file.- Throws:
IOException
-
targetHasArcs
returns true if the node at this address has any outgoing arcs -
getFirstArc
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 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:
IOException
-
readFirstTargetArc
public FST.Arc<T> readFirstTargetArc(FST.Arc<T> follow, FST.Arc<T> arc, FST.BytesReader in) throws 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:
IOException
-
readFirstRealTargetArc
public FST.Arc<T> readFirstRealTargetArc(long node, FST.Arc<T> arc, FST.BytesReader in) throws IOException - Throws:
IOException
-
readNextArc
In-place read; returns the arc.- Throws:
IOException
-
readNextArcLabel
Peeks at next arc's label; does not alter arc. Do not call this if arc.isLast()!- Throws:
IOException
-
readNextRealArc
Never returns null, but you should never call this if arc.isLast() is true.- Throws:
IOException
-
findTargetArc
public FST.Arc<T> findTargetArc(int labelToMatch, FST.Arc<T> follow, FST.Arc<T> arc, FST.BytesReader in) throws 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:
IOException
-
getNodeCount
public long getNodeCount() -
getArcCount
public long getArcCount() -
getArcWithOutputCount
public long getArcWithOutputCount() -
getBytesReader
Returns aFST.BytesReaderfor this FST, positioned at position 0.
-