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