Package opennlp.tools.postag
Class POSTaggerFactory
- java.lang.Object
-
- opennlp.tools.util.BaseToolFactory
-
- opennlp.tools.postag.POSTaggerFactory
-
public class POSTaggerFactory extends BaseToolFactory
The factory that providesPOSTagger
default implementations and resources.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
POSTaggerFactory.POSDictionarySerializer
-
Constructor Summary
Constructors Constructor Description POSTaggerFactory()
Initializes aPOSTaggerFactory
that provides the default implementation of the resources.POSTaggerFactory(byte[] featureGeneratorBytes, Map<String,Object> resources, TagDictionary posDictionary)
Initializes aPOSTaggerFactory
from a given set of the resources.
-
Method Summary
-
Methods inherited from class opennlp.tools.util.BaseToolFactory
create, create, createManifestEntries
-
-
-
-
Constructor Detail
-
POSTaggerFactory
public POSTaggerFactory()
Initializes aPOSTaggerFactory
that provides the default implementation of the resources.
-
POSTaggerFactory
public POSTaggerFactory(byte[] featureGeneratorBytes, Map<String,Object> resources, TagDictionary posDictionary)
Initializes aPOSTaggerFactory
from a given set of the resources.- Parameters:
featureGeneratorBytes
- The bytes for feature generation.resources
- Additional resources as key-value map.posDictionary
- ATagDictionary
used for the new instance.
-
-
Method Detail
-
createFeatureGenerators
public AdaptiveFeatureGenerator 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
null
if there is no descriptor in the model - Throws:
IllegalStateException
- Thrown if inconsistencies occurred during creation.
-
createArtifactSerializersMap
public Map<String,ArtifactSerializer> createArtifactSerializersMap()
Description copied from class:BaseToolFactory
Creates aMap
with pairs of keys andArtifactSerializer
. The models implementation should call this method fromBaseModel#createArtifactSerializersMap
.The base implementation will return a
HashMap
that should be populated by subclasses.- Overrides:
createArtifactSerializersMap
in classBaseToolFactory
-
createArtifactMap
public Map<String,Object> createArtifactMap()
Description copied from class:BaseToolFactory
A model's implementation should call this constructor that creates a model programmatically.The base implementation will return a
HashMap
that should be populated by subclasses.- Overrides:
createArtifactMap
in classBaseToolFactory
- Returns:
- Retrieves a
Map
with pairs of keys and objects.
-
createTagDictionary
public TagDictionary createTagDictionary(File dictionary) throws IOException
Initializes aTagDictionary
from adictionary file
.- Parameters:
dictionary
- TheFile
used for creating the dictionary.- Returns:
- A valid
TagDictionary
ready for use. - Throws:
IOException
- Thrown if IO errors occurred during creation.
-
createTagDictionary
public TagDictionary createTagDictionary(InputStream in) throws IOException
Initializes aTagDictionary
from adictionary stream
.- Parameters:
in
- TheInputStream
used for creating the dictionary.- Returns:
- A valid
TagDictionary
ready for use. - Throws:
IOException
- Thrown if IO errors occurred during creation.
-
setTagDictionary
public void setTagDictionary(TagDictionary dictionary)
-
getTagDictionary
public TagDictionary getTagDictionary()
- Returns:
- The
TagDictionary
used.
-
getPOSContextGenerator
public POSContextGenerator getPOSContextGenerator()
- Returns:
- The
POSContextGenerator
with a default cache size of0
.
-
getPOSContextGenerator
public POSContextGenerator getPOSContextGenerator(int cacheSize)
- Parameters:
cacheSize
- Must be greater than or equal to0
.- Returns:
- The
POSContextGenerator
configured with the givencacheSize
.
-
getSequenceValidator
public SequenceValidator<String> getSequenceValidator()
- Returns:
- The
SequenceValidator
used.
-
validateArtifactMap
public void validateArtifactMap() throws InvalidFormatException
Description copied from class:BaseToolFactory
Validates the parsed artifacts.Note: Subclasses should generally invoke
super.validateArtifactMap
at the beginning of this method.- Specified by:
validateArtifactMap
in classBaseToolFactory
- Throws:
InvalidFormatException
- Thrown if validation found invalid states.
-
create
public static POSTaggerFactory create(String subclassName, byte[] featureGeneratorBytes, Map<String,Object> resources, TagDictionary posDictionary) throws InvalidFormatException
Instantiates aPOSTaggerFactory
via a givensubclassName
.- Parameters:
subclassName
- The class name used for instantiation. Ifnull
, an instance ofPOSTaggerFactory
will be returned per default. Otherwise, theExtensionLoader
mechanism is applied to load the requestedsubclassName
.featureGeneratorBytes
- The bytes for feature generation.resources
- Additional resources as key-value map.posDictionary
- ATagDictionary
used for the new instance.- Returns:
- Throws:
InvalidFormatException
- Thrown if theExtensionLoader
mechanism failed to load the factory via thesubclassName
.
-
createEmptyTagDictionary
public TagDictionary createEmptyTagDictionary()
- Returns:
- An empty, case-sensitive
TagDictionary
.
-
-