use of org.dmg.pmml.IntervalDocument.Interval in project knime-core by knime.
the class PMMLDataDictionaryTranslator method exportTo.
/**
* Adds a data dictionary to the PMML document based on the
* {@link DataTableSpec}.
*
* @param pmmlDoc the PMML document to export to
* @param dts the data table spec
* @return the schema type of the exported schema if applicable, otherwise
* null
* @see #exportTo(PMMLDocument, PMMLPortObjectSpec)
*/
public SchemaType exportTo(final PMMLDocument pmmlDoc, final DataTableSpec dts) {
DataDictionary dict = DataDictionary.Factory.newInstance();
dict.setNumberOfFields(BigInteger.valueOf(dts.getNumColumns()));
DataField dataField;
for (DataColumnSpec colSpec : dts) {
dataField = dict.addNewDataField();
dataField.setName(colSpec.getName());
DataType dataType = colSpec.getType();
dataField.setOptype(getOptype(dataType));
dataField.setDataType(getPMMLDataType(dataType));
// Value
if (colSpec.getType().isCompatible(NominalValue.class) && colSpec.getDomain().hasValues()) {
for (DataCell possVal : colSpec.getDomain().getValues()) {
Value value = dataField.addNewValue();
value.setValue(possVal.toString());
}
} else if (colSpec.getType().isCompatible(DoubleValue.class) && colSpec.getDomain().hasBounds()) {
Interval interval = dataField.addNewInterval();
interval.setClosure(Interval.Closure.CLOSED_CLOSED);
interval.setLeftMargin(((DoubleValue) colSpec.getDomain().getLowerBound()).getDoubleValue());
interval.setRightMargin(((DoubleValue) colSpec.getDomain().getUpperBound()).getDoubleValue());
}
}
pmmlDoc.getPMML().setDataDictionary(dict);
// no schematype available yet
return null;
}
use of org.dmg.pmml.IntervalDocument.Interval in project knime-core by knime.
the class PMMLBinningTranslator method initializeFrom.
@Override
public List<Integer> initializeFrom(final DerivedField[] derivedFields) {
m_mapper = new DerivedFieldMapper(derivedFields);
final List<Integer> consumed = new ArrayList<>(derivedFields.length);
for (int i = 0; i < derivedFields.length; i++) {
final DerivedField df = derivedFields[i];
if (!df.isSetDiscretize()) {
// only reading discretize entries other entries are skipped
continue;
}
consumed.add(i);
final Discretize discretize = df.getDiscretize();
@SuppressWarnings("deprecation") final DiscretizeBin[] pmmlBins = discretize.getDiscretizeBinArray();
final NumericBin[] knimeBins = new NumericBin[pmmlBins.length];
for (int j = 0; j < pmmlBins.length; j++) {
final DiscretizeBin bin = pmmlBins[j];
final String binName = bin.getBinValue();
final Interval interval = bin.getInterval();
final double leftValue = interval.getLeftMargin();
final double rightValue = interval.getRightMargin();
final Closure.Enum closure = interval.getClosure();
boolean leftOpen = true;
boolean rightOpen = true;
if (Closure.OPEN_CLOSED == closure) {
rightOpen = false;
} else if (Closure.CLOSED_OPEN == closure) {
leftOpen = false;
} else if (Closure.CLOSED_CLOSED == closure) {
leftOpen = false;
rightOpen = false;
}
knimeBins[j] = new NumericBin(binName, leftOpen, leftValue, rightOpen, rightValue);
}
/**
* This field contains the name of the column in KNIME that corresponds to the derived field in PMML. This
* is necessary if derived fields are defined on other derived fields and the columns in KNIME are replaced
* with the preprocessed values. In this case KNIME has to know the original names (e.g. A) while PMML
* references to A', A'' etc.
*/
final String displayName = df.getDisplayName();
if (displayName != null) {
m_columnToBins.put(displayName, knimeBins);
m_columnToAppend.put(displayName, null);
} else if (df.getName() != null) {
final String field = m_mapper.getColumnName(discretize.getField());
m_columnToBins.put(field, knimeBins);
m_columnToAppend.put(field, df.getName());
}
}
return consumed;
}
Aggregations