Package opennlp.tools.util.featuregen

# Class GeneratorFactory

java.lang.Object
opennlp.tools.util.featuregen.GeneratorFactory

public class GeneratorFactory extends Object
Creates a set of feature generators based on a provided XML descriptor.

Example of an XML descriptor:

<featureGenerators name="namefind"> <generator class="opennlp.tools.util.featuregen.CachedFeatureGeneratorFactory"> <generator class="opennlp.tools.util.featuregen.WindowFeatureGeneratorFactory"> <int name="prevLength">2</int> <int name="nextLength">2</int> <generator class="opennlp.tools.util.featuregen.TokenClassFeatureGeneratorFactory"/> </generator> <generator class="opennlp.tools.util.featuregen.WindowFeatureGeneratorFactory"> <int name="prevLength">2</int> <int name="nextLength">2</int> <generator class="opennlp.tools.util.featuregen.TokenFeatureGeneratorFactory"/> </generator> <generator class="opennlp.tools.util.featuregen.DefinitionFeatureGeneratorFactory"/> <generator class="opennlp.tools.util.featuregen.PreviousMapFeatureGeneratorFactory"/> <generator class="opennlp.tools.util.featuregen.BigramNameFeatureGeneratorFactory"/> <generator class="opennlp.tools.util.featuregen.SentenceFeatureGeneratorFactory"> <bool name="begin">true</bool> <bool name="end">false</bool> </generator> </generator> </featureGenerators>

Each XML element is mapped to a `GeneratorFactory.AbstractXmlFeatureGeneratorFactory` which is responsible to process the element and create the specified `AdaptiveFeatureGenerator`. Elements can contain other elements in this case it is the responsibility of the mapped factory to process the child elements correctly.

In the example above the generators element is mapped to the `AggregatedFeatureGeneratorFactory` which then creates all the aggregated `AdaptiveFeatureGenerator`s to accomplish this it evaluates the mapping with the same mechanism and gives the child element to the corresponding factories. All created generators are added to a new instance of the `AggregatedFeatureGenerator` which is then returned.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `GeneratorFactory.AbstractXmlFeatureGeneratorFactory`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GeneratorFactory()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static opennlp.tools.util.featuregen.AdaptiveFeatureGenerator`
  `create(InputStream xmlDescriptorIn, opennlp.tools.util.featuregen.FeatureGeneratorResourceProvider resourceManager)`
  Creates an `AdaptiveFeatureGenerator` from an provided XML descriptor.
  `static Map<String,opennlp.tools.util.model.ArtifactSerializer<?>>`
  `extractArtifactSerializerMappings(InputStream xmlDescriptorIn)`
  `static List<Element>`
  `getDescriptorElements(InputStream xmlDescriptorIn)`
  Provides a `List` with all the elements in the xml feature descriptor.

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

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

- ## Constructor Details

  - ### GeneratorFactory

    public GeneratorFactory()

- ## Method Details

  - ### create

    public static opennlp.tools.util.featuregen.AdaptiveFeatureGenerator create(InputStream xmlDescriptorIn, opennlp.tools.util.featuregen.FeatureGeneratorResourceProvider resourceManager) throws IOException
    Creates an `AdaptiveFeatureGenerator` from an provided XML descriptor.

    Usually this XML descriptor contains a set of nested feature generators which are then used to generate the features by one of the opennlp components.

    Parameters:
      `xmlDescriptorIn` - the `InputStream` from which the descriptor is read, the stream remains open and must be closed by the caller.
      `resourceManager` - the resource manager which is used to resolve resources referenced by a key in the descriptor
    Returns:
      created feature generators
    Throws:
      `IOException` - if an error occurs during reading from the descriptor `InputStream`

  - ### extractArtifactSerializerMappings

    public static Map<String,opennlp.tools.util.model.ArtifactSerializer<?>> extractArtifactSerializerMappings(InputStream xmlDescriptorIn) throws IOException
    Throws:
      `IOException`

  - ### getDescriptorElements

    public static List<Element> getDescriptorElements(InputStream xmlDescriptorIn) throws IOException
    Provides a `List` with all the elements in the xml feature descriptor.
    Parameters:
      `xmlDescriptorIn` - the xml feature descriptor
    Returns:
      a list containing all elements
    Throws:
      `IOException` - if the given `InputStream` cannot be open
      `opennlp.tools.util.InvalidFormatException` - if xml is not well-formed