{
TupleListIterator tuples = (TupleListIterator)iterationInputs[0];
TupleMetadata metadata = (TupleMetadata)tuples.getMetadataWrapper().getMetadata();
Map<Integer, List<Object>> nominalValues =
getNominalValues(iterationInputs, metadata);
Instances dataset = WekaUtilities.createAssociationDataset(tuples, nominalValues);
String options = TupleUtilities.getAsString(iterationInputs[1], INPUT_OPTIONS);
String algorithmClass = TupleUtilities.getAsString(iterationInputs[2], INPUT_ALGORITHM_CLASS);
Associator associator;
try
{
associator = loadAssociator(options, algorithmClass);
if(associator instanceof Apriori) {
((Apriori)associator).setTreatZeroAsMissing(true);
}
TupleAssociator tupleAssociator =
new TupleAssociator(
associator,
WekaUtilities.getAttributes(dataset));
associator.buildAssociations(dataset);
mOutputAssociator.write(ControlBlock.LIST_BEGIN);
mOutputAssociator.write(tupleAssociator.getAssociator());
mOutputAssociator.write(ControlBlock.LIST_END);
if(mOutputRules != null && ((AssociationRulesProducer)tupleAssociator.getAssociator()).getAssociationRules().getRules().size() > 0 ) {
mOutputRules.write(ControlBlock.LIST_BEGIN);
ArrayList<ColumnMetadata> columns = new ArrayList<ColumnMetadata>();
columns.add(new SimpleColumnMetadata("Rule", TupleTypes._STRING,
0,
ColumnMetadata.COLUMN_NO_NULLS,
0));
String[] metrics = ((AssociationRulesProducer)tupleAssociator.getAssociator()).getAssociationRules().getRules().get(0).getMetricNamesForRule();
for(int i = 0 ; i<metrics.length; i++) {
SimpleColumnMetadata md = new SimpleColumnMetadata(metrics[i], TupleTypes._DOUBLE,
0,
ColumnMetadata.COLUMN_NO_NULLS,
0);
columns.add(md);
}
// columns.addAll(Arrays.asList(((AssociationRulesProducer)tupleAssociator.getAssociator()).getAssociationRules().getRules().get(0).getMetricNamesForRule()));
TupleMetadata rulesMetadata = new SimpleTupleMetadata(columns);
mOutputRules.write(new MetadataWrapper(rulesMetadata));
for(AssociationRule rule:((AssociationRulesProducer)tupleAssociator.getAssociator()).getAssociationRules().getRules()) {
List<Object> elements = new ArrayList<Object>();
elements.add(rule.toString());
for(int i=1; i<columns.size();i++) {