use of org.dmg.pmml.DerivedFieldDocument.DerivedField in project knime-core by knime.
the class PMMLDataDictionaryTranslator method addOrUpdateColSpecsForDerivedFields.
/**
* @param pmmlDoc the PMML document to analyze
* @param colSpecs the list to add the data column specs to
*/
private void addOrUpdateColSpecsForDerivedFields(final PMMLDocument pmmlDoc, final List<DataColumnSpec> colSpecs) {
DerivedField[] derivedFields = DerivedFieldMapper.getDerivedFields(pmmlDoc.getPMML());
DerivedFieldMapper mapper = new DerivedFieldMapper(derivedFields);
Set<String> mappedColumnNames = mapper.getDerivedNames();
for (DerivedField df : derivedFields) {
String name = df.getName();
DataType dataType = getKNIMEDataType(df.getDataType());
if (!mappedColumnNames.contains(name)) {
/* It is a "real" column - not one that is mapping to another
* column. Hence add a data column spec. */
DataColumnSpecCreator specCreator = new DataColumnSpecCreator(name, dataType);
DataColumnSpec newSpec = specCreator.createSpec();
colSpecs.add(newSpec);
m_activeDerivedFields.add(name);
} else {
/* Update the data type of the referenced data column spec
* by replacing it with a spec of the new type. */
String colName = mapper.getColumnName(name);
DataColumnSpecCreator specCreator = new DataColumnSpecCreator(colName, dataType);
DataColumnSpec newSpec = specCreator.createSpec();
for (int i = 0; i < colSpecs.size(); i++) {
if (colSpecs.get(i).getName().equals(colName)) {
colSpecs.remove(i);
colSpecs.add(i, newSpec);
break;
}
}
m_activeDerivedFields.add(colName);
}
}
}
Aggregations