All Downloads are FREE. Search and download functionalities are using the official Maven repository.

es.ucm.fdi.gaia.jcolibri.method.reuse.classification.AbstractKNNClassificationMethod Maven / Gradle / Ivy

Go to download

jCOLIBRI is a java framework for the development of Case-Based Reasoning systems.

There is a newer version: 3.2
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy