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

The following examples show how to use org.dmg.pmml.Value#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: ValueParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(Value value){
	PMMLObject parent = getParent();

	Object simpleValue = value.getValue();
	if(simpleValue == null){
		throw new MissingAttributeException(value, PMMLAttributes.VALUE_VALUE);
	} // End if

	if(parent instanceof Field){
		Field<?> field = (Field<?>)parent;

		DataType dataType = field.getDataType();
		if(dataType != null){
			simpleValue = safeParseOrCast(dataType, simpleValue);

			value.setValue(simpleValue);
		}
	}

	return super.visit(value);
}
 
Example 2
Source File: FieldUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
static
private List<Object> parseCategories(DataField dataField){
	List<Object> result = new ArrayList<>();

	if(dataField.hasValues()){
		List<Value> pmmlValues = dataField.getValues();

		for(Value pmmlValue : pmmlValues){
			Object simpleValue = pmmlValue.getValue();
			if(simpleValue == null){
				throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE);
			}

			Value.Property property = pmmlValue.getProperty();
			switch(property){
				case VALID:
					result.add(simpleValue);
					break;
				default:
					break;
			}
		}
	}

	return result;
}
 
Example 3
Source File: RichOutputField.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
private Map<Object, Integer> parseValues(){
	DataType dataType = getDataType();

	Map<Object, Integer> result = new LinkedHashMap<>();

	int validIndex = 0;

	List<Value> pmmlValues = getValues();
	for(Value pmmlValue : pmmlValues){
		Object objectValue = pmmlValue.getValue();
		if(objectValue == null){
			throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE);
		}

		Value.Property property = pmmlValue.getProperty();
		switch(property){
			case VALID:
				{
					validIndex++;

					Object value = TypeUtil.parseOrCast(dataType, objectValue);

					result.put(value, validIndex);
				}
				break;
			case INVALID:
			case MISSING:
				throw new InvalidAttributeException(pmmlValue, property);
			default:
				throw new UnsupportedAttributeException(pmmlValue, property);
		}
	}

	return result;
}
 
Example 4
Source File: FieldUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private <F extends Field<F> & HasDiscreteDomain<F>> List<Object> parseValidValues(F field){
	List<Object> result = new ArrayList<>();

	DataType dataType = field.getDataType();
	if(dataType == null){
		throw new MissingAttributeException(MissingAttributeException.formatMessage(XPathUtil.formatElement(field.getClass()) + "@dataType"), field);
	} // End if

	if(field.hasValues()){
		List<Value> pmmlValues = field.getValues();

		for(Value pmmlValue : pmmlValues){
			Object simpleValue = pmmlValue.getValue();
			if(simpleValue == null){
				throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE);
			}

			Value.Property property = pmmlValue.getProperty();
			switch(property){
				case VALID:
					result.add(TypeUtil.parseOrCast(dataType, simpleValue));
					break;
				default:
					break;
			}
		}
	}

	return result;
}
 
Example 5
Source File: RichDerivedField.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
private Map<Object, Integer> parseValues(){
	DataType dataType = getDataType();

	Map<Object, Integer> result = new LinkedHashMap<>();

	int validIndex = 0;

	List<Value> pmmlValues = getValues();
	for(Value pmmlValue : pmmlValues){
		Object objectValue = pmmlValue.getValue();
		if(objectValue == null){
			throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE);
		}

		Value.Property property = pmmlValue.getProperty();
		switch(property){
			case VALID:
				{
					validIndex++;

					Object value = TypeUtil.parseOrCast(dataType, objectValue);

					result.put(value, validIndex);
				}
				break;
			case INVALID:
			case MISSING:
				throw new InvalidAttributeException(pmmlValue, property);
			default:
				throw new UnsupportedAttributeException(pmmlValue, property);
		}
	}

	return result;
}
 
Example 6
Source File: TargetFieldUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
static
public Value getValidValue(DataField dataField, Object value){

	if(value == null){
		return null;
	} // End if

	if(dataField.hasValues()){
		DataType dataType = dataField.getDataType();
		if(dataType == null){
			throw new MissingAttributeException(dataField, PMMLAttributes.DATAFIELD_DATATYPE);
		}

		value = TypeUtil.parseOrCast(dataType, value);

		List<Value> pmmlValues = dataField.getValues();
		for(int i = 0, max = pmmlValues.size(); i < max; i++){
			Value pmmlValue = pmmlValues.get(i);

			Object simpleValue = pmmlValue.getValue();
			if(simpleValue == null){
				throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE);
			}

			Value.Property property = pmmlValue.getProperty();
			switch(property){
				case VALID:
					{
						boolean equals = TypeUtil.equals(dataType, value, simpleValue);

						if(equals){
							return pmmlValue;
						}
					}
					break;
				case INVALID:
				case MISSING:
					break;
				default:
					throw new UnsupportedAttributeException(pmmlValue, property);
			}
		}
	}

	return null;
}