public class MojoReaderBackendFactory
extends java.lang.Object
This class provides convenience methods for loading MOJOs from files, URLs (this includes classpath resources) and also from a generic InputStream source.
User needs to make a choice of a Caching Strategy for MOJO sources that are not file based. Available caching strategies:
Example of using MojoReaderBackendFactory to read a MOJO from a classpath resource:
public class ExampleApp {
public static void main(String[] args) throws Exception {
URL mojoURL = ExampleApp.class.getResource("/com/company/mojo.zip");
MojoReaderBackend reader = MojoReaderBackendFactory.createReaderBackend(mojoURL, CachingStrategy.MEMORY);
MojoModel model = ModelMojoReader.readFrom(reader);
EasyPredictModelWrapper modelWrapper = new EasyPredictModelWrapper(model);
RowData testRow = new RowData();
for (int i = 0; i < args.length; i++)
testRow.put("C"+i, Double.valueOf(args[i]));
RegressionModelPrediction prediction = (RegressionModelPrediction) modelWrapper.predict(testRow);
System.out.println("Prediction: " + prediction.value);
}
}
Modifier and Type | Class and Description |
---|---|
static class |
MojoReaderBackendFactory.CachingStrategy |
Constructor and Description |
---|
MojoReaderBackendFactory() |
Modifier and Type | Method and Description |
---|---|
static MojoReaderBackend |
createReaderBackend(java.io.File file) |
static MojoReaderBackend |
createReaderBackend(java.io.InputStream inputStream,
MojoReaderBackendFactory.CachingStrategy cachingStrategy) |
static MojoReaderBackend |
createReaderBackend(java.lang.String filename) |
static MojoReaderBackend |
createReaderBackend(java.net.URL url,
MojoReaderBackendFactory.CachingStrategy cachingStrategy) |
public static MojoReaderBackend createReaderBackend(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static MojoReaderBackend createReaderBackend(java.io.File file) throws java.io.IOException
java.io.IOException
public static MojoReaderBackend createReaderBackend(java.net.URL url, MojoReaderBackendFactory.CachingStrategy cachingStrategy) throws java.io.IOException
java.io.IOException
public static MojoReaderBackend createReaderBackend(java.io.InputStream inputStream, MojoReaderBackendFactory.CachingStrategy cachingStrategy) throws java.io.IOException
java.io.IOException