Class DoubleArrayLexicon.Builder

java.lang.Object
opennlp.tools.tokenize.lattice.DoubleArrayLexicon.Builder
Enclosing class:
DoubleArrayLexicon

private static final class DoubleArrayLexicon.Builder extends Object
Builds the trie from sorted surface ranges. Each node places children at a common free base, and a moving watermark makes that search near-linear over real lexicons. The traversal uses an explicit stack so a long surface cannot exhaust the thread stack.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final record 
    A surface range with children waiting to be placed.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int[]
     
    private int[]
     
    private final int[]
     
    private static final int
     
    private int
     
    private static final int
     
    private final String[]
     
    private int
     
    private int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Builder(String[] surfaces, int[] codeOf)
    Initializes storage for the sorted surfaces and their dense character codes.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    ensureCapacity(int slot)
    Grows the base and check arrays until a slot is addressable.
    private int
    findBase(int[] labels, int labelCount)
    Finds the lowest base at which all labels use free indices.
    private void
    insert(int left, int right, int depth, int state)
    Places one trie node and all its descendants, using an explicit work stack instead of recursion.

    Methods inherited from class java.lang.Object

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

    • ROOT

      private static final int ROOT
      See Also:
    • EMPTY

      private static final int EMPTY
      See Also:
    • surfaces

      private final String[] surfaces
    • codeOf

      private final int[] codeOf
    • base

      private int[] base
    • check

      private int[] check
    • high

      private int high
    • watermark

      private int watermark
    • valueIndex

      private int valueIndex
  • Constructor Details

    • Builder

      private Builder(String[] surfaces, int[] codeOf)
      Initializes storage for the sorted surfaces and their dense character codes.
      Parameters:
      surfaces - The sorted surface forms.
      codeOf - The dense label for each UTF-16 character.
  • Method Details

    • insert

      private void insert(int left, int right, int depth, int state)
      Places one trie node and all its descendants, using an explicit work stack instead of recursion.
      Parameters:
      left - The first surface of the node's range.
      right - The exclusive end of the node's surface range.
      depth - The character depth of the node.
      state - The node's own slot.
    • findBase

      private int findBase(int[] labels, int labelCount)
      Finds the lowest base at which all labels use free indices. Labels follow surface-character order, not numeric order, so this method computes their smallest and largest values first.
      Parameters:
      labels - The child labels to place.
      labelCount - How many leading elements of labels are in use.
      Returns:
      The base offset every label fits at.
    • ensureCapacity

      private void ensureCapacity(int slot)
      Grows the base and check arrays until a slot is addressable.
      Parameters:
      slot - The highest slot index that has to be writable.