@Override public final void doWork() throws OperatorException { ExampleSet inputExampleSet = exampleSetInput.getData(ExampleSet.class); ExampleSet applySet = null; // check for needed copy of original exampleset if (originalOutput.isConnected() && writesIntoExistingData()) { int type = DataRowFactory.TYPE_DOUBLE_ARRAY; if (inputExampleSet.getExampleTable() instanceof MemoryExampleTable) { DataRowReader dataRowReader = inputExampleSet.getExampleTable().getDataRowReader(); if (dataRowReader.hasNext()) { type = dataRowReader.next().getType(); } } // check if type is supported to be copied if (type >= 0) { applySet = MaterializeDataInMemory.materializeExampleSet(inputExampleSet, type); } } if (applySet == null) applySet = (ExampleSet) inputExampleSet.clone(); // we apply on the materialized data, because writing can't take place in views anyway. ExampleSet result = apply(applySet); originalOutput.deliver(inputExampleSet); exampleSetOutput.deliver(result); }
/** * Generates all new attributes and updates the ExampleTable. Returns a list of Attributes for the * newly generated attributes. * * @param exampleTable the source example table * @param generatorList List of FeatureGenerators * @return A list of Attributes */ public static List<Attribute> generateAll( ExampleTable exampleTable, Collection<FeatureGenerator> generatorList) throws GenerationException { // LogService.getGlobal().log("Starting feature generation with " + generatorList.size() + " // generators.", LogService.STATUS); LogService.getRoot() .log( Level.FINE, "com.rapidminer.generator.FeatureGenerator.starting_feature_generation", generatorList.size()); Iterator<FeatureGenerator> gi = generatorList.iterator(); while (gi.hasNext()) gi.next().setExampleTable(exampleTable); // for performance reasons convert the list to an array FeatureGenerator[] generators = new FeatureGenerator[generatorList.size()]; generatorList.toArray(generators); List<Attribute> newAttributeList = newAttributes(generators, exampleTable); // add the attributes to the example table and ensure length of the // DataRows exampleTable.addAttributes(newAttributeList); // LogService.getGlobal().log("Generator list: " + generatorList, LogService.STATUS); LogService.getRoot() .log(Level.FINE, "com.rapidminer.generator.FeatureGenerator.generator_list", generatorList); // LogService.getGlobal().log("Input set has " + exampleTable.getAttributeCount() + " features, // " + exampleTable.size() + " examples.", LogService.STATUS); LogService.getRoot() .log( Level.FINE, "com.rapidminer.generator.FeatureGenerator.input_has_feature_count_and_example_count", new Object[] {exampleTable.getAttributeCount(), exampleTable.size()}); // generate the attribute values: DataRowReader reader = exampleTable.getDataRowReader(); while (reader.hasNext()) { DataRow dataRow = reader.next(); for (int j = 0; j < generators.length; j++) { generators[j].generate(dataRow); } } // LogService.getGlobal().log("Finished feature generation.", LogService.STATUS); LogService.getRoot() .log(Level.FINE, "com.rapidminer.generator.FeatureGenerator.finished_feature_generation"); // LogService.getGlobal().log("Generated set has " + exampleTable.getAttributeCount() + " // features, " + exampleTable.size() + " examples.", LogService.STATUS); LogService.getRoot() .log( Level.FINE, "com.rapidminer.generator.FeatureGenerator.generated_set_has_feature_count_and_example_count", new Object[] {exampleTable.getAttributeCount(), exampleTable.size()}); return newAttributeList; }