001package es.ucm.fdi.gaia.jcolibri.method.maintenance.solvesFunctions; 002 003 004import java.util.Collection; 005import java.util.Iterator; 006import java.util.LinkedList; 007 008import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase; 009import es.ucm.fdi.gaia.jcolibri.extensions.classification.ClassificationSolution; 010import es.ucm.fdi.gaia.jcolibri.method.maintenance.SolvesFunction; 011import es.ucm.fdi.gaia.jcolibri.method.retrieve.RetrievalResult; 012import es.ucm.fdi.gaia.jcolibri.method.retrieve.NNretrieval.NNScoringMethod; 013import es.ucm.fdi.gaia.jcolibri.method.retrieve.selection.SelectCases; 014import es.ucm.fdi.gaia.jcolibri.method.reuse.classification.KNNClassificationConfig; 015import es.ucm.fdi.gaia.jcolibri.method.revise.classification.BasicClassificationOracle; 016import es.ucm.fdi.gaia.jcolibri.method.revise.classification.ClassificationOracle; 017 018/** 019 * Provides the ICF algorithm solves function which will 020 * decide which cases solve a query. 021 * 022 * @author Lisa Cummins 023 * @author Derek Bridge 024 * 22/05/07 025 */ 026public class ICFSolvesFunction extends SolvesFunction 027{ 028 /** 029 * Sets the cases that both solve q or contribute to its 030 * misclassification. In the case of ICF we only record 031 * cases that solve q. According to the ICF definition, 032 * a case solves a query if it is of the same class as 033 * the query and if there are no classes more similar 034 * to the query with a different class. 035 * 036 * @param q the query 037 * @param cases from which to find the cases which solve 038 * and classify the query. These include the query itself. 039 * @param knnConfig the similarity configuration 040 */ 041 public void setCasesThatSolveAndMisclassifyQ(CBRCase q, Collection<CBRCase> cases, KNNClassificationConfig knnConfig) 042 { 043 solveQ = new LinkedList<CBRCase>(); 044 misclassifyQ = null; 045 046 knnConfig.setK(RetrievalResult.RETRIEVE_ALL); 047 Collection<RetrievalResult> orderedRetrievedCases = NNScoringMethod.evaluateSimilarity(cases, q, knnConfig); 048 orderedRetrievedCases = SelectCases.selectTopKRR(orderedRetrievedCases, knnConfig.getK()); 049 050 ClassificationOracle oracle = new BasicClassificationOracle(); 051 boolean disagreeingCaseFound = false; 052 Iterator<RetrievalResult> iter = orderedRetrievedCases.iterator(); 053 while(!disagreeingCaseFound && iter.hasNext()) 054 { CBRCase c = iter.next().get_case(); 055 ClassificationSolution cSol = (ClassificationSolution)c.getSolution(); 056 if(oracle.isCorrectPrediction(cSol, q)) 057 { solveQ.add(c); 058 } 059 else 060 { disagreeingCaseFound = true; 061 } 062 } 063 } 064}