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