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