@Override public boolean doEquivalent(Object expected, Object actual){ if(actual instanceof Computable){ actual = EvaluatorUtil.decode(actual); } // End if if(actual instanceof Number){ actual = TypeUtil.parseOrCast(DataType.FLOAT, actual); expected = TypeUtil.parseOrCast(DataType.FLOAT, expected); } return super.doEquivalent(expected, actual); } }
static public Double getEntityAffinity(Object object){ HasEntityAffinity hasEntityAffinity = TypeUtil.cast(HasEntityAffinity.class, object); return hasEntityAffinity.getEntityAffinity(); }
static public DataType getConstantDataType(Constant constant){ DataType dataType = constant.getDataType(); if(dataType == null){ dataType = TypeUtil.getConstantDataType(constant.getValue()); } return dataType; }
/** * @throws IllegalArgumentException If the value is a String, and it cannot be parsed to the requested representation. * @throws TypeCheckException If the value is an Object other than String, and it cannot be cast to the requested representation. */ static public Object parseOrCast(DataType dataType, Object value){ if(value instanceof String){ String string = (String)value; return parse(dataType, string); } return cast(dataType, value); }
static public boolean equals(DataType dataType, Object value, String referenceValue){ try { return (parseOrCast(dataType, value)).equals(parse(dataType, referenceValue)); } catch(IllegalArgumentException | TypeCheckException e){ // The String representation of invalid or missing values (eg. "N/A") may not be parseable to the requested representation try { return (parseOrCast(DataType.STRING, value)).equals(referenceValue); } catch(TypeCheckException tce){ // Ignored } throw e; } }
static public FieldValue create(Object value){ if(value == null){ return FieldValues.MISSING_VALUE; } DataType dataType; if(value instanceof Collection){ Collection<?> values = (Collection<?>)value; dataType = TypeUtil.getDataType(values); } else { dataType = TypeUtil.getDataType(value); } OpType opType = TypeUtil.getOpType(dataType); return FieldValue.create(dataType, opType, value); }
@Override public boolean doEquivalent(Object expected, Object actual){ double precision = getPrecision(); double zeroThreshold = getZeroThreshold(); if(actual instanceof Computable){ actual = EvaluatorUtil.decode(actual); } expected = TypeUtil.parseOrCast(TypeUtil.getDataType(actual), expected); return VerificationUtil.acceptable(expected, actual, precision, zeroThreshold); }
value = TypeUtil.parseOrCast(dataType, value); case VALID: boolean equals = TypeUtil.equals(dataType, value, stringValue);
static private DataType getDataType(Object value){ if(value != null){ try { return TypeUtil.getDataType(value); } catch(EvaluationException ee){ // Ignored } } return null; }
static public TargetValue getTargetValue(Target target, Object value){ DataType dataType = TypeUtil.getDataType(value); List<TargetValue> targetValues = target.getTargetValues(); for(TargetValue targetValue : targetValues){ String stringValue = targetValue.getValue(); if(stringValue == null){ throw new MissingAttributeException(targetValue, PMMLAttributes.TARGETVALUE_VALUE); } // End if if((value).equals(TypeUtil.parse(dataType, stringValue))){ return targetValue; } } return null; }
DaysSinceDate period = (DaysSinceDate)value; return getDaysDataType(period.getEpoch()); } else SecondsSinceDate period = (SecondsSinceDate)value; return getSecondsDataType(period.getEpoch());
private FieldValue evaluate(FieldValue left, FieldValue right){ DataType dataType = TypeUtil.getCommonDataType(left.getDataType(), right.getDataType()); Double result = Math.pow((left.asNumber()).doubleValue(), (right.asNumber()).doubleValue()); return FieldValueUtil.create(dataType, OpType.CONTINUOUS, result); } };
/** * @see DataType#DATE_DAYS_SINCE_1960 * @see DataType#DATE_DAYS_SINCE_1970 * @see DataType#DATE_DAYS_SINCE_1980 */ static private DaysSinceDate toDaysSinceDate(LocalDate epoch, Object value){ if(value instanceof DaysSinceDate){ DaysSinceDate period = (DaysSinceDate)value; if((epoch).equals(period.getEpoch())){ return period; } long days = ChronoUnit.DAYS.between(epoch, period.getEpoch()) + period.getDays(); return new DaysSinceDate(epoch, days); } throw new TypeCheckException(getDaysDataType(epoch), value); }
@Override public boolean doEquivalent(Object expected, Object actual){ double precision = getPrecision(); double zeroThreshold = getZeroThreshold(); if(actual instanceof Computable){ actual = EvaluatorUtil.decode(actual); } expected = TypeUtil.parseOrCast(TypeUtil.getDataType(actual), expected); return VerificationUtil.acceptable(expected, actual, precision, zeroThreshold); }
private Object getValue(DataType dataType){ Object value = getValue(); try { return TypeUtil.cast(dataType, value); } catch(TypeCheckException tce){ try { if(value instanceof String){ String string = (String)value; return TypeUtil.parse(dataType, string); } } catch(IllegalArgumentException iae){ // Ignored } throw tce; } }
@Override public DataType getDataType(){ DataType dataType = outputField.getDataType(); if(dataType == null){ if(value instanceof Collection){ Collection<?> values = (Collection<?>)value; dataType = TypeUtil.getDataType(values); } else { dataType = TypeUtil.getDataType(value); } } return dataType; }
private FieldValue evaluate(FieldValue left, FieldValue right){ DataType dataType = TypeUtil.getCommonDataType(left.getDataType(), right.getDataType()); Integer result = ((left.asNumber()).doubleValue() > (right.asNumber()).doubleValue()) ? Numbers.INTEGER_ONE : Numbers.INTEGER_ZERO; return FieldValueUtil.create(dataType, OpType.CONTINUOUS, result); } };
@Override public boolean doEquivalent(Object expected, Object actual){ if(actual instanceof Computable){ actual = EvaluatorUtil.decode(actual); } // End if if(actual instanceof Number){ actual = TypeUtil.parseOrCast(DataType.FLOAT, actual); expected = TypeUtil.parseOrCast(DataType.FLOAT, expected); } return super.doEquivalent(expected, actual); } }
private void verify(Object expected, Object actual, double precision, double zeroThreshold){ if(expected == null){ return; } // End if if(!(actual instanceof Collection)){ DataType dataType = TypeUtil.getDataType(actual); expected = TypeUtil.parseOrCast(dataType, expected); } boolean acceptable = VerificationUtil.acceptable(expected, actual, precision, zeroThreshold); if(!acceptable){ throw new EvaluationException("Values " + PMMLException.formatValue(expected) + " and " + PMMLException.formatValue(actual) + " do not match"); } }