Package opennlp.tools.doccat
Class DocumentCategorizerME
java.lang.Object
opennlp.tools.doccat.DocumentCategorizerME
- All Implemented Interfaces:
DocumentCategorizer
A Max-Ent based implementation of
DocumentCategorizer
.-
Constructor Summary
ConstructorDescriptionDocumentCategorizerME
(DoccatModel model) Initializes aDocumentCategorizerME
instance with a doccat model. -
Method Summary
Modifier and TypeMethodDescriptiondouble[]
categorize
(String[] text) Categorizes the giventext
, provided in separate tokens.double[]
categorize
(String[] text, Map<String, Object> extraInformation) Categorize the giventext
provided as tokens along with the provided extra information.getAllResults
(double[] results) Retrieves the name of the category associated with the given probabilities.getBestCategory
(double[] outcome) Retrieves the best category from previously generatedoutcome
probabilitiesgetCategory
(int index) Retrieves the category at a givenindex
.int
Retrieves the index of a certain category.int
Retrieves the number of categories.Retrieves aMap
in which the key is the category name and the value is the score.sortedScoreMap
(String[] text) Retrieves aSortedMap
of the scores sorted in ascending order, together with their associated categories.static DoccatModel
train
(String lang, ObjectStream<DocumentSample> samples, TrainingParameters mlParams, DoccatFactory factory) Starts a training of aDoccatModel
with the given parameters.
-
Constructor Details
-
DocumentCategorizerME
Initializes aDocumentCategorizerME
instance with a doccat model. Default feature generation is used.- Parameters:
model
- theDoccatModel
to be used for categorization.
-
-
Method Details
-
categorize
Categorize the giventext
provided as tokens along with the provided extra information.- Specified by:
categorize
in interfaceDocumentCategorizer
- Parameters:
text
- The text tokens to categorize.extraInformation
- Additional information for context to be used by the feature generator.- Returns:
- The per category probabilities.
-
categorize
Description copied from interface:DocumentCategorizer
Categorizes the giventext
, provided in separate tokens.- Specified by:
categorize
in interfaceDocumentCategorizer
- Parameters:
text
- The tokens of text to categorize.- Returns:
- The per category probabilities.
-
scoreMap
Description copied from interface:DocumentCategorizer
Retrieves aMap
in which the key is the category name and the value is the score.- Specified by:
scoreMap
in interfaceDocumentCategorizer
- Parameters:
text
- The tokenized input text to classify.- Returns:
- A
Map
with the score as a key.
-
sortedScoreMap
Description copied from interface:DocumentCategorizer
Retrieves aSortedMap
of the scores sorted in ascending order, together with their associated categories.Many categories can have the same score, hence the
Set
as value.- Specified by:
sortedScoreMap
in interfaceDocumentCategorizer
- Parameters:
text
- the input text to classify- Returns:
- A
SortedMap
with the score as a key.
-
getBestCategory
Description copied from interface:DocumentCategorizer
Retrieves the best category from previously generatedoutcome
probabilities- Specified by:
getBestCategory
in interfaceDocumentCategorizer
- Parameters:
outcome
- An array of computed outcome probabilities.- Returns:
- The best category represented as String.
-
getIndex
Description copied from interface:DocumentCategorizer
Retrieves the index of a certain category.- Specified by:
getIndex
in interfaceDocumentCategorizer
- Parameters:
category
- The category for which theindex
is to be found.- Returns:
- The index.
-
getCategory
Description copied from interface:DocumentCategorizer
Retrieves the category at a givenindex
.- Specified by:
getCategory
in interfaceDocumentCategorizer
- Parameters:
index
- The index for which thecategory
shall be found.- Returns:
- The category represented as String.
-
getNumberOfCategories
public int getNumberOfCategories()Description copied from interface:DocumentCategorizer
Retrieves the number of categories.- Specified by:
getNumberOfCategories
in interfaceDocumentCategorizer
- Returns:
- The no. of categories.
-
getAllResults
Description copied from interface:DocumentCategorizer
Retrieves the name of the category associated with the given probabilities.- Specified by:
getAllResults
in interfaceDocumentCategorizer
- Parameters:
results
- The probabilities of each category.- Returns:
- The name of the outcome.
-
train
public static DoccatModel train(String lang, ObjectStream<DocumentSample> samples, TrainingParameters mlParams, DoccatFactory factory) throws IOException Starts a training of aDoccatModel
with the given parameters.- Parameters:
lang
- The ISO conform language code.samples
- TheObjectStream
ofDocumentSample
used as input for training.mlParams
- TheTrainingParameters
for the context of the training.factory
- TheDoccatFactory
for creating related objects defined viamlParams
.- Returns:
- A valid, trained
DoccatModel
instance. - Throws:
IOException
- Thrown if IO errors occurred.
-