Class BasicContextGenerator

java.lang.Object
opennlp.tools.ml.maxent.BasicContextGenerator
All Implemented Interfaces:
ContextGenerator<String>

public class BasicContextGenerator extends Object implements ContextGenerator<String>
A ContextGenerator implementation for maxent decisions, assuming that the input given to the getContext(String) method is a String containing contextual predicates separated by whitespace, for instance:

cp_1 cp_2 ... cp_n

A separator given to the constructor is literal text; empty predicates are not returned.
  • Constructor Details

    • BasicContextGenerator

      public BasicContextGenerator()
      Initializes a BasicContextGenerator that splits on runs of whitespace under the Unicode White_Space property, see StringUtil.isUnicodeWhitespace(int). That definition is fixed and does not depend on the opennlp.whitespace.mode system property, see WhitespaceMode.
    • BasicContextGenerator

      public BasicContextGenerator(String sep)
      Initializes a BasicContextGenerator that splits on sep only. Other whitespace is part of the predicates.
      Parameters:
      sep - The separator, taken as written and not as a regular expression. Must not be null or empty, and must not contain a backslash or an unpaired surrogate. A backslash is rejected to catch regular expression separators written for 2.x, such as \s+.
      Throws:
      IllegalArgumentException - Thrown if sep is null, empty, contains a backslash, or contains an unpaired surrogate.
  • Method Details

    • getContext

      public String[] getContext(String o)
      Builds up the list of contextual predicates given an object. Splits o at each occurrence of the separator, or on runs of Unicode whitespace if none was given, and leaves out empty parts.
      Specified by:
      getContext in interface ContextGenerator<String>
      Parameters:
      o - The object used as input.
      Returns:
      The contextual predicates of o, in order.