001package es.ucm.fdi.gaia.jcolibri.method.reuse.classification; 002 003 004import java.util.Collection; 005 006import es.ucm.fdi.gaia.jcolibri.extensions.classification.ClassificationSolution; 007import es.ucm.fdi.gaia.jcolibri.method.retrieve.RetrievalResult; 008 009/** 010 * Provides the ability to classify a query by predicting its 011 * solution from supplied cases. Classification is done by 012 * unaimous voting respecting to a class. That class is 013 * configured using the constructor . 014 * 015 * @author Juan A. Recio Garcia 016 * 16/05/07 017 */ 018public class UnanimousVotingMethod extends AbstractKNNClassificationMethod 019{ 020 021 private Object _class; 022 023 public UnanimousVotingMethod(Object classification) 024 { 025 _class = classification; 026 } 027 028 /** 029 * Predicts the class that has all the votes 030 * among the k most similar cases and is equal to the class configured 031 * using the constructor. 032 * If several classes receive the same highest vote, the class that 033 * has the lowest hash code is taken as the prediction. 034 * @param cases 035 * an ordered list of cases along with similarity scores. 036 * @return Returns the predicted solution. 037 */ 038 public ClassificationSolution getPredictedSolution(Collection<RetrievalResult> cases) 039 { 040 ClassificationSolution solution = null; 041 042 for (RetrievalResult result: cases) 043 { 044 ClassificationSolution sol = (ClassificationSolution)result.get_case().getSolution(); 045 046 Object classif = sol.getClassification(); 047 048 if(classif.equals(_class)) 049 solution = sol; 050 else 051 return sol; 052 } 053 054 055 return solution; 056 } 057}