Package opennlp.tools.namefind
Class NameSample
java.lang.Object
opennlp.tools.namefind.NameSample
- All Implemented Interfaces:
Serializable,Sample
Encapsulates names for a single unit of text.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String[][]static final StringThe default type value when there is no type in training data.static final Stringprivate final Stringprivate final booleanprivate static final longstatic final Stringstatic final Stringprivate static final charEnds a start tag.private static final charSeparates<STARTfrom the name type in a start tag. -
Constructor Summary
ConstructorsConstructorDescriptionNameSample(String[] sentence, Span[] names, boolean clearAdaptiveData) Initializes aNameSampleinstance with given parameters.NameSample(String[] sentence, Span[] names, String[][] additionalContext, boolean clearAdaptiveData) Initializes aNameSampleinstance with given parameters.NameSample(String id, String[] sentence, Span[] names, String[][] additionalContext, boolean clearAdaptiveData) Initializes aNameSampleinstance with given parameters. -
Method Summary
Modifier and TypeMethodDescriptionbooleanprivate static StringerrorTokenWithContext(String[] sentence, int index) String[][]getId()Span[]getNames()String[]inthashCode()booleanprivate static booleanisStartTag(String token) Checks whether a token is a start tag, either<START>or<START:type>, where the possibly empty type contains neither':','>'nor ASCII whitespace.static NameSampleParses given input into aNameSample.static NameSampleParses given input into aNameSample.private static StringstartTagType(String startTag) Extracts the type of a start tag accepted byisStartTag(String).toString()
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
START_TAG_PREFIX
- See Also:
-
START_TAG
- See Also:
-
END_TAG
- See Also:
-
TYPE_SEPARATOR
private static final char TYPE_SEPARATORSeparates<STARTfrom the name type in a start tag.- See Also:
-
TAG_END
private static final char TAG_ENDEnds a start tag.- See Also:
-
id
-
sentence
-
names
-
additionalContext
-
isClearAdaptiveData
private final boolean isClearAdaptiveData -
DEFAULT_TYPE
The default type value when there is no type in training data.- See Also:
-
-
Constructor Details
-
NameSample
public NameSample(String id, String[] sentence, Span[] names, String[][] additionalContext, boolean clearAdaptiveData) Initializes aNameSampleinstance with given parameters.- Parameters:
id- The identifier to use.sentence- The tokens representing a training sentence. Must not benull.names- Thenamesto use.additionalContext- Additional context in a 2-dimensional array.clearAdaptiveData- Iftruethe adaptive data of the feature generators is cleared.- Throws:
IllegalArgumentException- Thrown ifsentenceisnull.RuntimeException- Thrown if name spans are overlapping.
-
NameSample
public NameSample(String[] sentence, Span[] names, String[][] additionalContext, boolean clearAdaptiveData) Initializes aNameSampleinstance with given parameters.- Parameters:
sentence- The tokens representing a sentence. Must not benull.names- Thenamesto use.additionalContext- Additional context in a 2-dimensional array.clearAdaptiveData- Iftruethe adaptive data of the feature generators is cleared.- Throws:
IllegalArgumentException- Thrown ifsentenceisnull.RuntimeException- Thrown if name spans are overlapping.
-
NameSample
Initializes aNameSampleinstance with given parameters.- Parameters:
sentence- The tokens representing a sentence. Must not benull.names- Thenamesto use.clearAdaptiveData- Iftruethe adaptive data of the feature generators is cleared.- Throws:
IllegalArgumentException- Thrown ifsentenceisnull.RuntimeException- Thrown if name spans are overlapping.
-
-
Method Details
-
getId
- Returns:
- Retrieves the current identifier. May be
null.
-
getSentence
- Returns:
- Retrieves the sentence in tokenized form.
-
getNames
- Returns:
- Retrieves the
names.
-
getAdditionalContext
- Returns:
- Retrieves additional context. May be
null.
-
isClearAdaptiveDataSet
public boolean isClearAdaptiveDataSet()- Returns:
trueif the adaptive data of the feature generators are cleared,falseotherwise.
-
hashCode
public int hashCode() -
equals
-
toString
-
errorTokenWithContext
-
isStartTag
Checks whether a token is a start tag, either<START>or<START:type>, where the possibly empty type contains neither':','>'nor ASCII whitespace.- Parameters:
token- The token to test.- Returns:
trueiftokenis a start tag.
-
startTagType
Extracts the type of a start tag accepted byisStartTag(String).- Parameters:
startTag- A start tag.- Returns:
- The type, which is empty for
<START:>, ornullfor<START>.
-
parse
Parses given input into aNameSample.- Parameters:
taggedTokens- The input data to parse.clearAdaptiveData-trueif the adaptive data of the feature generators should be cleared,falseotherwise.- Returns:
- A
NameSampleinstance resulting from the parsing. - Throws:
IOException- Thrown if IO errors occurred during parsing.
-
parse
public static NameSample parse(String taggedTokens, String defaultType, boolean clearAdaptiveData) throws IOException Parses given input into aNameSample.- Parameters:
taggedTokens- The input data to parse.defaultType- The type to set by default.clearAdaptiveData-trueif the adaptive data of the feature generators should be cleared,falseotherwise.- Returns:
- A
NameSampleinstance resulting from the parsing. - Throws:
IOException- Thrown if IO errors occurred during parsing.
-