001/** 002 * PartialMoreLikeThis.java 003 * jCOLIBRI2 framework. 004 * @author Juan A. Recio-Garc�a. 005 * GAIA - Group for Artificial Intelligence Applications 006 * http://gaia.fdi.ucm.es 007 * 02/11/2007 008 */ 009package es.ucm.fdi.gaia.jcolibri.extensions.recommendation.navigationByProposing.queryElicitation; 010 011 012import java.util.Collection; 013 014import es.ucm.fdi.gaia.jcolibri.cbrcore.Attribute; 015import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase; 016import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRQuery; 017import es.ucm.fdi.gaia.jcolibri.util.AttributeUtils; 018 019/** 020 * Partially replaces current query with the description of the selected case. 021 * It only transfers a feature value from the selected case if none of the 022 * rejected cases have the same feature value. 023 * <p>See: 024 * <p>L. McGinty and B. Smyth. Comparison-based recommendation. In ECCBR'02: 025 * Proceedings of the 6th European Conference on Advances in Case-Based 026 * Reasoning, pages 575-589, London, UK, 2002. Springer-Verlag. 027 * 028 * @author Juan A. Recio-Garcia 029 * @author Developed at University College Cork (Ireland) in collaboration with Derek Bridge. 030 * @version 1.0 031 * 032 */ 033public class PartialMoreLikeThis implements ComparisonQueryElicitation 034{ 035 /******************************************************************************/ 036 /** STATIC METHODS **/ 037 /******************************************************************************/ 038 039 /** 040 * Partially replaces current query with the description of the selected case. 041 */ 042 public static void partialMoreLikeThis(CBRQuery query, CBRCase selectedCase, Collection<CBRCase> proposedCases) 043 { 044 boolean copyAttribute = true; 045 for(Attribute at: AttributeUtils.getAttributes(selectedCase.getDescription())) 046 { 047 Object selectedValue = AttributeUtils.findValue(at, selectedCase); 048 for(CBRCase c: proposedCases) 049 { 050 Object value = AttributeUtils.findValue(at, c); 051 if(selectedValue == null) 052 { 053 if(value == null) 054 copyAttribute = false; 055 }else 056 copyAttribute = !selectedValue.equals(value); 057 if(!copyAttribute) 058 break; 059 } 060 if(copyAttribute) 061 AttributeUtils.setValue(at, query, selectedValue); 062 } 063 064 065 } 066 067 068 /******************************************************************************/ 069 /** OBJECT METHODS **/ 070 /******************************************************************************/ 071 072 073 /** 074 * Partially replaces current query with the description of the selected case. 075 */ 076 public void reviseQuery(CBRQuery query, CBRCase selectedCase, Collection<CBRCase> proposedCases) 077 { 078 partialMoreLikeThis(query, selectedCase, proposedCases); 079 } 080}