lbuf = new ArrayList<>();
// Split the column
for(Object obj : objects.getColumn(i)) {
if(obj != null) {
LabelList ll = (LabelList) obj;
int off = (classLabelIndex >= 0) ? classLabelIndex : (ll.size() - classLabelIndex);
try {
ClassLabel lbl = classLabelFactory.makeFromString(ll.get(off));
clscol.add(lbl);
}
catch(Exception e) {
throw new AbortException("Cannot initialize class labels: " + e.getMessage(), e);
}
lbuf.clear();
for(int j = 0; j < ll.size(); j++) {
if(j == off) {
continue;
}
lbuf.add(ll.get(j));
}
lblcol.add(LabelList.make(lbuf));
if(lbuf.size() > 0) {
keeplabelcol = true;
}
}
else {
clscol.add(null);
lblcol.add(null);
}
}
bundle.appendColumn(classLabelFactory.getTypeInformation(), clscol);
// Only add the label column when it's not empty.
if(keeplabelcol) {
bundle.appendColumn(meta, lblcol);
}
}
return bundle;
}
/**
* Parameterization class.
*
* @author Erich Schubert
*
* @apiviz.exclude
*/
public static class Parameterizer extends AbstractParameterizer {
/**
* Optional parameter that specifies the index of the label to be used as
* class label, must be an integer equal to or greater than 0.
*
* Key: {@code -dbc.classLabelIndex}
*
*/
public static final OptionID CLASS_LABEL_INDEX_ID = new OptionID("dbc.classLabelIndex", "The index of the label to be used as class label. The first label is 0, negative indexes are relative to the end.");
/**
* Parameter to specify the class of occurring class labels.
*
* Key: {@code -dbc.classLabelClass}
*
*/
public static final OptionID CLASS_LABEL_CLASS_ID = new OptionID("dbc.classLabelClass", "Class label class to use.");
/**
* The index of the label to be used as class label, null if no class label
* is specified.
*/
protected int classLabelIndex;
/**
* The class label factory to use.
*/
private ClassLabel.Factory> classLabelFactory;
@Override
protected void makeOptions(Parameterization config) {
super.makeOptions(config);
// parameter class label index
final IntParameter classLabelIndexParam = new IntParameter(CLASS_LABEL_INDEX_ID);
final ObjectParameter> classlabelClassParam = new ObjectParameter<>(CLASS_LABEL_CLASS_ID, ClassLabel.Factory.class, SimpleClassLabel.Factory.class);
config.grab(classLabelIndexParam);
config.grab(classlabelClassParam);
if(classLabelIndexParam.isDefined() && classlabelClassParam.isDefined()) {
classLabelIndex = classLabelIndexParam.intValue();
classLabelFactory = classlabelClassParam.instantiateClass(config);
}
}
@Override
protected ClassLabelFilter makeInstance() {
return new ClassLabelFilter(classLabelIndex, classLabelFactory);
}
}
}