Class DefaultSDContextGenerator

java.lang.Object
opennlp.tools.sentdetect.DefaultSDContextGenerator
All Implemented Interfaces:
SDContextGenerator
Direct Known Subclasses:
SentenceContextGenerator

public class DefaultSDContextGenerator extends Object implements SDContextGenerator
Generate event contexts for maxent decisions for sentence detection.
  • Field Details

    • buf

      protected final StringBuffer buf
      String buffer for generating features.
    • collectFeats

      protected final List<String> collectFeats
      List for holding features as they are generated.
    • inducedAbbreviations

      private final Set<String> inducedAbbreviations
    • eosCharacters

      private final Set<Character> eosCharacters
  • Constructor Details

    • DefaultSDContextGenerator

      public DefaultSDContextGenerator(char[] eosCharacters)
      Creates a new instance with no induced abbreviations.
      Parameters:
      eosCharacters - The characters to be used to detect sentence endings.
    • DefaultSDContextGenerator

      public DefaultSDContextGenerator(Set<String> inducedAbbreviations, char[] eosCharacters)
      Creates a new SDContextGenerator instance which uses the set of induced abbreviations.
      Parameters:
      inducedAbbreviations - a Set of Strings representing induced abbreviations in the training data. Example: "Mr."
      eosCharacters - The characters to be used to detect sentence endings.
  • Method Details

    • escapeChar

      private static String escapeChar(Character c)
    • getContext

      public String[] getContext(CharSequence sb, int position)
      Description copied from interface: SDContextGenerator
      Returns an array of contextual features for the potential sentence boundary at the specified position within the specified string buffer.
      Specified by:
      getContext in interface SDContextGenerator
      Parameters:
      sb - The String for which sentences are being determined.
      position - An index into the specified string buffer when a sentence boundary may occur.
      Returns:
      an array of contextual features for the potential sentence boundary at the specified position within the specified string buffer.
    • collectFeatures

      protected void collectFeatures(String prefix, String suffix, String previous, String next, Character eosChar)
      Determines some features for the sentence detector and adds them to list features.
      Parameters:
      prefix - String preceding the eosChar in the eos token.
      suffix - String following the eosChar in the eos token.
      previous - Space delimited token preceding token containing eosChar.
      next - Space delimited token following token containing eosChar.
      eosChar - the EOS character been analyzed.
    • isFirstUpper

      private static boolean isFirstUpper(String s)
    • previousSpaceIndex

      private static int previousSpaceIndex(CharSequence sb, int seek)
      Finds the index of the nearest space before a specified index which is not itself preceded by a space.
      Parameters:
      sb - The CharSequence which contains the text being examined.
      seek - The index to begin searching from.
      Returns:
      The index which contains the nearest space.
    • nextSpaceIndex

      private static int nextSpaceIndex(CharSequence sb, int seek, int lastIndex)
      Finds the index of the nearest space after a specified index.
      Parameters:
      sb - The CharSequence which contains the text being examined.
      seek - The index to begin searching from.
      lastIndex - The highest index of the StringBuffer sb.
      Returns:
      The index which contains the nearest space.