Java Code Examples for org.dmg.pmml.DataField#hasValues()

The following examples show how to use org.dmg.pmml.DataField#hasValues() . 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: MapHolderParser.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public VisitorAction visit(DataDictionary dataDictionary){

	if(dataDictionary.hasDataFields()){
		List<DataField> dataFields = dataDictionary.getDataFields();

		for(ListIterator<DataField> it = dataFields.listIterator(); it.hasNext(); ){
			DataField dataField = it.next();

			if(dataField.hasValues()){
				it.set(new RichDataField(dataField));
			}
		}
	}

	return super.visit(dataDictionary);
}
 
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: 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;
}