<commit_before>/*
 * Copyright (c) 2015 <NAME>
 *
 * This file is part of JPMML-Converter
 *
 * JPMML-Converter 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-Converter 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-Converter.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jpmml.converter;

import rexp.Rexp.REXP;

public class ConverterFactory {

	protected ConverterFactory(){
	}

	public Converter getConverter(REXP rexp){

		if(REXPUtil.inherits(rexp, "BinaryTree")){
			return new BinaryTreeConverter();
		} else

		if(REXPUtil.inherits(rexp, "gbm")){
			return new GBMConverter();
		} else

		if(REXPUtil.inherits(rexp, "kmeans")){
			return new KMeansConverter();
		} else

		if(REXPUtil.inherits(rexp, "randomForest")){
			return new RandomForestConverter();
		} else

		if(REXPUtil.inherits(rexp, "train")){
			return new TrainConverter();
		}

		{
			throw new IllegalArgumentException();
		}
	}

	static
	public ConverterFactory getInstance(){
		return new ConverterFactory();
	}<commit_msg>Improved the resolution of Converter classes<commit_after>/*
 * Copyright (c) 2015 <NAME>
 *
 * This file is part of JPMML-Converter
 *
 * JPMML-Converter 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-Converter 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-Converter.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jpmml.converter;

import java.util.Map;

import com.google.common.collect.Maps;
import rexp.Rexp;
import rexp.Rexp.REXP;
import rexp.Rexp.STRING;

public class ConverterFactory {

	protected ConverterFactory(){
	}

	public Converter getConverter(REXP rexp){
		Rexp.REXP names = REXPUtil.attribute(rexp, "class");

		for(int i = 0; i < names.getStringValueCount(); i++){
			STRING name = names.getStringValue(i);

			Class<? extends Converter> clazz = ConverterFactory.converters.get(name.getStrval());
			if(clazz != null){

				try {
					return clazz.newInstance();
				} catch(Exception e){
					throw new IllegalArgumentException(e);
				}
			}
		}

		throw new IllegalArgumentException();
	}

	static
	public ConverterFactory getInstance(){
		return new ConverterFactory();
	}

	private static Map<String, Class<? extends Converter>> converters = Maps.newLinkedHashMap();

	static {
		converters.put("BinaryTree", BinaryTreeConverter.class);
		converters.put("gbm", GBMConverter.class);
		converters.put("kmeans", KMeansConverter.class);
		converters.put("randomForest", RandomForestConverter.class);
		converters.put("train", TrainConverter.class);
	}
{'fraction_non_alphanumeric': 0.09974278365247213, 'fraction_numerical': 0.003143755358673907, 'mean_word_length': 4.223880597014926, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, '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': '2492363', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1031, 'n_words': 355}