Class POSTaggerFactory
java.lang.Object
opennlp.tools.util.BaseToolFactory
opennlp.tools.postag.POSTaggerFactory
- Direct Known Subclasses:
MorfologikPOSTaggerFactory
The factory that provides
POSTagger default implementations and resources.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]private static final Stringprotected Dictionaryprotected TagDictionaryprivate static final StringFields inherited from class BaseToolFactory
artifactProvider -
Constructor Summary
ConstructorsConstructorDescriptionInitializes aPOSTaggerFactorythat provides the default implementation of the resources.POSTaggerFactory(byte[] featureGeneratorBytes, Map<String, Object> resources, TagDictionary posDictionary) Initializes aPOSTaggerFactoryfrom a given set of the resources.POSTaggerFactory(Dictionary ngramDictionary, TagDictionary posDictionary) Deprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionstatic POSTaggerFactorycreate(String subclassName, byte[] featureGeneratorBytes, Map<String, Object> resources, TagDictionary posDictionary) Instantiates aPOSTaggerFactoryvia a givensubclassName.(package private) static POSTaggerFactorycreate(String subclassName, Dictionary ngramDictionary, TagDictionary posDictionary) Deprecated.A model's implementation should call this constructor that creates a model programmatically.Map<String, ArtifactSerializer<?>> Creates aMapwith pairs of keys andArtifactSerializer.Creates theAdaptiveFeatureGenerator.createTagDictionary(File dictionary) Initializes aTagDictionaryfrom adictionary file.Initializes aTagDictionaryfrom adictionary stream.private DictionaryDeprecated, for removal: This API element is subject to removal in a future version.protected byte[]getPOSContextGenerator(int cacheSize) protected voidinit(byte[] featureGeneratorBytes, Map<String, Object> resources, TagDictionary posDictionary) (package private) voidinit(Dictionary ngramDictionary, TagDictionary posDictionary) Deprecated, for removal: This API element is subject to removal in a future version.private static byte[]voidsetTagDictionary(TagDictionary dictionary) voidValidates the parsed artifacts.protected voidvalidatePOSDictionary(POSDictionary posDict, AbstractModel posModel) Methods inherited from class BaseToolFactory
create, create, createManifestEntries, init
-
Field Details
-
TAG_DICTIONARY_ENTRY_NAME
- See Also:
-
NGRAM_DICTIONARY_ENTRY_NAME
- See Also:
-
ngramDictionary
-
featureGeneratorBytes
private byte[] featureGeneratorBytes -
resources
-
posDictionary
-
-
Constructor Details
-
POSTaggerFactory
public POSTaggerFactory()Initializes aPOSTaggerFactorythat provides the default implementation of the resources. -
POSTaggerFactory
public POSTaggerFactory(byte[] featureGeneratorBytes, Map<String, Object> resources, TagDictionary posDictionary) Initializes aPOSTaggerFactoryfrom a given set of the resources.- Parameters:
featureGeneratorBytes- The bytes for feature generation.resources- Additional resources as key-value map.posDictionary- ATagDictionaryused for the new instance.
-
POSTaggerFactory
@Deprecated(forRemoval=true) POSTaggerFactory(Dictionary ngramDictionary, TagDictionary posDictionary) Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Details
-
init
Deprecated, for removal: This API element is subject to removal in a future version. -
init
protected void init(byte[] featureGeneratorBytes, Map<String, Object> resources, TagDictionary posDictionary) -
loadDefaultFeatureGeneratorBytes
private static byte[] loadDefaultFeatureGeneratorBytes() -
createFeatureGenerators
Creates theAdaptiveFeatureGenerator. Usually this is a set of generators contained in theAggregatedFeatureGenerator.Note: The generators are created on every call to this method.
- Returns:
- the feature generator or
nullif there is no descriptor in the model - Throws:
IllegalStateException- Thrown if inconsistencies occurred during creation.
-
createArtifactSerializersMap
Description copied from class:BaseToolFactoryCreates aMapwith pairs of keys andArtifactSerializer. The models implementation should call this method fromBaseModel#createArtifactSerializersMap.The base implementation will return a
HashMapthat should be populated by subclasses.- Overrides:
createArtifactSerializersMapin classBaseToolFactory
-
createArtifactMap
Description copied from class:BaseToolFactoryA model's implementation should call this constructor that creates a model programmatically.The base implementation will return a
HashMapthat should be populated by subclasses.- Overrides:
createArtifactMapin classBaseToolFactory- Returns:
- Retrieves a
Mapwith pairs of keys and objects.
-
createTagDictionary
Initializes aTagDictionaryfrom adictionary file.- Parameters:
dictionary- TheFileused for creating the dictionary.- Returns:
- A valid
TagDictionaryready for use. - Throws:
IOException- Thrown if IO errors occurred during creation.
-
createTagDictionary
Initializes aTagDictionaryfrom adictionary stream.- Parameters:
in- TheInputStreamused for creating the dictionary.- Returns:
- A valid
TagDictionaryready for use. - Throws:
IOException- Thrown if IO errors occurred during creation.
-
setTagDictionary
-
getResources
-
getFeatureGenerator
protected byte[] getFeatureGenerator()- Returns:
- The feature generator bytes used.
-
getTagDictionary
- Returns:
- The
TagDictionaryused.
-
getDictionary
Deprecated, for removal: This API element is subject to removal in a future version. -
getPOSContextGenerator
- Returns:
- The
POSContextGeneratorwith a default cache size of0.
-
getPOSContextGenerator
- Parameters:
cacheSize- Must be greater than or equal to0.- Returns:
- The
POSContextGeneratorconfigured with the givencacheSize.
-
getSequenceValidator
- Returns:
- The
SequenceValidatorused.
-
validatePOSDictionary
protected void validatePOSDictionary(POSDictionary posDict, AbstractModel posModel) throws InvalidFormatException - Throws:
InvalidFormatException
-
validateArtifactMap
Description copied from class:BaseToolFactoryValidates the parsed artifacts.Note: Subclasses should generally invoke
super.validateArtifactMapat the beginning of this method.- Specified by:
validateArtifactMapin classBaseToolFactory- Throws:
InvalidFormatException- Thrown if validation found invalid states.
-
create
@Deprecated static POSTaggerFactory create(String subclassName, Dictionary ngramDictionary, TagDictionary posDictionary) throws InvalidFormatException Deprecated.- Throws:
InvalidFormatException
-
create
public static POSTaggerFactory create(String subclassName, byte[] featureGeneratorBytes, Map<String, Object> resources, TagDictionary posDictionary) throws InvalidFormatExceptionInstantiates aPOSTaggerFactoryvia a givensubclassName.- Parameters:
subclassName- The class name used for instantiation. Ifnull, an instance ofPOSTaggerFactorywill be returned per default. Otherwise, theExtensionLoadermechanism is applied to load the requestedsubclassName.featureGeneratorBytes- The bytes for feature generation.resources- Additional resources as key-value map.posDictionary- ATagDictionaryused for the new instance.- Returns:
- @return A valid
POSTaggerFactoryinstance. - Throws:
InvalidFormatException- Thrown if theExtensionLoadermechanism failed to load the factory via thesubclassName.
-
createEmptyTagDictionary
- Returns:
- An empty, case-sensitive
TagDictionary.
-