Java Code Examples for org.dmg.pmml.TargetValue#getValue()

The following examples show how to use org.dmg.pmml.TargetValue#getValue() . 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: TargetUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public TargetValue getTargetValue(Target target, Object value){
	DataType dataType = TypeUtil.getDataType(value);

	List<TargetValue> targetValues = target.getTargetValues();
	for(TargetValue targetValue : targetValues){
		Object simpleValue = targetValue.getValue();
		if(simpleValue == null){
			throw new MissingAttributeException(targetValue, PMMLAttributes.TARGETVALUE_VALUE);
		} // End if

		if((value).equals(TypeUtil.parseOrCast(dataType, simpleValue))){
			return targetValue;
		}
	}

	return null;
}
 
Example 2
Source File: TargetUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private <V extends Number> Value<V> getDefaultValue(ValueFactory<V> valueFactory, Target target){

	if(!target.hasTargetValues()){
		return null;
	}

	List<TargetValue> targetValues = target.getTargetValues();
	if(targetValues.size() != 1){
		throw new InvalidElementListException(targetValues);
	}

	TargetValue targetValue = targetValues.get(0);

	Number defaultValue = targetValue.getDefaultValue();

	// "The value and priorProbability attributes are used only if the optype of the field is categorical or ordinal"
	if(targetValue.getValue() != null || targetValue.getPriorProbability() != null){
		throw new InvalidElementException(targetValue);
	} // End if

	if(defaultValue == null){
		return null;
	}

	return valueFactory.newValue(defaultValue);
}