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 provides `POSTagger` 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 a `POSTaggerFactory` that provides the default implementation of the resources.
  `POSTaggerFactory(byte[] featureGeneratorBytes, Map<String,Object> resources, TagDictionary posDictionary)`
  Initializes a `POSTaggerFactory` from a given set of the resources.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static POSTaggerFactory`
  `create(String subclassName, byte[] featureGeneratorBytes, Map<String,Object> resources, TagDictionary posDictionary)`
  Instantiates a `POSTaggerFactory` via a given `subclassName`.
  `Map<String,Object>`
  `createArtifactMap()`
  A model's implementation should call this constructor that creates a model programmatically.
  `Map<String,ArtifactSerializer<?>>`
  `createArtifactSerializersMap()`
  Creates a `Map` with pairs of keys and `ArtifactSerializer`.
  `TagDictionary`
  `createEmptyTagDictionary()`
  `AdaptiveFeatureGenerator`
  `createFeatureGenerators()`
  Creates the `AdaptiveFeatureGenerator`.
  `TagDictionary`
  `createTagDictionary(File dictionary)`
  Initializes a `TagDictionary` from a `dictionary file`.
  `TagDictionary`
  `createTagDictionary(InputStream in)`
  Initializes a `TagDictionary` from a `dictionary stream`.
  `POSContextGenerator`
  `getPOSContextGenerator()`
  `POSContextGenerator`
  `getPOSContextGenerator(int cacheSize)`
  `SequenceValidator<String>`
  `getSequenceValidator()`
  `TagDictionary`
  `getTagDictionary()`
  `void`
  `setTagDictionary(TagDictionary dictionary)`
  `void`
  `validateArtifactMap()`
  Validates the parsed artifacts.

  ### Methods inherited from class opennlp.tools.util.BaseToolFactory

  `create, create, createManifestEntries`

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### POSTaggerFactory

    public POSTaggerFactory()
    Initializes a `POSTaggerFactory` that provides the default implementation of the resources.

  - ### POSTaggerFactory

    public POSTaggerFactory(byte[] featureGeneratorBytes, Map<String,Object> resources, TagDictionary posDictionary)
    Initializes a `POSTaggerFactory` from a given set of the resources.
    Parameters:
      `featureGeneratorBytes` - The bytes for feature generation.
      `resources` - Additional resources as key-value map.
      `posDictionary` - A `TagDictionary` used for the new instance.

- ## Method Details

  - ### createFeatureGenerators

    public AdaptiveFeatureGenerator createFeatureGenerators()
    Creates the `AdaptiveFeatureGenerator`. Usually this is a set of generators contained in the `AggregatedFeatureGenerator`.

    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 a `Map` with pairs of keys and `ArtifactSerializer`. The models implementation should call this method from `BaseModel#createArtifactSerializersMap`.

    The base implementation will return a `HashMap` that should be populated by subclasses.

    Overrides:
      `createArtifactSerializersMap` in class `BaseToolFactory`

  - ### 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 class `BaseToolFactory`
    Returns:
      Retrieves a `Map` with pairs of keys and objects.

  - ### createTagDictionary

    public TagDictionary createTagDictionary(File dictionary) throws IOException
    Initializes a `TagDictionary` from a `dictionary file`.
    Parameters:
      `dictionary` - The `File` 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 a `TagDictionary` from a `dictionary stream`.
    Parameters:
      `in` - The `InputStream` 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 of `0`.

  - ### getPOSContextGenerator

    public POSContextGenerator getPOSContextGenerator(int cacheSize)
    Parameters:
      `cacheSize` - Must be greater than or equal to `0`.
    Returns:
      The `POSContextGenerator` configured with the given `cacheSize`.

  - ### 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 class `BaseToolFactory`
    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 a `POSTaggerFactory` via a given `subclassName`.
    Parameters:
      `subclassName` - The class name used for instantiation. If `null`, an instance of `POSTaggerFactory` will be returned per default. Otherwise, the `ExtensionLoader` mechanism is applied to load the requested `subclassName`.
      `featureGeneratorBytes` - The bytes for feature generation.
      `resources` - Additional resources as key-value map.
      `posDictionary` - A `TagDictionary` used for the new instance.
    Returns:
    Throws:
      `InvalidFormatException` - Thrown if the `ExtensionLoader` mechanism failed to load the factory via the `subclassName`.

  - ### createEmptyTagDictionary

    public TagDictionary createEmptyTagDictionary()
    Returns:
      An empty, case-sensitive `TagDictionary`.