Class GeneratorFactory
- Namespace
- NOpenNLP.Tools.Util.Featuregen
- Assembly
- NOpenNLP.Tools.dll
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.IXmlFeatureGeneratorFactory which
is responsible to process the element and create the specified
IAdaptiveFeatureGenerator. 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 the
GeneratorFactory.IXmlFeatureGeneratorFactory.Create
method.
In the example above the generators element is mapped to the AggregatedFeatureGeneratorFactory which then creates all the aggregated IAdaptiveFeatureGenerators 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.
public static class GeneratorFactory
- Inheritance
-
GeneratorFactory
- Inherited Members
Methods
Create(Stream, FeatureGeneratorResourceProvider)
Creates an IAdaptiveFeatureGenerator 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.
public static IAdaptiveFeatureGenerator? Create(Stream xmlDescriptorIn, FeatureGeneratorResourceProvider resourceManager)
Parameters
xmlDescriptorInStreamthe Stream from which the descriptor is read, the stream remains open and must be closed by the caller.
resourceManagerFeatureGeneratorResourceProviderthe resource manager which is used to resolve resources referenced by a key in the descriptor
Returns
- IAdaptiveFeatureGenerator
created feature generators
Exceptions
- IOException
if an error occurs during reading from the descriptor Stream
ExtractArtifactSerializerMappings(Stream)
public static Dictionary<string, IArtifactSerializer> ExtractArtifactSerializerMappings(Stream xmlDescriptorIn)
Parameters
xmlDescriptorInStream
Returns
- Dictionary<string, IArtifactSerializer>
GetDescriptorElements(Stream)
Provides a list with all the elements in the xml feature descriptor.
public static IList<XmlElement> GetDescriptorElements(Stream xmlDescriptorIn)
Parameters
xmlDescriptorInStreamthe xml feature descriptor
Returns
- IList<XmlElement>
a list containing all elements
Exceptions
- IOException
if inputstream cannot be open
- InvalidFormatException
if xml is not well-formed