public abstract class BaseModel extends Object implements ArtifactProvider
Modifier and Type | Field and Description |
---|---|
protected Map<String,Object> |
artifactMap |
protected static String |
FACTORY_NAME |
protected static String |
MANIFEST_ENTRY |
protected BaseToolFactory |
toolFactory |
static String |
TRAINING_CUTOFF_PROPERTY |
static String |
TRAINING_EVENTHASH_PROPERTY |
static String |
TRAINING_ITERATIONS_PROPERTY |
Modifier | Constructor and Description |
---|---|
protected |
BaseModel(String componentName,
File modelFile) |
protected |
BaseModel(String componentName,
InputStream in)
Initializes the current instance.
|
protected |
BaseModel(String componentName,
String languageCode,
Map<String,String> manifestInfoEntries)
Initializes the current instance.
|
protected |
BaseModel(String componentName,
String languageCode,
Map<String,String> manifestInfoEntries,
BaseToolFactory factory)
Initializes the current instance.
|
protected |
BaseModel(String componentName,
URL modelURL) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkArtifactMap()
Checks the artifact map.
|
protected static Map<String,ArtifactSerializer> |
createArtifactSerializers() |
protected void |
createArtifactSerializers(Map<String,ArtifactSerializer> serializers)
Registers all
ArtifactSerializer for their artifact file name extensions. |
<T> T |
getArtifact(String key)
Gets an artifact by name
|
protected ArtifactSerializer |
getArtifactSerializer(String resourceName) |
protected Class<? extends BaseToolFactory> |
getDefaultFactory()
Sub-classes should override this method if their module has a default
BaseToolFactory sub-class.
|
String |
getLanguage()
Retrieves the language code of the material which
was used to train the model or x-unspecified if
non was set.
|
String |
getManifestProperty(String key)
Retrieves the value to the given key from the manifest.properties
entry.
|
Version |
getVersion()
Retrieves the OpenNLP version which was used
to create the model.
|
boolean |
isLoadedFromSerialized()
Indicates if this provider was loaded from serialized.
|
void |
serialize(OutputStream out)
Serializes the model to the given
OutputStream . |
protected void |
setManifestProperty(String key,
String value)
Sets a given value for a given key to the manifest.properties entry.
|
protected void |
validateArtifactMap()
Validates the parsed artifacts.
|
protected static final String MANIFEST_ENTRY
protected static final String FACTORY_NAME
public static final String TRAINING_CUTOFF_PROPERTY
public static final String TRAINING_ITERATIONS_PROPERTY
public static final String TRAINING_EVENTHASH_PROPERTY
protected BaseToolFactory toolFactory
protected BaseModel(String componentName, String languageCode, Map<String,String> manifestInfoEntries, BaseToolFactory factory)
checkArtifactMap()
to check the artifact map is OK.
Sub-classes will have access to custom artifacts and serializers provided by the factory.
componentName
- the component namelanguageCode
- the language codemanifestInfoEntries
- additional information in the manifestfactory
- the factoryprotected BaseModel(String componentName, String languageCode, Map<String,String> manifestInfoEntries)
checkArtifactMap()
to check the artifact map is OK.componentName
- the component namelanguageCode
- the language codemanifestInfoEntries
- additional information in the manifestprotected BaseModel(String componentName, InputStream in) throws IOException, InvalidFormatException
componentName
- the component namein
- the input stream containing the modelIOException
InvalidFormatException
protected BaseModel(String componentName, File modelFile) throws IOException, InvalidFormatException
IOException
InvalidFormatException
protected BaseModel(String componentName, URL modelURL) throws IOException, InvalidFormatException
IOException
InvalidFormatException
protected Class<? extends BaseToolFactory> getDefaultFactory()
BaseToolFactory
for the module, or null if none.protected ArtifactSerializer getArtifactSerializer(String resourceName)
protected static Map<String,ArtifactSerializer> createArtifactSerializers()
protected void createArtifactSerializers(Map<String,ArtifactSerializer> serializers)
ArtifactSerializer
for their artifact file name extensions.
The registered ArtifactSerializer
are used to create and serialize
resources in the model package.
Override this method to register custom ArtifactSerializer
s.
Note:
Subclasses should generally invoke super.createArtifactSerializers at the beginning
of this method.
This method is called during construction.serializers
- the key of the map is the file extension used to lookup
the ArtifactSerializer
.protected void validateArtifactMap() throws InvalidFormatException
InvalidFormatException
.
Note:
Subclasses should generally invoke super.validateArtifactMap at the beginning
of this method.InvalidFormatException
protected void checkArtifactMap()
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.
public final String getManifestProperty(String key)
getManifestProperty
in interface ArtifactProvider
key
- protected final void setManifestProperty(String key, String value)
key
- value
- public final String getLanguage()
getLanguage
in interface ArtifactProvider
public final Version getVersion()
public final void serialize(OutputStream out) throws IOException
OutputStream
.out
- stream to write the model toIOException
public <T> T getArtifact(String key)
ArtifactProvider
getArtifact
in interface ArtifactProvider
public boolean isLoadedFromSerialized()
ArtifactProvider
isLoadedFromSerialized
in interface ArtifactProvider
Copyright © 2017 The Apache Software Foundation. All rights reserved.