Class BaseModel
This model is a common based which can be used by the components model classes.
TODO: Provide sub classes access to serializers already in constructor
public abstract class BaseModel : IArtifactProvider
- Inheritance
-
BaseModel
- Implements
- Derived
- Inherited Members
Constructors
BaseModel(string, FileInfo)
protected BaseModel(string componentName, FileInfo modelFile)
Parameters
BaseModel(string, Stream)
Initializes the current instance.
protected BaseModel(string componentName, Stream @in)
Parameters
Exceptions
BaseModel(string, string, Dictionary<string, string>)
Initializes the current instance. The sub-class constructor should call the
method CheckArtifactMap() to check the artifact map is OK.
protected BaseModel(string componentName, string languageCode, Dictionary<string, string> manifestInfoEntries)
Parameters
componentNamestringthe component name
languageCodestringthe language code
manifestInfoEntriesDictionary<string, string>additional information in the manifest
BaseModel(string, string?, IDictionary<string, string>?, BaseToolFactory?)
Initializes the current instance. The sub-class constructor should call the
method CheckArtifactMap() to check the artifact map is OK.
Sub-classes will have access to custom artifacts and serializers provided by the factory.
protected BaseModel(string componentName, string? languageCode, IDictionary<string, string>? manifestInfoEntries, BaseToolFactory? factory)
Parameters
componentNamestringthe component name
languageCodestringthe language code
manifestInfoEntriesIDictionary<string, string>additional information in the manifest
factoryBaseToolFactorythe factory
Fields
FACTORY_NAME
protected const string FACTORY_NAME = "factory"
Field Value
MANIFEST_ENTRY
protected const string MANIFEST_ENTRY = "manifest.properties"
Field Value
TRAINING_CUTOFF_PROPERTY
public const string TRAINING_CUTOFF_PROPERTY = "Training-Cutoff"
Field Value
TRAINING_EVENTHASH_PROPERTY
public const string TRAINING_EVENTHASH_PROPERTY = "Training-Eventhash"
Field Value
TRAINING_ITERATIONS_PROPERTY
public const string TRAINING_ITERATIONS_PROPERTY = "Training-Iterations"
Field Value
artifactMap
protected readonly IDictionary<string, object> artifactMap
Field Value
toolFactory
public BaseToolFactory toolFactory
Field Value
Properties
DefaultFactory
Sub-classes should override this method if their module has a default BaseToolFactory sub-class.
protected virtual Type? DefaultFactory { get; }
Property Value
- Type
the default BaseToolFactory for the module, or null if none.
Language
Retrieves the language code of the material which was used to train the model or x-unspecified if non was set.
public string Language { get; }
Property Value
- string
the language code of this model
Version
Retrieves the OpenNLP version which was used to create the model.
public Version Version { get; }
Property Value
- Version
the version
Methods
CheckArtifactMap()
Checks the artifact map.
A subclass should call this method from a constructor which accepts the individual artifact map items, to validate that these items form a valid model.
If the artifacts are not valid an IllegalArgumentException will be thrown.
protected virtual void CheckArtifactMap()
CreateArtifactSerializers()
public static IDictionary<string, IArtifactSerializer> CreateArtifactSerializers()
Returns
CreateArtifactSerializers(IDictionary<string, IArtifactSerializer>)
Registers all IArtifactSerializer for their artifact file name extensions. The registered IArtifactSerializer are used to create and serialize resources in the model package.
Override this method to register custom IArtifactSerializers.
Note: Subclasses should generally invoke super.createArtifactSerializers at the beginning of this method.
This method is called during construction.
public virtual void CreateArtifactSerializers(IDictionary<string, IArtifactSerializer> serializers)
Parameters
serializersIDictionary<string, IArtifactSerializer>the key of the map is the file extension used to lookup the IArtifactSerializer.
GetArtifactSerializer(string)
public virtual IArtifactSerializer? GetArtifactSerializer(string resourceName)
Parameters
resourceNamestring
Returns
GetArtifact<T>(string)
Gets an artifact by name
public virtual T? GetArtifact<T>(string key)
Parameters
keystring
Returns
- T
Type Parameters
T
GetManifestProperty(string)
Retrieves the value to the given key from the manifest.properties entry.
public string? GetManifestProperty(string key)
Parameters
keystring
Returns
- string
the value
IsLoadedFromSerialized()
Indicates if this provider was loaded from serialized. It is useful, for example, while validating artifacts: you can skip the time consuming ones if they where already validated during the serialization.
public virtual bool IsLoadedFromSerialized()
Returns
- bool
true if this model was loaded from serialized
Serialize(FileInfo)
public void Serialize(FileInfo model)
Parameters
modelFileInfo
Exceptions
Serialize(Stream)
Serializes the model to the given Stream.
public void Serialize(Stream @out)
Parameters
outStreamstream to write the model to
Exceptions
Serialize(string)
public void Serialize(string model)
Parameters
modelstring
Exceptions
SetManifestProperty(string, string)
Sets a given value for a given key to the manifest.properties entry.
protected void SetManifestProperty(string key, string value)
Parameters
ValidateArtifactMap()
Validates the parsed artifacts. If something is not valid subclasses should throw an InvalidFormatException.
Note: Subclasses should generally invoke super.validateArtifactMap at the beginning of this method.
protected virtual void ValidateArtifactMap()