Class DefaultSDContextGenerator
java.lang.Object
opennlp.tools.sentdetect.DefaultSDContextGenerator
- All Implemented Interfaces:
SDContextGenerator
- Direct Known Subclasses:
SentenceContextGenerator
Generate event contexts for maxent decisions for sentence detection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StringBufferString buffer for generating features.List for holding features as they are generated. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultSDContextGenerator(char[] eosCharacters) Creates a new instance with no induced abbreviations.DefaultSDContextGenerator(Set<String> inducedAbbreviations, char[] eosCharacters) Creates a newSDContextGeneratorinstance which uses the set of induced abbreviations. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidDetermines some features for the sentence detector and adds them to list features.private static StringString[]getContext(CharSequence sb, int position) Returns an array of contextual features for the potential sentence boundary at the specified position within the specified string buffer.private static booleanprivate static intnextSpaceIndex(CharSequence sb, int seek, int lastIndex) Finds the index of the nearest space after a specified index.private static intpreviousSpaceIndex(CharSequence sb, int seek) Finds the index of the nearest space before a specified index which is not itself preceded by a space.
-
Field Details
-
buf
String buffer for generating features. -
collectFeats
-
inducedAbbreviations
-
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
Creates a newSDContextGeneratorinstance which uses the set of induced abbreviations.- Parameters:
inducedAbbreviations- aSetof Strings representing induced abbreviations in the training data. Example: "Mr."eosCharacters- The characters to be used to detect sentence endings.
-
-
Method Details
-
escapeChar
-
getContext
Description copied from interface:SDContextGeneratorReturns an array of contextual features for the potential sentence boundary at the specified position within the specified string buffer.- Specified by:
getContextin interfaceSDContextGenerator- Parameters:
sb- TheStringfor 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
positionwithin 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 theeosCharin the eos token.suffix- String following theeosCharin the eos token.previous- Space delimited token preceding token containingeosChar.next- Space delimited token following token containingeosChar.eosChar- the EOS character been analyzed.
-
isFirstUpper
-
previousSpaceIndex
Finds the index of the nearest space before a specified index which is not itself preceded by a space.- Parameters:
sb- TheCharSequencewhich contains the text being examined.seek- The index to begin searching from.- Returns:
- The index which contains the nearest space.
-
nextSpaceIndex
Finds the index of the nearest space after a specified index.- Parameters:
sb- TheCharSequencewhich 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.
-