<commit_before>/*
 * Copyright (c) 2015 <NAME>
 *
 * This file is part of JPMML-Evaluator
 *
 * JPMML-Evaluator is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JPMML-Evaluator is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with JPMML-Evaluator.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jpmml.evaluator.testing;

import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

import com.esotericsoftware.kryo.Kryo;
import com.google.common.base.Equivalence;
import org.dmg.pmml.Application;
import org.dmg.pmml.MiningSchema;
import org.dmg.pmml.PMML;
import org.dmg.pmml.Visitor;
import org.dmg.pmml.VisitorAction;
import org.jpmml.evaluator.Evaluator;
import org.jpmml.evaluator.EvaluatorBuilder;
import org.jpmml.evaluator.HasEntityRegistry;
import org.jpmml.evaluator.ModelEvaluatorBuilder;
import org.jpmml.evaluator.OutputFilters;
import org.jpmml.evaluator.ResultField;
import org.jpmml.evaluator.kryo.KryoUtil;
import org.jpmml.evaluator.visitors.InvalidMarkupInspector;
import org.jpmml.evaluator.visitors.UnsupportedMarkupInspector;
import org.jpmml.model.SerializationUtil;
import org.jpmml.model.visitors.LocatorTransformer;

abstract
public class IntegrationTestBatch extends ArchiveBatch {

	private String testJavaSerializability = System.getProperty(IntegrationTestBatch.class.getName() + ".testJavaSerializability", "true");

	private String testKryoSerializability = System.getProperty(IntegrationTestBatch.class.getName() + ".testKryoSerializability", "true");

	private Evaluator evaluator = null;


	public IntegrationTestBatch(String name, String dataset, Predicate<ResultField> predicate, Equivalence<Object> equivalence){
		super(name, dataset, predicate, equivalence);
	}

	abstract
	public IntegrationTest getIntegrationTest();

	@Override
	public InputStream open(String path){
		IntegrationTest integrationTest = getIntegrationTest();

		Class<? extends IntegrationTest> clazz = integrationTest.getClass();

		return clazz.getResourceAsStream(path);
	}

	@Override
	public EvaluatorBuilder getEvaluatorBuilder() throws Exception {
		ModelEvaluatorBuilder modelEvaluatorBuilder = (ModelEvaluatorBuilder)super.getEvaluatorBuilder();

		modelEvaluatorBuilder.setOutputFilter(OutputFilters.KEEP_FINAL_RESULTS);

		return modelEvaluatorBuilder;
	}

	/**
	 * @see #validateEvaluator(Evaluator)
	 */
	@Override
	public Evaluator getEvaluator() throws Exception {

		if(this.evaluator != null){
			throw new IllegalStateException();
		}

		Evaluator evaluator =  super.getEvaluator();

		validateEvaluator(evaluator);

		this.evaluator = evaluator;

		return evaluator;
	}

	/**
	 * @see #validatePMML(PMML)
	 */
	@Override
	public PMML getPMML() throws Exception {
		PMML pmml = super.getPMML();

		LocatorTransformer locatorTransformer = new LocatorTransformer();
		locatorTransformer.applyTo(pmml);

		validatePMML(pmml);

		return pmml;
	}

	@Override
	public void close() throws Exception {

		if(this.evaluator != null){
			Evaluator evaluator = this.evaluator;

			try {
				validateEvaluator(evaluator);
			} finally {
				this.evaluator = null;
			}
		}
	}

	protected void validateEvaluator(Evaluator evaluator) throws Exception {

		if(evaluator instanceof HasEntityRegistry){
			HasEntityRegistry<?> hasEntityRegistry = (HasEntityRegistry<?>)evaluator;

			hasEntityRegistry.getEntityRegistry();
		} // End if

		if(Boolean.parseBoolean(this.testJavaSerializability)){
			SerializationUtil.clone(evaluator);
		} // End if

		if(Boolean.parseBoolean(this.testKryoSerializability)){
			Kryo kryo = new Kryo();

			KryoUtil.init(kryo);
			KryoUtil.register(kryo);

			KryoUtil.clone(kryo, evaluator);
		}
	}
