use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class AttributeSelectionPanel method getMissingColSpecName.
@SuppressWarnings("null")
private static String getMissingColSpecName(final DataTableSpec spec, final String[] includedNames, final String[] excludedNames) {
ColumnRearranger r = new ColumnRearranger(spec);
// remove columns we know from the include list
for (String colName : includedNames) {
if (spec.containsName(colName)) {
r.remove(colName);
}
}
// remove columns we know from the exclude list
for (String colName : excludedNames) {
if (spec.containsName(colName)) {
r.remove(colName);
}
}
DataTableSpec tableSpecWithMissing = r.createSpec();
DataColumnSpec formerTargetSpec = null;
// were either in the include or exclude list
for (DataColumnSpec colSpec : tableSpecWithMissing) {
DataType colType = colSpec.getType();
if (colType.isCompatible(NominalValue.class) || colType.isCompatible(DoubleValue.class)) {
formerTargetSpec = colSpec;
break;
}
}
assert formerTargetSpec != null : "The former target spec is no longer part of the table, please check.";
return formerTargetSpec.getName();
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class TreeEnsembleClassificationPredictorCellFactory2 method createFactory.
/**
* Creates a TreeEnsembleClassificationPredictorCellFactory from the provided <b>predictor</b>
* @param predictor
* @return an instance of TreeEnsembleClassificationPredictorCellFactory configured according to the settings of the provided
* <b>predictor<b>
* @throws InvalidSettingsException
*/
public static TreeEnsembleClassificationPredictorCellFactory2 createFactory(final TreeEnsemblePredictor predictor) throws InvalidSettingsException {
DataTableSpec testDataSpec = predictor.getDataSpec();
TreeEnsembleModelPortObjectSpec modelSpec = predictor.getModelSpec();
TreeEnsembleModelPortObject modelObject = predictor.getModelObject();
TreeEnsemblePredictorConfiguration configuration = predictor.getConfiguration();
UniqueNameGenerator nameGen = new UniqueNameGenerator(testDataSpec);
Map<String, DataCell> targetValueMap = modelSpec.getTargetColumnPossibleValueMap();
List<DataColumnSpec> newColsList = new ArrayList<DataColumnSpec>();
DataType targetColType = modelSpec.getTargetColumn().getType();
String targetColName = configuration.getPredictionColumnName();
DataColumnSpec targetCol = nameGen.newColumn(targetColName, targetColType);
newColsList.add(targetCol);
if (configuration.isAppendPredictionConfidence()) {
newColsList.add(nameGen.newColumn(targetCol.getName() + " (Confidence)", DoubleCell.TYPE));
}
if (configuration.isAppendClassConfidences()) {
// and this class is not called)
assert targetValueMap != null : "Target column has no possible values";
for (String v : targetValueMap.keySet()) {
newColsList.add(nameGen.newColumn(v, DoubleCell.TYPE));
}
}
if (configuration.isAppendModelCount()) {
newColsList.add(nameGen.newColumn("model count", IntCell.TYPE));
}
// assigned
assert modelObject == null || targetValueMap != null : "Target values must be known during execution";
DataColumnSpec[] newCols = newColsList.toArray(new DataColumnSpec[newColsList.size()]);
int[] learnColumnInRealDataIndices = modelSpec.calculateFilterIndices(testDataSpec);
return new TreeEnsembleClassificationPredictorCellFactory2(predictor, targetValueMap, newCols, learnColumnInRealDataIndices);
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class TreeEnsembleRegressionPredictorCellFactory method createFactory.
/**
* Creates a TreeEnsembleRegressionPredictorCellFactory from the provided <b>predictor</b>
*
* @param predictor
* @return an instance of TreeEnsembleRegressionPredictorCellFactory configured according to the settings of the provided
* <b>predictor<b>
* @throws InvalidSettingsException
*/
public static TreeEnsembleRegressionPredictorCellFactory createFactory(final TreeEnsemblePredictor predictor) throws InvalidSettingsException {
DataTableSpec testDataSpec = predictor.getDataSpec();
TreeEnsembleModelPortObjectSpec modelSpec = predictor.getModelSpec();
// TreeEnsembleModelPortObject modelObject = predictor.getModelObject();
TreeEnsemblePredictorConfiguration configuration = predictor.getConfiguration();
UniqueNameGenerator nameGen = new UniqueNameGenerator(testDataSpec);
List<DataColumnSpec> newColsList = new ArrayList<DataColumnSpec>();
String targetColName = configuration.getPredictionColumnName();
DataColumnSpec targetCol = nameGen.newColumn(targetColName, DoubleCell.TYPE);
newColsList.add(targetCol);
if (configuration.isAppendPredictionConfidence()) {
newColsList.add(nameGen.newColumn(targetCol.getName() + " (Prediction Variance)", DoubleCell.TYPE));
}
if (configuration.isAppendModelCount()) {
newColsList.add(nameGen.newColumn("model count", IntCell.TYPE));
}
DataColumnSpec[] newCols = newColsList.toArray(new DataColumnSpec[newColsList.size()]);
int[] learnColumnInRealDataIndices = modelSpec.calculateFilterIndices(testDataSpec);
return new TreeEnsembleRegressionPredictorCellFactory(predictor, newCols, learnColumnInRealDataIndices);
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class MissingValueHandling2Panel method createWestLayout.
/**
* @param setting
* @param tabPanel
* @param icon
* @param name
* @param spec
*/
private void createWestLayout(final MissingValueHandling2ColSetting setting, final JPanel tabPanel, final Icon icon, final String name, final DataColumnSpec... spec) {
String shortName = name;
if (setting.isMetaConfig()) {
if (name.length() > 15) {
shortName = name.substring(0, 14).concat("...");
}
JLabel jLabel = new JLabel(shortName, icon, SwingConstants.LEFT);
jLabel.setToolTipText(name);
JPanel typePanel = new JPanel(new BorderLayout());
typePanel.add(jLabel, BorderLayout.NORTH);
tabPanel.add(typePanel, BorderLayout.WEST);
} else {
final JList jList = new JList(spec);
jList.setCellRenderer(new DataColumnSpecListCellRenderer() {
@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
// The super method will reset the icon if we call this method
// last. So we let super do its job first and then we take care
// that everything is properly set.
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
String text = null;
if (value instanceof DataColumnSpec && MissingValueHandling2NodeDialogPane.isIncompatible((DataColumnSpec) value)) {
setBorder(BorderFactory.createLineBorder(Color.YELLOW));
text = "Column " + ((DataColumnSpec) value).getName() + " is incompatible to the current settings";
}
setToolTipText(text);
return this;
}
});
jList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
jList.setSelectedIndices(new int[0]);
}
});
// jList.setSE
JScrollPane columns = new JScrollPane(jList);
columns.setMaximumSize(new Dimension(150, 150));
columns.setPreferredSize(new Dimension(100, 150));
tabPanel.add(columns, BorderLayout.WEST);
}
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class MissingValueHandling2Panel method createContent.
/**
* @param setting
* @param spec
* @throws InternalError
*/
private void createContent(final MissingValueHandling2ColSetting setting, final DataColumnSpec... spec) throws InternalError {
final List<String> warningMessages = new ArrayList<String>();
// if we got incompatible types the original type is overwritten by unkown.
int settingTypeBackup = setting.getType();
JPanel tabPanel = new JPanel(new BorderLayout(0, 5));
final JPanel panel = new JPanel(new GridLayout(0, 2));
final Icon icon;
final String name;
final Border border;
final JComponent removePanel;
if (setting.isMetaConfig()) {
switch(setting.getType()) {
case MissingValueHandling2ColSetting.TYPE_INT:
icon = IntCell.TYPE.getIcon();
name = "Integer";
border = BorderFactory.createTitledBorder("Integer Columns");
break;
case MissingValueHandling2ColSetting.TYPE_STRING:
icon = StringCell.TYPE.getIcon();
name = "String";
border = BorderFactory.createTitledBorder("String Columns");
break;
case MissingValueHandling2ColSetting.TYPE_DOUBLE:
icon = DoubleCell.TYPE.getIcon();
name = "Double";
border = BorderFactory.createTitledBorder("Double Columns");
break;
case MissingValueHandling2ColSetting.TYPE_UNKNOWN:
icon = DataType.getType(DataCell.class).getIcon();
name = "Unknown";
border = BorderFactory.createTitledBorder("Unknown Columns");
break;
default:
throw new InternalError("No such type.");
}
removePanel = new JLabel();
} else {
final List<String> names = new ArrayList<String>(Arrays.asList(setting.getNames()));
for (DataColumnSpec cspec : spec) {
names.remove(cspec.getName());
}
if (!names.isEmpty()) {
throw new NullPointerException("Not equal on init: '" + Arrays.toString(setting.getNames()) + "' vs. '" + Arrays.toString(spec) + "'.");
}
name = setting.getDisplayName();
icon = spec[0].getType().getIcon();
JButton requestRemoveButton = new JButton("Remove");
requestRemoveButton.addActionListener(new ActionListener() {
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(final ActionEvent e) {
firePropertyChange(REMOVE_ACTION, null, null);
}
});
removePanel = new JPanel();
removePanel.setLayout(new GridLayout(2, 0));
removePanel.add(requestRemoveButton);
final List<DataColumnSpec> notExistingColumns = getNotExistingColumns(spec);
final List<DataColumnSpec> incompatibleColumns = getIncompatibleTypedColumns(setting.getType(), spec);
if (!notExistingColumns.isEmpty()) {
warningMessages.add("Some columns no longer exist (red bordered)");
}
if (!incompatibleColumns.isEmpty()) {
warningMessages.add(String.format("Some columns have an incompatible type to %s (yellow borderd)", typeToString(setting.getType())));
}
final Set<DataColumnSpec> invalidColumns = new HashSet<DataColumnSpec>();
invalidColumns.addAll(notExistingColumns);
invalidColumns.addAll(incompatibleColumns);
if (!incompatibleColumns.isEmpty()) {
setting.setType(MissingValueHandling2ColSetting.TYPE_UNKNOWN);
}
if (!invalidColumns.isEmpty() && // if all columns are invalid a clean is the same as a remove
!(invalidColumns.size() == spec.length)) {
JButton removeNotExistingColumns = new JButton("Clean");
removeNotExistingColumns.setToolTipText("Removes all invalid columns from the configuration.");
removeNotExistingColumns.addActionListener(new ActionListener() {
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(final ActionEvent e) {
MissingValueHandling2Panel.this.removeAll();
// recreate the content, based on the new settings with removed invalid columns
createContent(diff(m_setting, invalidColumns), diff(spec, invalidColumns));
firePropertyChange(REMOVED_INVALID_COLUMNS, null, invalidColumns.toArray(new DataColumnSpec[invalidColumns.size()]));
}
});
removePanel.add(removeNotExistingColumns);
}
if (!warningMessages.isEmpty()) {
LOGGER.warn("get warnings during panel validation: " + warningMessages);
border = BorderFactory.createLineBorder(Color.RED, 2);
tabPanel.add(createWarningLabel(warningMessages), BorderLayout.NORTH);
} else {
border = BorderFactory.createLineBorder(Color.BLACK);
}
}
createWestLayout(setting, tabPanel, icon, name, spec);
panel.add(createSpacer(1));
panel.add(removePanel);
createEastLayout(setting, panel, spec);
setting.setType(settingTypeBackup);
m_setting = setting;
setBorder(border);
tabPanel.add(panel, BorderLayout.CENTER);
tabPanel.add(createSpacer(65), BorderLayout.SOUTH);
add(tabPanel);
}
Aggregations