001/** 002 * NNConfig.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 * 03/01/2007 008 */ 009package es.ucm.fdi.gaia.jcolibri.method.retrieve.NNretrieval; 010 011 012import java.util.HashMap; 013 014import es.ucm.fdi.gaia.jcolibri.cbrcore.Attribute; 015import es.ucm.fdi.gaia.jcolibri.method.retrieve.NNretrieval.similarity.GlobalSimilarityFunction; 016import es.ucm.fdi.gaia.jcolibri.method.retrieve.NNretrieval.similarity.LocalSimilarityFunction; 017 018/** 019 * This class stores the configuration for the NN retrieval method. 020 * It stores: 021 * <ul> 022 * <li>The global similarity function for the description. 023 * <li>Global similarity functions for each compound attribute (CaseComponents excepting the description). 024 * <li>Local similairity functions for each simple attribute. 025 * <li>Weight for each attribute. (1 by default) 026 * </ul> 027 * @author Juan A. Recio-Garcia 028 * @version 1.0 029 */ 030public class NNConfig{ 031 032 private HashMap<Attribute, LocalSimilarityFunction> maplocal = new HashMap<>(); 033 private HashMap<Attribute, GlobalSimilarityFunction> mapglobal = new HashMap<>(); 034 private HashMap<Attribute, Double> mapweight = new HashMap<>(); 035 036 private GlobalSimilarityFunction descriptionSimFunction; 037 038 039 public NNConfig() 040 { 041 } 042 043 /** 044 * @return Returns the description similarity function. 045 */ 046 public GlobalSimilarityFunction getDescriptionSimFunction() { 047 return descriptionSimFunction; 048 } 049 /** 050 * @param descriptionSimFunction The description similarity function. to set. 051 */ 052 public void setDescriptionSimFunction(GlobalSimilarityFunction descriptionSimFunction) { 053 this.descriptionSimFunction = descriptionSimFunction; 054 } 055 056 /** 057 * Sets the local similarity function to apply to a simple attribute. 058 */ 059 public void addMapping(Attribute attribute, LocalSimilarityFunction similFunction) 060 { 061 maplocal.put(attribute, similFunction); 062 } 063 064 /** 065 * Gets the local similarity function configured for a given simple attribute. 066 */ 067 public LocalSimilarityFunction getLocalSimilFunction(Attribute attribute) 068 { 069 return maplocal.get(attribute); 070 } 071 072 /** 073 * Sets the global similarity function to apply to a compound attribute. 074 */ 075 public void addMapping(Attribute attribute, GlobalSimilarityFunction similFunction) 076 { 077 mapglobal.put(attribute, similFunction); 078 } 079 080 /** 081 * Gets the global similarity function configured for a given compound attribute. 082 */ 083 public GlobalSimilarityFunction getGlobalSimilFunction(Attribute attribute) 084 { 085 return mapglobal.get(attribute); 086 } 087 088 /** 089 * Sets the weight for an attribute. 090 */ 091 public void setWeight(Attribute attribute, Double weight) 092 { 093 mapweight.put(attribute, weight); 094 } 095 096 /** 097 * Gets the weight for an attribute. If an attribute does not have a configured weight it returns 1 by default. 098 */ 099 public Double getWeight(Attribute attribute) 100 { 101 Double d = mapweight.get(attribute); 102 if(d!= null) 103 return d; 104 else 105 return new Double(1); 106 } 107}