<commit_msg>Renamed 'test' system property prefix to 'check'<commit_after>/*
 * Copyright (c) 2015 <NAME>
 *
 * This file is part of JPMML-Evaluator
 *
 * JPMML-Evaluator is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JPMML-Evaluator is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with JPMML-Evaluator.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jpmml.evaluator.testing;

import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

import com.esotericsoftware.kryo.Kryo;
import com.google.common.base.Equivalence;
import org.dmg.pmml.Application;
import org.dmg.pmml.MiningSchema;
import org.dmg.pmml.PMML;
import org.dmg.pmml.Visitor;
import org.dmg.pmml.VisitorAction;
import org.jpmml.evaluator.Evaluator;
import org.jpmml.evaluator.EvaluatorBuilder;
import org.jpmml.evaluator.HasEntityRegistry;
import org.jpmml.evaluator.ModelEvaluatorBuilder;
import org.jpmml.evaluator.OutputFilters;
import org.jpmml.evaluator.ResultField;
import org.jpmml.evaluator.kryo.KryoUtil;
import org.jpmml.evaluator.visitors.InvalidMarkupInspector;
import org.jpmml.evaluator.visitors.UnsupportedMarkupInspector;
import org.jpmml.model.SerializationUtil;
import org.jpmml.model.visitors.LocatorTransformer;

abstract
public class IntegrationTestBatch extends ArchiveBatch {

	private String checkJavaSerializability = System.getProperty(IntegrationTestBatch.class.getName() + "." + "checkJavaSerializability", "true");

	private String checkKryoSerializability = System.getProperty(IntegrationTestBatch.class.getName() + "." + "checkKryoSerializability", "true");

	private Evaluator evaluator = null;


	public IntegrationTestBatch(String name, String dataset, Predicate<ResultField> predicate, Equivalence<Object> equivalence){
		super(name, dataset, predicate, equivalence);
	}

	abstract
	public IntegrationTest getIntegrationTest();

	@Override
	public InputStream open(String path){
		IntegrationTest integrationTest = getIntegrationTest();

		Class<? extends IntegrationTest> clazz = integrationTest.getClass();

		return clazz.getResourceAsStream(path);
	}

	@Override
	public EvaluatorBuilder getEvaluatorBuilder() throws Exception {
		ModelEvaluatorBuilder modelEvaluatorBuilder = (ModelEvaluatorBuilder)super.getEvaluatorBuilder();

		modelEvaluatorBuilder.setOutputFilter(OutputFilters.KEEP_FINAL_RESULTS);

		return modelEvaluatorBuilder;
	}

	/**
	 * @see #validateEvaluator(Evaluator)
	 */
	@Override
	public Evaluator getEvaluator() throws Exception {

		if(this.evaluator != null){
			throw new IllegalStateException();
		}

		Evaluator evaluator =  super.getEvaluator();

		validateEvaluator(evaluator);

		this.evaluator = evaluator;

		return evaluator;
	}

	/**
	 * @see #validatePMML(PMML)
	 */
	@Override
	public PMML getPMML() throws Exception {
		PMML pmml = super.getPMML();

		LocatorTransformer locatorTransformer = new LocatorTransformer();
		locatorTransformer.applyTo(pmml);

		validatePMML(pmml);

		return pmml;
	}

	@Override
	public void close() throws Exception {

		if(this.evaluator != null){
			Evaluator evaluator = this.evaluator;

			try {
				validateEvaluator(evaluator);
			} finally {
				this.evaluator = null;
			}
		}
	}

	protected void validateEvaluator(Evaluator evaluator) throws Exception {

		if(evaluator instanceof HasEntityRegistry){
			HasEntityRegistry<?> hasEntityRegistry = (HasEntityRegistry<?>)evaluator;

			hasEntityRegistry.getEntityRegistry();
		} // End if

		if(Boolean.parseBoolean(this.checkJavaSerializability)){
			SerializationUtil.clone(evaluator);
		} // End if

		if(Boolean.parseBoolean(this.checkKryoSerializability)){
			Kryo kryo = new Kryo();

			KryoUtil.init(kryo);
			KryoUtil.register(kryo);

			KryoUtil.clone(kryo, evaluator);
		}
	}

{'fraction_non_alphanumeric': 0.09567791592658378, 'fraction_numerical': 0.0011841326228537595, 'mean_word_length': 5.13362381989833, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1378332', 'n_tokens_mistral': 2803, 'n_tokens_neox': 2625, 'n_words': 618}