001 /** 002 * WeightedMoreLikeThis.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 */ 009 package jcolibri.extensions.recommendation.navigationByProposing.queryElicitation; 010 011 import java.util.Collection; 012 import java.util.HashSet; 013 014 import jcolibri.cbrcore.Attribute; 015 import jcolibri.cbrcore.CBRCase; 016 import jcolibri.cbrcore.CBRQuery; 017 import jcolibri.method.retrieve.NNretrieval.NNConfig; 018 import jcolibri.util.AttributeUtils; 019 020 /** 021 * The WeightedMoreLikeThis transfers all attributes from the selected case 022 * to the query but weights them given preference to diverse attributes among 023 * the proposed cases. The new weights are stored into a NNConfig object, so 024 * this strategy should be used with NN retrieval. 025 * <p>See: 026 * <p>L. McGinty and B. Smyth. Comparison-based recommendation. In ECCBR'02: 027 * Proceedings of the 6th European Conference on Advances in Case-Based 028 * Reasoning, pages 575-589, London, UK, 2002. Springer-Verlag. 029 * 030 * @see jcolibri.method.retrieve.NNretrieval.NNConfig 031 * @author Juan A. Recio-Garcia 032 * @author Developed at University College Cork (Ireland) in collaboration with Derek Bridge. 033 * @version 1.0 034 * 035 */ 036 public class WeightedMoreLikeThis implements ComparisonQueryElicitation 037 { 038 /******************************************************************************/ 039 /** STATIC METHODS **/ 040 /******************************************************************************/ 041 042 /** 043 * Replaces current query with the description of the selected case but weighting 044 * the attributes given preference to diverse attributes among the proposed cases. 045 */ 046 public static void weightedMoreLikeThis(CBRQuery query, CBRCase selectedCase,Collection<CBRCase> proposedCases, NNConfig simConfig) 047 { 048 for(Attribute at: AttributeUtils.getAttributes(selectedCase.getDescription())) 049 { 050 Object selectedValue = AttributeUtils.findValue(at, selectedCase); 051 HashSet<Object> alternatives = new HashSet<Object>(); 052 for(CBRCase c: proposedCases) 053 { 054 Object value = AttributeUtils.findValue(at, c); 055 if(selectedValue == null) 056 { 057 if(value != null) 058 alternatives.add(value); 059 }else if(selectedValue.equals(value)) 060 alternatives.add(value); 061 } 062 AttributeUtils.setValue(at, query, selectedValue); 063 simConfig.setWeight(at, ((double)alternatives.size())/((double)proposedCases.size())); 064 065 } 066 067 068 } 069 070 071 /******************************************************************************/ 072 /** OBJECT METHODS **/ 073 /******************************************************************************/ 074 075 private NNConfig _simConfig; 076 077 public WeightedMoreLikeThis(NNConfig simConfig) 078 { 079 _simConfig = simConfig; 080 } 081 082 /** 083 * Replaces current query with the description of the selected case but weighting 084 * the attributes given preference to diverse attributes among the proposed cases. 085 */ 086 public void reviseQuery(CBRQuery query, CBRCase selectedCase, Collection<CBRCase> proposedCases) 087 { 088 weightedMoreLikeThis(query, selectedCase, proposedCases,_simConfig); 089 } 090 }