org.jpmml.evaluator.LoadingModelEvaluatorBuilder Java Examples

The following examples show how to use org.jpmml.evaluator.LoadingModelEvaluatorBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EvaluatorUtil.java    From jpmml-evaluator-spark with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see LoadingModelEvaluatorBuilder#load(InputStream)
 * @see LoadingModelEvaluatorBuilder#load(InputStream, String)
 */
@Deprecated
static
public Evaluator createEvaluator(InputStream is) throws SAXException, JAXBException {
	EvaluatorBuilder evaluatorBuilder = new LoadingModelEvaluatorBuilder()
		.load(is);

	Evaluator evaluator = evaluatorBuilder.build();

	// Perform self-testing
	evaluator.verify();

	return evaluator;
}
 
Example #2
Source File: Openscoring.java    From openscoring with GNU Affero General Public License v3.0 4 votes vote down vote up
public Openscoring(){
	Config config = ConfigFactory.load();

	setConfig(config);

	Binder configBinder = new AbstractBinder(){

		@Override
		public void configure(){
			bind(config).to(Config.class).named("openscoring");
		}
	};
	register(configBinder);

	ModelRegistry modelRegistry = createModelRegistry(config);

	setModelRegistry(modelRegistry);

	Binder modelRegistryBinder = new AbstractBinder(){

		@Override
		public void configure(){
			bind(modelRegistry).to(ModelRegistry.class).named("openscoring");
		}
	};
	register(modelRegistryBinder);

	LoadingModelEvaluatorBuilder loadingModelEvaluatorBuilder = createLoadingModelEvaluatorBuilder(config);

	setLoadingModelEvaluatorBuilder(loadingModelEvaluatorBuilder);

	Binder loadingModelEvaluatorBuilderBinder = new AbstractBinder(){

		@Override
		public void configure(){
			bind(loadingModelEvaluatorBuilder).to(LoadingModelEvaluatorBuilder.class);
		}
	};
	register(loadingModelEvaluatorBuilderBinder);

	Config applicationConfig = config.getConfig("application");

	register(ModelResource.class);

	// Convert path variables to ModelRef objects
	register(loadClass(ModelRefConverterProvider.class, applicationConfig));

	// PMML support
	register(loadClass(ModelProvider.class, applicationConfig));

	// JSON support
	register(JacksonJsonProvider.class);
	register(ObjectMapperProvider.class);

	// CSV support
	register(loadClass(TableProvider.class, applicationConfig));

	// Convert exceptions to JSON objects
	register(WebApplicationExceptionMapper.class);

	// Permit the HTTP POST method to be changed to HTTP PUT or DELETE methods
	register(HttpMethodOverrideFilter.class);

	// File upload support
	register(MultiPartFeature.class);

	// Security support
	register(RolesAllowedDynamicFeature.class);

	// GZip and Deflate encoding support
	register(EncodingFilter.class);
	register(GZipEncoder.class);
	register(DeflateEncoder.class);

	// Application identification
	register(ApplicationHeaderFilter.class);

	List<String> componentClassNames = applicationConfig.getStringList("componentClasses");
	for(String componentClassName : componentClassNames){
		Class<?> clazz = loadClass(Object.class, componentClassName);

		register(clazz);
	}
}
 
Example #3
Source File: Openscoring.java    From openscoring with GNU Affero General Public License v3.0 4 votes vote down vote up
public LoadingModelEvaluatorBuilder getLoadingModelEvaluatorBuilder(){
	return this.loadingModelEvaluatorBuilder;
}
 
Example #4
Source File: Openscoring.java    From openscoring with GNU Affero General Public License v3.0 4 votes vote down vote up
private void setLoadingModelEvaluatorBuilder(LoadingModelEvaluatorBuilder loadingModelEvaluatorBuilder){
	this.loadingModelEvaluatorBuilder = loadingModelEvaluatorBuilder;
}
 
Example #5
Source File: Openscoring.java    From openscoring with GNU Affero General Public License v3.0 4 votes vote down vote up
static
private LoadingModelEvaluatorBuilder createLoadingModelEvaluatorBuilder(Config config){
	Config modelEvaluatorBuilderConfig = config.getConfig("modelEvaluatorBuilder");

	LoadingModelEvaluatorBuilder modelEvaluatorBuilder = new LoadingModelEvaluatorBuilder();

	Class<? extends ModelEvaluatorFactory> modelEvaluatorFactoryClazz = loadClass(ModelEvaluatorFactory.class, modelEvaluatorBuilderConfig);
	modelEvaluatorBuilder.setModelEvaluatorFactory(newInstance(modelEvaluatorFactoryClazz));

	Class<? extends ValueFactoryFactory> valueFactoryFactoryClazz = loadClass(ValueFactoryFactory.class, modelEvaluatorBuilderConfig);
	modelEvaluatorBuilder.setValueFactoryFactory(newInstance(valueFactoryFactoryClazz));

	modelEvaluatorBuilder.setOutputFilter(OutputFilters.KEEP_FINAL_RESULTS);

	// Jackson does not support the JSON serialization of <code>null</code> map keys
	ResultMapper resultMapper = new ResultMapper(){

		private FieldName defaultTargetName = FieldName.create(ModelResponse.DEFAULT_TARGET_NAME);


		@Override
		public FieldName apply(FieldName name){

			// A "phantom" default target field
			if(name == null){
				return this.defaultTargetName;
			}

			return name;
		}
	};

	modelEvaluatorBuilder.setResultMapper(resultMapper);

	boolean validate = modelEvaluatorBuilderConfig.getBoolean("validate");

	if(validate){
		Schema schema;

		try {
			schema = JAXBUtil.getSchema();
		} catch(SAXException | IOException e){
			throw new RuntimeException(e);
		}

		modelEvaluatorBuilder
			.setSchema(schema)
			.setValidationEventHandler(new SimpleValidationEventHandler());
	}

	boolean locatable = modelEvaluatorBuilderConfig.getBoolean("locatable");

	modelEvaluatorBuilder.setLocatable(locatable);

	VisitorBattery visitors = new VisitorBattery();

	List<String> visitorClassNames = modelEvaluatorBuilderConfig.getStringList("visitorClasses");
	for(String visitorClassName : visitorClassNames){
		Class<?> clazz = loadClass(Object.class, visitorClassName);

		if((Visitor.class).isAssignableFrom(clazz)){
			Class<? extends Visitor> visitorClazz = clazz.asSubclass(Visitor.class);

			visitors.add(visitorClazz);
		} else

		if((VisitorBattery.class).isAssignableFrom(clazz)){
			Class<? extends VisitorBattery> visitorBatteryClazz = clazz.asSubclass(VisitorBattery.class);

			VisitorBattery visitorBattery = newInstance(visitorBatteryClazz);

			visitors.addAll(visitorBattery);
		} else

		{
			throw new IllegalArgumentException(new ClassCastException(clazz.toString()));
		}
	}

	modelEvaluatorBuilder.setVisitors(visitors);

	return modelEvaluatorBuilder;
}
 
Example #6
Source File: ModelProvider.java    From openscoring with GNU Affero General Public License v3.0 4 votes vote down vote up
@Inject
public ModelProvider(LoadingModelEvaluatorBuilder modelEvaluatorBuilder){
	this.modelEvaluatorBuilder = modelEvaluatorBuilder;
}