public abstract class JarClassifierBuilder<CLASSIFIER_TYPE> extends Object
EncodingJarClassifierBuilder.
Subclasses will typically override:
saveToTrainingDirectory(File) to add items to the model training directorypackageClassifier(File, JarOutputStream) to copy items to the classifier jarunpackageClassifier(JarInputStream) to load items from the classifier jarnewClassifier() to create a classifier from the loaded attributes| Modifier and Type | Field and Description |
|---|---|
protected Manifest |
manifest
The manifest associated with this classifier builder.
|
| Constructor and Description |
|---|
JarClassifierBuilder()
Creates a new classifier builder with a default manifest.
|
| Modifier and Type | Method and Description |
|---|---|
static JarClassifierBuilder<?> |
fromManifest(Manifest manifest)
Loads a classifier builder from a manifest.
|
static JarClassifierBuilder<?> |
fromTrainingDirectory(File dir)
Loads a classifier builder from manifest in the training directory.
|
static File |
getModelJarFile(File dir)
Get the classifier jar file, as packaged by
packageClassifier(File). |
static File |
getModelJarFile(String directoryName) |
CLASSIFIER_TYPE |
loadClassifier(InputStream inputStream)
Load a classifier packaged by
packageClassifier(File) from an InputStream. |
CLASSIFIER_TYPE |
loadClassifierFromTrainingDirectory(File dir)
Load a classifier packaged by
packageClassifier(File) from the jar file in the
training directory. |
protected abstract CLASSIFIER_TYPE |
newClassifier()
Create a new classifier using the attributes loaded by
unpackageClassifier(JarInputStream). |
void |
packageClassifier(File dir)
Create a classifier jar file from a directory where a classifier model was trained by
trainClassifier(File, String[]). |
protected void |
packageClassifier(File dir,
JarOutputStream modelStream)
Add elements to a classifier jar.
|
void |
saveToTrainingDirectory(File dir)
Write all information stored in the classifier builder to the training directory.
|
static void |
trainAndPackage(File trainingDirectory,
String... trainingArguments)
Loads a classifier builder from the training directory and invokes
trainClassifier(File, String...) and packageClassifier(File). |
abstract void |
trainClassifier(File dir,
String... args)
Train a classifier from a training directory, as prepared by
saveToTrainingDirectory(File). |
protected void |
unpackageClassifier(JarInputStream modelStream)
Load classifier elements from a classifier jar.
|
protected Manifest manifest
saveToTrainingDirectory(File) and packageClassifier(File)
and can be used to load a new instance of the classifier builder (via
loadClassifier(InputStream) and loadClassifierFromTrainingDirectory(File).public JarClassifierBuilder()
public static JarClassifierBuilder<?> fromManifest(Manifest manifest)
manifest - The classifier manifest, either from a training directory or from a classifier jar.public static JarClassifierBuilder<?> fromTrainingDirectory(File dir) throws IOException
dir - The training directory where the classifier builder was written by a call to
saveToTrainingDirectory(File). This is typically the same directory as was
used for DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY.IOExceptionpublic static File getModelJarFile(File dir)
packageClassifier(File).dir - The directory where the classifier was packaged.public static File getModelJarFile(String directoryName)
public CLASSIFIER_TYPE loadClassifier(InputStream inputStream) throws IOException
packageClassifier(File) from an InputStream.
This method should typically not be overridden by subclasses - use
unpackageClassifier(JarInputStream) and newClassifier() instead.inputStream - The classifier stream.IOExceptionpublic CLASSIFIER_TYPE loadClassifierFromTrainingDirectory(File dir) throws IOException
packageClassifier(File) from the jar file in the
training directory.
This method should typically not be overridden by subclasses - use
unpackageClassifier(JarInputStream) and newClassifier() instead.dir - The directory where the classifier was trained and packaged.IOExceptionprotected abstract CLASSIFIER_TYPE newClassifier()
unpackageClassifier(JarInputStream).public void packageClassifier(File dir) throws IOException
trainClassifier(File, String[]).
This method should typically not be overridden by subclasses - use
packageClassifier(File, JarOutputStream) instead.dir - The directory where the classifier model was trained.IOExceptionprotected void packageClassifier(File dir, JarOutputStream modelStream) throws IOException
dir - The directory where the classifier model was trained.modelStream - The jar where the classifier is being written.IOException - For errors reading the directory or writing to the jar.public void saveToTrainingDirectory(File dir) throws IOException
DataWriter.finish() or SequenceDataWriter.finish().dir - The directory where classifier information should be written.IOExceptionpublic static void trainAndPackage(File trainingDirectory, String... trainingArguments) throws Exception
trainClassifier(File, String...) and packageClassifier(File).trainingDirectory - The directory where saveToTrainingDirectory(File) has saved the model
training files.trainingArguments - Any additional arguments that should be passed to the classifier trainer via
trainClassifier(File, String...).Exceptionpublic abstract void trainClassifier(File dir, String... args) throws Exception
saveToTrainingDirectory(File). Typically called at the command line by
Train.main(String...).dir - The directory where training data and other classifier information has been written
and where the trained classifier should be stored.args - Additional command line arguments for the classifier trainer.Exceptionprotected void unpackageClassifier(JarInputStream modelStream) throws IOException
newClassifier().modelStream - The classifier jarIOException - For errors reading from the jar.Copyright © 2014. All rights reserved.