es.ucm.fdi.gaia.jcolibri.method.reuse.classification.AbstractKNNClassificationMethod Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jCOLIBRI Show documentation
Show all versions of jCOLIBRI Show documentation
jCOLIBRI is a java framework for the development of Case-Based Reasoning systems.
package es.ucm.fdi.gaia.jcolibri.method.reuse.classification;
import java.util.Collection;
import org.apache.logging.log4j.LogManager;
import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase;
import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRQuery;
import es.ucm.fdi.gaia.jcolibri.extensions.classification.ClassificationSolution;
import es.ucm.fdi.gaia.jcolibri.method.retrieve.RetrievalResult;
import es.ucm.fdi.gaia.jcolibri.util.CopyUtils;
/**
* Provides the ability to classify a query by predicting its
* solution from supplied cases.
*
* @author Derek Bridge
* @author Lisa Cummins
* 16/05/07
*/
public abstract class AbstractKNNClassificationMethod implements KNNClassificationMethod
{
/**
* Gets the predicted solution of the given cases according
* to the classification type.
* @param cases a list of cases along with similarity scores.
* @return Returns the predicted solution.
*/
public abstract ClassificationSolution getPredictedSolution(Collection cases);
/**
* Gets the predicted solution of the given cases according
* to the classification type and returns a case that has the
* query description and the predicted solution.
* @param query the query.
* @param cases a list of cases along with similarity scores.
* @return Returns a case with the query description as its
* description and the predicted solution as its solution.
*/
public CBRCase getPredictedCase(CBRQuery query, Collection cases)
{
CBRCase queryWithPredSoln = null;
if(cases.size() > 0)
{ //Make a copy of any case. This will be used as
//the query with its predicted solution.
CBRCase c = cases.iterator().next().get_case();
try {
queryWithPredSoln = c.getClass().newInstance();
} catch (Exception e) {
LogManager.getLogger().error(e);
}
queryWithPredSoln.setDescription(CopyUtils.copyCaseComponent(query.getDescription()));
ClassificationSolution predSolution = getPredictedSolution(cases);
queryWithPredSoln.setSolution(predSolution);
queryWithPredSoln.setJustificationOfSolution(null);
queryWithPredSoln.setResult(null);
}
return queryWithPredSoln;
}
}