Class AffixCondition

java.lang.Object
opennlp.tools.stemmer.hunspell.AffixCondition

final class AffixCondition extends Object
One parsed affix condition: a fixed-length sequence of literal code points and bracketed character classes, matched with a single scan and no regular expressions. A suffix condition anchors at the end of the candidate stem, a prefix condition at its start; the condition . matches everything. Positions are Unicode code points so supplementary characters agree with FLAG UTF-8 flag reading.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int[][]
    Per position: the accepted code points, or null for any code point.
    private static final AffixCondition
    The shared instance for the condition ., which accepts every stem.
    private final boolean[]
    Per position with a class: whether the class is negated; null rows unused.
    private final boolean
    Whether the owning rule is a suffix rule, which anchors the condition at the end.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    AffixCondition(int[][] accepted, boolean[] negated, boolean suffix)
    Initializes the condition.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) boolean
    Tests a candidate stem against the condition at its anchored side: the last positions of the stem for a suffix condition, the first positions for a prefix condition.
    (package private) static AffixCondition
    parse(String pattern, boolean suffix, int lineNumber)
    Parses a condition field.

    Methods inherited from class java.lang.Object

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

    • ANY

      private static final AffixCondition ANY
      The shared instance for the condition ., which accepts every stem.
    • accepted

      private final int[][] accepted
      Per position: the accepted code points, or null for any code point.
    • negated

      private final boolean[] negated
      Per position with a class: whether the class is negated; null rows unused.
    • suffix

      private final boolean suffix
      Whether the owning rule is a suffix rule, which anchors the condition at the end.
  • Constructor Details

    • AffixCondition

      private AffixCondition(int[][] accepted, boolean[] negated, boolean suffix)
      Initializes the condition.
      Parameters:
      accepted - The accepted code points per position.
      negated - The negation marker per position.
      suffix - Whether the owning rule is a suffix rule.
  • Method Details

    • parse

      static AffixCondition parse(String pattern, boolean suffix, int lineNumber) throws IOException
      Parses a condition field. Each pattern position is a literal code point, a . matching any code point, or a bracketed class such as [sx]; a class starting with ^ is negated and matches any code point outside it.
      Parameters:
      pattern - The condition text from the affix rule.
      suffix - Whether the owning rule is a suffix rule.
      lineNumber - The affix file line, for error messages.
      Returns:
      The parsed condition. Never null.
      Throws:
      IOException - Thrown if a character class is unterminated.
    • matches

      boolean matches(String stem)
      Tests a candidate stem against the condition at its anchored side: the last positions of the stem for a suffix condition, the first positions for a prefix condition. A stem shorter than the condition never matches. Length is in code points.
      Parameters:
      stem - The candidate stem after affix removal and strip restoration.
      Returns:
      true if the stem satisfies the condition.