Package opennlp.tools.util.model
Class BaseModel
- java.lang.Object
-
- opennlp.tools.util.model.BaseModel
-
- All Implemented Interfaces:
Serializable
,ArtifactProvider
- Direct Known Subclasses:
ChunkerModel
,DoccatModel
,LanguageDetectorModel
,LemmatizerModel
,ParserModel
,POSModel
,SentenceModel
,TokenizerModel
,TokenNameFinderModel
public abstract class BaseModel extends Object implements ArtifactProvider, Serializable
This is a common base model which can be used by the components' specific model classes.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
TRAINING_CUTOFF_PROPERTY
static String
TRAINING_EVENTHASH_PROPERTY
static String
TRAINING_ITERATIONS_PROPERTY
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
getArtifact(String key)
String
getLanguage()
String
getManifestProperty(String key)
Version
getVersion()
boolean
isLoadedFromSerialized()
Indicates if this provider was loaded from a serialized form.void
serialize(File f)
Serializes the model to the specifiedFile
.void
serialize(OutputStream out)
Serializes the model to the givenOutputStream
.void
serialize(Path p)
Serializes the model to the specifiedPath
.
-
-
-
Field Detail
-
TRAINING_CUTOFF_PROPERTY
public static final String TRAINING_CUTOFF_PROPERTY
- See Also:
- Constant Field Values
-
TRAINING_ITERATIONS_PROPERTY
public static final String TRAINING_ITERATIONS_PROPERTY
- See Also:
- Constant Field Values
-
TRAINING_EVENTHASH_PROPERTY
public static final String TRAINING_EVENTHASH_PROPERTY
- See Also:
- Constant Field Values
-
-
Method Detail
-
getManifestProperty
public final String getManifestProperty(String key)
- Specified by:
getManifestProperty
in interfaceArtifactProvider
- Parameters:
key
- A string identifying an element.- Returns:
- Retrieves the value for the given
key
from themanifest.properties
.
-
getLanguage
public final String getLanguage()
- Specified by:
getLanguage
in interfaceArtifactProvider
- Returns:
- Retrieves the language code of the material which was used to train a model
or
'x-unspecified'
if non was set.
-
getVersion
public final Version getVersion()
- Returns:
- Retrieves the OpenNLP
Version
which was used to create the model.
-
serialize
public final void serialize(OutputStream out) throws IOException
Serializes the model to the givenOutputStream
.- Parameters:
out
- TheOutputStream
to write the model to.- Throws:
IOException
- Thrown if IO errors occurred.IllegalStateException
- Thrown ifloadArtifactSerializers()
was not called in a subclass constructor.
-
serialize
public final void serialize(File f) throws IOException
Serializes the model to the specifiedFile
.- Parameters:
f
- The write-accessibleFile
to write the model to.- Throws:
IOException
- Thrown if IO errors occurred.IllegalStateException
- Thrown ifloadArtifactSerializers()
was not called in a subclass constructor.
-
serialize
public final void serialize(Path p) throws IOException
Serializes the model to the specifiedPath
.- Parameters:
p
- The write-accessiblePath
to write the model to.- Throws:
IOException
- Thrown if IO errors occurred.IllegalStateException
- Thrown ifloadArtifactSerializers()
was not called in a subclass constructor.
-
getArtifact
public <T> T getArtifact(String key)
- Specified by:
getArtifact
in interfaceArtifactProvider
- Returns:
- Gets an artifact by an identifying key or name.
-
isLoadedFromSerialized
public boolean isLoadedFromSerialized()
Description copied from interface:ArtifactProvider
Indicates if this provider was loaded from a serialized form. It is useful, for example, during the validation of artifacts: Skip the time-consuming ones if those were already validated during the serialization process.- Specified by:
isLoadedFromSerialized
in interfaceArtifactProvider
- Returns:
true
if this model was loaded from a serialized form,false
otherwise.
-
-