All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpmml.evaluator.InputField Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2016 Villu Ruusmann
 *
 * 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 .
 */
package org.jpmml.evaluator;

import java.util.List;
import java.util.Objects;

import com.google.common.collect.RangeSet;
import org.dmg.pmml.DataType;
import org.dmg.pmml.Field;
import org.dmg.pmml.HasContinuousDomain;
import org.dmg.pmml.HasDiscreteDomain;
import org.dmg.pmml.MiningField;
import org.dmg.pmml.OpType;
import org.jpmml.model.MarkupException;

public class InputField extends ModelField {

	private MiningField miningField = null;


	InputField(){
	}

	public InputField(Field field, MiningField miningField){
		super(field);

		setMiningField(miningField);

		if(!Objects.equals(field.requireName(), miningField.requireName())){
			throw new IllegalArgumentException();
		}
	}

	@Override
	public OpType getOpType(){
		return FieldUtil.getOpType(getField(), getMiningField());
	}

	/**
	 * 

* Prepares the input value for a field. *

* *

* First, the value is converted from the user-supplied representation to PMML representation. * After that, the value is subjected to missing value treatment, invalid value treatment and outlier treatment. *

* * @param value The input value in user-supplied representation. * Use null to represent a missing input value. * * @throws EvaluationException If the input value preparation fails. * @throws MarkupException */ public FieldValue prepare(Object value){ return InputFieldUtil.prepareInputValue(getField(), getMiningField(), value); } /** *

* Returns the domain of valid values for this continuous field. * If specified, then all input values that are contained in this set shall be considered valid, and all others invalid. * If not specified, then all input values shall be considered valid. *

* * @return A non-empty set, or null. * * @see #getOpType() */ public RangeSet getContinuousDomain(){ Field field = getField(); if(field instanceof HasContinuousDomain){ RangeSet validRanges = FieldUtil.getValidRanges((Field & HasContinuousDomain)field); if(validRanges != null && !validRanges.isEmpty()){ return validRanges; } } return null; } /** *

* Returns the domain of valid values for this categorical or ordinal field. * If specified, then all input values that are contained in this list shall be considered valid, and all others invalid. * In not specified, then all input values shall be considered valid. *

* *

* List elements are all valid values in PMML representation. * For example, if the data type of this field is {@link DataType#INTEGER}, then all list elements shall be {@link Integer}. *

* * @return A non-empty list, or null. * * @see #getDataType() * @see #getOpType() * * @see TypeUtil#format(Object) * @see TypeUtil#parse(DataType, String) * @see TypeUtil#parseOrCast(DataType, Object) */ public List getDiscreteDomain(){ Field field = getField(); if(field instanceof HasDiscreteDomain){ List validValues = FieldUtil.getValidValues((Field & HasDiscreteDomain)field); if(validValues != null && !validValues.isEmpty()){ return validValues; } } return null; } /** * @return The backing {@link MiningField} element. */ public MiningField getMiningField(){ return this.miningField; } private void setMiningField(MiningField miningField){ this.miningField = Objects.requireNonNull(miningField); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy