es.ucm.fdi.gaia.jcolibri.method.reuse.CombineQueryAndCasesMethod 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.
/**
* CombineQueryAndCasesMethod.java
* jCOLIBRI2 framework.
* @author Juan A. Recio-Garc�a.
* GAIA - Group for Artificial Intelligence Applications
* http://gaia.fdi.ucm.es
* 05/01/2007
*/
package es.ucm.fdi.gaia.jcolibri.method.reuse;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.log4j.LogManager;
import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase;
import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRQuery;
import es.ucm.fdi.gaia.jcolibri.util.CopyUtils;
/**
* Method to combine the description of a query with the other components of a case: solution, result and justification of solution.
* @author Juan A. Recio-Garcia
* @version 2.0
*/
public class CombineQueryAndCasesMethod {
/**
* Combienes some cases with a query.
* This method creates a new copy for each case and overwrites their description with the description of the query.
*/
public static List combine(CBRQuery query, Collection cases)
{
ArrayList res = new ArrayList();
for(CBRCase orig: cases)
{
try {
CBRCase copy = orig.getClass().newInstance();
copy.setDescription(CopyUtils.copyCaseComponent(query.getDescription()));
copy.setSolution(CopyUtils.copyCaseComponent(orig.getSolution()));
copy.setJustificationOfSolution(CopyUtils.copyCaseComponent(orig.getJustificationOfSolution()));
copy.setResult(CopyUtils.copyCaseComponent(orig.getResult()));
res.add(copy);
} catch (Exception e) {
LogManager.getLogger(CombineQueryAndCasesMethod.class).error("Error combining cases and query", e);
}
}
return res;
}
}