Class GeneratorFactory
- java.lang.Object
-
- opennlp.tools.util.featuregen.GeneratorFactory
-
public class GeneratorFactory extends java.lang.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 aGeneratorFactory.XmlFeatureGeneratorFactory
which is responsible to process the element and create the specifiedAdaptiveFeatureGenerator
. Elements can contain other elements in this case it is the responsibility of the mapped factory to process the child elements correctly. In some factories this leads to recursive calls theGeneratorFactory.XmlFeatureGeneratorFactory.create(Element, FeatureGeneratorResourceProvider)
method. In the example above the generators element is mapped to theAggregatedFeatureGeneratorFactory
which then creates all the aggregatedAdaptiveFeatureGenerator
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 theAggregatedFeatureGenerator
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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AdaptiveFeatureGenerator
create(java.io.InputStream xmlDescriptorIn, FeatureGeneratorResourceProvider resourceManager)
Creates anAdaptiveFeatureGenerator
from an provided XML descriptor.static java.util.Map<java.lang.String,ArtifactSerializer<?>>
extractArtifactSerializerMappings(java.io.InputStream xmlDescriptorIn)
static java.util.List<org.w3c.dom.Element>
getDescriptorElements(java.io.InputStream xmlDescriptorIn)
Provides a list with all the elements in the xml feature descriptor.
-
-
-
Method Detail
-
create
public static AdaptiveFeatureGenerator create(java.io.InputStream xmlDescriptorIn, FeatureGeneratorResourceProvider resourceManager) throws java.io.IOException
Creates anAdaptiveFeatureGenerator
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
- theInputStream
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:
java.io.IOException
- if an error occurs during reading from the descriptorInputStream
-
extractArtifactSerializerMappings
public static java.util.Map<java.lang.String,ArtifactSerializer<?>> extractArtifactSerializerMappings(java.io.InputStream xmlDescriptorIn) throws java.io.IOException
- Throws:
java.io.IOException
-
getDescriptorElements
public static java.util.List<org.w3c.dom.Element> getDescriptorElements(java.io.InputStream xmlDescriptorIn) throws java.io.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:
java.io.IOException
- if inputstream cannot be openInvalidFormatException
- if xml is not well-formed
-
-