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
ConstructorsConstructorDescriptionDocumentCategorizerME(DoccatModel model) Initializes aDocumentCategorizerMEinstance 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 giventextprovided 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 generatedoutcomeprobabilitiesgetCategory(int index) Retrieves the category at a givenindex.intRetrieves the index of a certain category.intRetrieves the number of categories.Retrieves aMapin which the key is the category name and the value is the score.sortedScoreMap(String[] text) Retrieves aSortedMapof the scores sorted in ascending order, together with their associated categories.static DoccatModeltrain(String lang, ObjectStream<DocumentSample> samples, TrainingParameters mlParams, DoccatFactory factory) Starts a training of aDoccatModelwith the given parameters.
-
Constructor Details
-
DocumentCategorizerME
Initializes aDocumentCategorizerMEinstance with a doccat model. Default feature generation is used.- Parameters:
model- theDoccatModelto be used for categorization.
-
-
Method Details
-
categorize
Categorize the giventextprovided as tokens along with the provided extra information.- Specified by:
categorizein 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:DocumentCategorizerCategorizes the giventext, provided in separate tokens.- Specified by:
categorizein interfaceDocumentCategorizer- Parameters:
text- The tokens of text to categorize.- Returns:
- The per category probabilities.
-
scoreMap
Description copied from interface:DocumentCategorizerRetrieves aMapin which the key is the category name and the value is the score.- Specified by:
scoreMapin interfaceDocumentCategorizer- Parameters:
text- The tokenized input text to classify.- Returns:
- A
Mapwith the score as a key.
-
sortedScoreMap
Description copied from interface:DocumentCategorizerRetrieves aSortedMapof the scores sorted in ascending order, together with their associated categories.Many categories can have the same score, hence the
Setas value.- Specified by:
sortedScoreMapin interfaceDocumentCategorizer- Parameters:
text- the input text to classify- Returns:
- A
SortedMapwith the score as a key.
-
getBestCategory
Description copied from interface:DocumentCategorizerRetrieves the best category from previously generatedoutcomeprobabilities- Specified by:
getBestCategoryin interfaceDocumentCategorizer- Parameters:
outcome- An array of computed outcome probabilities.- Returns:
- The best category represented as String.
-
getIndex
Description copied from interface:DocumentCategorizerRetrieves the index of a certain category.- Specified by:
getIndexin interfaceDocumentCategorizer- Parameters:
category- The category for which theindexis to be found.- Returns:
- The index.
-
getCategory
Description copied from interface:DocumentCategorizerRetrieves the category at a givenindex.- Specified by:
getCategoryin interfaceDocumentCategorizer- Parameters:
index- The index for which thecategoryshall be found.- Returns:
- The category represented as String.
-
getNumberOfCategories
public int getNumberOfCategories()Description copied from interface:DocumentCategorizerRetrieves the number of categories.- Specified by:
getNumberOfCategoriesin interfaceDocumentCategorizer- Returns:
- The no. of categories.
-
getAllResults
Description copied from interface:DocumentCategorizerRetrieves the name of the category associated with the given probabilities.- Specified by:
getAllResultsin 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 aDoccatModelwith the given parameters.- Parameters:
lang- The ISO conform language code.samples- TheObjectStreamofDocumentSampleused as input for training.mlParams- TheTrainingParametersfor the context of the training.factory- TheDoccatFactoryfor creating related objects defined viamlParams.- Returns:
- A valid, trained
DoccatModelinstance. - Throws:
IOException- Thrown if IO errors occurred.
-