001package es.ucm.fdi.gaia.jcolibri.method.maintenance; 002 003 004import java.util.Collection; 005 006import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase; 007import es.ucm.fdi.gaia.jcolibri.method.reuse.classification.KNNClassificationConfig; 008 009/** 010 * Provides the ability to run two case base editing algorithms consecutively on 011 * a set of cases. This is useful to run, for example, noise elimintaion prior 012 * to redundancy removal. 013 * 014 * @author Lisa Cummins 015 */ 016public class TwoStepCaseBaseEditMethod extends AbstractCaseBaseEditMethod { 017 018 protected AbstractCaseBaseEditMethod method1; 019 protected AbstractCaseBaseEditMethod method2; 020 021 /** 022 * Sets up the edit method using the two provided methods. 023 * @param method1 The first method to run. 024 * @param method2 The second method to run. 025 */ 026 public TwoStepCaseBaseEditMethod(AbstractCaseBaseEditMethod method1, 027 AbstractCaseBaseEditMethod method2) 028 { this.method1 = method1; 029 this.method2 = method2; 030 } 031 032 /** 033 * Runs alg1 followed by alg2 on the given cases and returns the cases 034 * deleted by the combined algorithms 035 * 036 * @param cases 037 * The group of cases on which to perform maintenance 038 * @param simConfig 039 * The KNNConfig for these cases 040 * @return the list of cases deleted by the algorithm 041 */ 042 public Collection<CBRCase> retrieveCasesToDelete(Collection<CBRCase> cases, KNNClassificationConfig simConfig) { 043 044 Collection<CBRCase> deletedCases = method1.retrieveCasesToDelete(cases, simConfig); 045 System.out.println(method1.getClass().getName()+" Done, Deleted: " + deletedCases.size()); 046 System.out.println(); 047 for(CBRCase c: deletedCases) 048 System.out.println(c.getID()); 049 cases.removeAll(deletedCases); 050 051 deletedCases.addAll(method2.retrieveCasesToDelete(cases, simConfig)); 052 System.out.println(method2.getClass().getName()+" Done, Deleted: " + deletedCases.size()); 053 054 return deletedCases; 055 } 056}