Enum Class WordTraversalDirection

java.lang.Object
java.lang.Enum<WordTraversalDirection>
org.egothor.stemmer.WordTraversalDirection
All Implemented Interfaces:
Serializable, Comparable<WordTraversalDirection>, Constable

public enum WordTraversalDirection extends Enum<WordTraversalDirection>
Defines the logical direction in which word characters are traversed.

The same direction is used consistently in two places:

  • when a word key is traversed through a trie
  • when patch commands are serialized and then applied back to a source word

FORWARD means that processing starts at the logical beginning of the stored form and moves toward its end. BACKWARD means that processing starts at the logical end of the stored form and moves toward its beginning.

For traditional suffix-oriented Egothor data, BACKWARD matches the historical behavior. For right-to-left languages whose affix logic should operate on the stored form as written, FORWARD can be used so that neither trie construction nor patch application needs to reverse words externally.

  • Enum Constant Details

    • FORWARD

      public static final WordTraversalDirection FORWARD
      Traverses a word from its logical beginning toward its logical end.
    • BACKWARD

      public static final WordTraversalDirection BACKWARD
      Traverses a word from its logical end toward its logical beginning.
  • Method Details

    • values

      public static WordTraversalDirection[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static WordTraversalDirection valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • startIndex

      public int startIndex(int length)
      Returns the traversal start index for a character sequence of the supplied length.
      Parameters:
      length - sequence length
      Returns:
      start index, or -1 when the sequence is empty and traversal should therefore not begin
      Throws:
      IllegalArgumentException - if length is negative
    • logicalIndex

      public int logicalIndex(int length, int traversalOffset)
      Returns the logical character index addressed by the supplied traversal offset.

      A traversal offset of 0 addresses the first character seen in this direction, 1 the second character, and so on.

      Parameters:
      length - sequence length
      traversalOffset - zero-based offset from the traversal start
      Returns:
      corresponding logical character index
      Throws:
      IllegalArgumentException - if any argument is outside the valid range
    • toTraversalCharacters

      public char[] toTraversalCharacters(String word)
      Returns the characters of the supplied word in this traversal order.
      Parameters:
      word - source word
      Returns:
      traversal-ordered characters
      Throws:
      NullPointerException - if word is null
    • traversalPathToLogicalKey

      public String traversalPathToLogicalKey(CharSequence traversalPath)
      Converts a path represented in traversal order back to the logical key form.
      Parameters:
      traversalPath - key path in traversal order
      Returns:
      logical key form
      Throws:
      NullPointerException - if traversalPath is null