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

The following examples show how to use org.dmg.pmml.DataField#getValues() . 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: 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 2
Source File: AppPMMLUtils.java    From oryx with Apache License 2.0 5 votes vote down vote up
public static CategoricalValueEncodings buildCategoricalValueEncodings(
    DataDictionary dictionary) {
  Map<Integer,Collection<String>> indexToValues = new HashMap<>();
  List<DataField> dataFields = dictionary.getDataFields();
  for (int featureIndex = 0; featureIndex < dataFields.size(); featureIndex++) {
    DataField field = dataFields.get(featureIndex);
    Collection<Value> values = field.getValues();
    if (values != null && !values.isEmpty()) {
      Collection<String> categoricalValues =
          values.stream().map(v -> v.getValue().toString()).collect(Collectors.toList());
      indexToValues.put(featureIndex, categoricalValues);
    }
  }
  return new CategoricalValueEncodings(indexToValues);
}
 
Example 3
Source File: InputFieldUtilTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private void clearDomain(DataField dataField){
	List<Interval> intervals = dataField.getIntervals();
	intervals.clear();

	List<Value> values = dataField.getValues();
	values.clear();
}
 
Example 4
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;
}
 
Example 5
Source File: ReflectionUtilTest.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
@Test
public void equals(){
	DataField left = new DataField()
		.setName(FieldName.create("x"))
		.setCyclic(null);

	DataField right = new DataField()
		.setName(FieldName.create("x"))
		.setCyclic(DataField.Cyclic.ZERO);

	// Initialize a live list instance
	right.getValues();

	assertTrue(ReflectionUtil.equals(left, right));

	Value leftValue = new Value()
		.setValue(0)
		.setProperty(null);

	Value rightValue = new Value()
		.setValue(0)
		.setProperty(Value.Property.VALID);

	right.addValues(rightValue);

	assertFalse(ReflectionUtil.equals(left, right));

	left.addValues(leftValue);

	assertTrue(ReflectionUtil.equals(left, right));

	// Double != Integer
	leftValue.setValue(((Number)rightValue.getValue()).doubleValue());

	assertFalse(ReflectionUtil.equals(left, right));

	leftValue.setValue(rightValue.getValue());

	assertTrue(ReflectionUtil.equals(left, right));

	Value missingValue = new Value()
		.setValue(-999)
		.setProperty(Value.Property.MISSING);

	right.addValues(missingValue);

	assertFalse(ReflectionUtil.equals(left, right));
}