@Test public void testBuildDataDictionary() { Map<Integer,Collection<String>> distinctValues = new HashMap<>(); distinctValues.put(1, Arrays.asList("one", "two", "three", "four", "five")); CategoricalValueEncodings categoricalValueEncodings = new CategoricalValueEncodings(distinctValues); DataDictionary dictionary = AppPMMLUtils.buildDataDictionary(buildTestSchema(), categoricalValueEncodings); assertEquals(4, dictionary.getNumberOfFields().intValue()); checkDataField(dictionary.getDataFields().get(0), "foo", null); checkDataField(dictionary.getDataFields().get(1), "bar", true); checkDataField(dictionary.getDataFields().get(2), "baz", null); checkDataField(dictionary.getDataFields().get(3), "bing", false); List<Value> dfValues = dictionary.getDataFields().get(1).getValues(); assertEquals(5, dfValues.size()); String[] categoricalValues = { "one", "two", "three", "four", "five" }; for (int i = 0; i < categoricalValues.length; i++) { assertEquals(categoricalValues[i], dfValues.get(i).getValue()); } }
@Override public String getKey() { return getValue(); }
@Override public String getKey() { return getValue(); }
@Override public VisitorAction visit(Value pmmlValue){ Object value = values.get(pmmlValue.getValue()); if(value != null){ value = ScalarUtil.decode(value); addExtension(pmmlValue, ValueUtil.formatValue(value)); } return super.visit(pmmlValue); } };
static private List<String> parseCategories(DataField dataField){ List<String> result = new ArrayList<>(); if(dataField.hasValues()){ List<Value> pmmlValues = dataField.getValues(); for(Value pmmlValue : pmmlValues){ String stringValue = pmmlValue.getValue(); if(stringValue == null){ throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE); } Value.Property property = pmmlValue.getProperty(); switch(property){ case VALID: result.add(stringValue); break; default: break; } } } return result; }
private Map<FieldValue, Value> parseValues(DataType dataType, OpType opType){ Map<FieldValue, Value> result = new LinkedHashMap<>(); List<Value> fieldValues = getValues(); for(Value fieldValue : fieldValues){ Value.Property property = fieldValue.getProperty(); switch(property){ case VALID: { FieldValue value = FieldValueUtil.create(dataType, opType, fieldValue.getValue()); result.put(value, fieldValue); } break; case INVALID: case MISSING: break; default: throw new UnsupportedFeatureException(fieldValue, property); } } return result; } }
String stringValue = pmmlValue.getValue(); if(stringValue == null){ throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE);
String stringValue = pmmlValue.getValue(); if(stringValue == null){ throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE);
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){ String stringValue = pmmlValue.getValue(); if(stringValue == null){ throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE); } Value.Property property = pmmlValue.getProperty(); switch(property){ case VALID: result.add(TypeUtil.parse(dataType, stringValue)); break; default: break; } } } return result; }
Value pmmlValue = pmmlValues.get(i); String stringValue = pmmlValue.getValue(); if(stringValue == null){ throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE);
Value pmmlValue = pmmlValues.get(i); String stringValue = pmmlValue.getValue(); if(stringValue == null){ throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE);