Class FST<T>


  • public final class FST<T>
    extends Object
    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).

    NOTE: the FST cannot be larger than ~2.1 GB because it uses int to address the byte[].

    WARNING: This API is experimental and might change in incompatible ways in the next release.
    • Field Detail

      • outputs

        public final Outputs<T> outputs
      • nodeCount

        public int nodeCount
      • arcCount

        public int arcCount
      • arcWithOutputCount

        public int arcWithOutputCount
    • Method Detail

      • sizeInBytes

        public int sizeInBytes()
        Returns bytes used to represent the FST
      • getEmptyOutput

        public T getEmptyOutput()
      • targetHasArcs

        public static <T> boolean targetHasArcs​(FST.Arc<T> arc)
      • 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)
                                     throws IOException
        Follows the follow arc and reads the last arc of its target; this changes the provided arc (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)
                                      throws IOException
        Follow the follow arc and read the first arc of its target; this changes the provided arc (2nd arg) in-place and returns it.
        Returns:
        Returns the second argument (arc).
        Throws:
        IOException
      • readNextArcLabel

        public int readNextArcLabel​(FST.Arc<T> arc)
                             throws IOException
        Peeks at next arc's label; does not alter arc. Do not call this if arc.isLast()!
        Throws:
        IOException
      • getNodeCount

        public int getNodeCount()
      • getArcCount

        public int getArcCount()
      • getArcWithOutputCount

        public int getArcWithOutputCount()
      • setAllowArrayArcs

        public void setAllowArrayArcs​(boolean v)
      • getBytesReader

        public final FST.BytesReader getBytesReader​(int pos)
      • pack

        public FST<T> pack​(int minInCountDeref,
                           int maxDerefNodes)
                    throws IOException
        Expert: creates an FST by packing this one. This process requires substantial additional RAM (currently ~8 bytes per node), but then should produce a smaller FST.
        Throws:
        IOException