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