Class Trie

  • Direct Known Subclasses:
    MultiTrie

    public class Trie
    extends java.lang.Object
    A Trie is used to store a dictionary of words and their stems.

    Actually, what is stored are words with their respective patch commands. A trie can be termed forward (keys read from left to right) or backward (keys read from right to left). This property will vary depending on the language for which a Trie is constructed.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  Trie.StrEnum
      This class is part of the Egothor Project
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.util.List<java.lang.CharSequence> cmds  
      (package private) boolean forward  
      (package private) int root  
      (package private) java.util.List<Row> rows  
    • Constructor Summary

      Constructors 
      Constructor Description
      Trie​(boolean forward)
      Constructor for the Trie object.
      Trie​(boolean forward, int root, java.util.List<java.lang.CharSequence> cmds, java.util.List<Row> rows)
      Constructor for the Trie object.
      Trie​(java.io.DataInput is)
      Constructor for the Trie object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void add​(java.lang.CharSequence key, java.lang.CharSequence cmd)
      Add the given key associated with the given patch command.
      java.lang.CharSequence[] getAll​(java.lang.CharSequence key)
      Gets the all attribute of the Trie object
      int getCells()
      Return the number of cells in this Trie object.
      int getCellsPnt()
      Gets the cellsPnt attribute of the Trie object
      int getCellsVal()
      Gets the cellsVal attribute of the Trie object
      java.lang.CharSequence getFully​(java.lang.CharSequence key)
      Return the element that is stored in a cell associated with the given key.
      java.lang.CharSequence getLastOnPath​(java.lang.CharSequence key)
      Return the element that is stored as last on a path associated with the given key.
      private Row getRow​(int index)
      Return the Row at the given index.
      void printInfo​(java.io.PrintStream out, java.lang.CharSequence prefix)
      writes debugging info to the printstream
      Trie reduce​(Reduce by)
      Remove empty rows from the given Trie and return the newly reduced Trie.
      void store​(java.io.DataOutput os)
      Write this Trie to the given output stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • rows

        java.util.List<Row> rows
      • cmds

        java.util.List<java.lang.CharSequence> cmds
      • root

        int root
      • forward

        boolean forward
    • Constructor Detail

      • Trie

        public Trie​(java.io.DataInput is)
             throws java.io.IOException
        Constructor for the Trie object.
        Parameters:
        is - the input stream
        Throws:
        java.io.IOException - if an I/O error occurs
      • Trie

        public Trie​(boolean forward)
        Constructor for the Trie object.
        Parameters:
        forward - set to true
      • Trie

        public Trie​(boolean forward,
                    int root,
                    java.util.List<java.lang.CharSequence> cmds,
                    java.util.List<Row> rows)
        Constructor for the Trie object.
        Parameters:
        forward - true if read left to right, false if read right to left
        root - index of the row that is the root node
        cmds - the patch commands to store
        rows - a Vector of Vectors. Each inner Vector is a node of this Trie
    • Method Detail

      • getAll

        public java.lang.CharSequence[] getAll​(java.lang.CharSequence key)
        Gets the all attribute of the Trie object
        Parameters:
        key - Description of the Parameter
        Returns:
        The all value
      • getCells

        public int getCells()
        Return the number of cells in this Trie object.
        Returns:
        the number of cells
      • getCellsPnt

        public int getCellsPnt()
        Gets the cellsPnt attribute of the Trie object
        Returns:
        The cellsPnt value
      • getCellsVal

        public int getCellsVal()
        Gets the cellsVal attribute of the Trie object
        Returns:
        The cellsVal value
      • getFully

        public java.lang.CharSequence getFully​(java.lang.CharSequence key)
        Return the element that is stored in a cell associated with the given key.
        Parameters:
        key - the key
        Returns:
        the associated element
      • getLastOnPath

        public java.lang.CharSequence getLastOnPath​(java.lang.CharSequence key)
        Return the element that is stored as last on a path associated with the given key.
        Parameters:
        key - the key associated with the desired element
        Returns:
        the last on path element
      • getRow

        private Row getRow​(int index)
        Return the Row at the given index.
        Parameters:
        index - the index containing the desired Row
        Returns:
        the Row
      • store

        public void store​(java.io.DataOutput os)
                   throws java.io.IOException
        Write this Trie to the given output stream.
        Parameters:
        os - the output stream
        Throws:
        java.io.IOException - if an I/O error occurs
      • add

        void add​(java.lang.CharSequence key,
                 java.lang.CharSequence cmd)
        Add the given key associated with the given patch command. If either parameter is null this method will return without executing.
        Parameters:
        key - the key
        cmd - the patch command
      • reduce

        public Trie reduce​(Reduce by)
        Remove empty rows from the given Trie and return the newly reduced Trie.
        Parameters:
        by - the Trie to reduce
        Returns:
        the newly reduced Trie
      • printInfo

        public void printInfo​(java.io.PrintStream out,
                              java.lang.CharSequence prefix)
        writes debugging info to the printstream