Class BaseModel

Namespace
NOpenNLP.Tools.Util.Model
Assembly
NOpenNLP.Tools.dll

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

componentName string
modelFile FileInfo

BaseModel(string, Stream)

Initializes the current instance.

protected BaseModel(string componentName, Stream @in)

Parameters

componentName string

the component name

in Stream

the input stream containing the model

Exceptions

IOException

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

componentName string

the component name

languageCode string

the language code

manifestInfoEntries Dictionary<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

componentName string

the component name

languageCode string

the language code

manifestInfoEntries IDictionary<string, string>

additional information in the manifest

factory BaseToolFactory

the factory

Fields

FACTORY_NAME

protected const string FACTORY_NAME = "factory"

Field Value

string

MANIFEST_ENTRY

protected const string MANIFEST_ENTRY = "manifest.properties"

Field Value

string

TRAINING_CUTOFF_PROPERTY

public const string TRAINING_CUTOFF_PROPERTY = "Training-Cutoff"

Field Value

string

TRAINING_EVENTHASH_PROPERTY

public const string TRAINING_EVENTHASH_PROPERTY = "Training-Eventhash"

Field Value

string

TRAINING_ITERATIONS_PROPERTY

public const string TRAINING_ITERATIONS_PROPERTY = "Training-Iterations"

Field Value

string

artifactMap

protected readonly IDictionary<string, object> artifactMap

Field Value

IDictionary<string, object>

toolFactory

public BaseToolFactory toolFactory

Field Value

BaseToolFactory

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

IDictionary<string, IArtifactSerializer>

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

serializers IDictionary<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

resourceName string

Returns

IArtifactSerializer

GetArtifact<T>(string)

Gets an artifact by name

public virtual T? GetArtifact<T>(string key)

Parameters

key string

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

key string

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

model FileInfo

Exceptions

IOException

Serialize(Stream)

Serializes the model to the given Stream.

public void Serialize(Stream @out)

Parameters

out Stream

stream to write the model to

Exceptions

IOException

Serialize(string)

public void Serialize(string model)

Parameters

model string

Exceptions

IOException

SetManifestProperty(string, string)

Sets a given value for a given key to the manifest.properties entry.

protected void SetManifestProperty(string key, string value)

Parameters

key string
value string

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()

Exceptions

InvalidFormatException