1 // 2 // Fuzzy.h 3 // 4 // Fuzzy: This is the base class for all the different types of fuzzy searches. 5 // We only define the interface. 6 // 7 // There are two main uses of classes derived from this class: 8 // 1) Creation of a fuzzy index 9 // 2) Searching for a word using the fuzzy index 10 // 11 // The Fuzzy classes take the raw words from the user's query and generate 12 // a list of words to be looked up in the database. These words are created 13 // using the getWords call and can either be picked off from a separate fuzzy 14 // database specific to the method, or by generating words on the fly. 15 // 16 // Part of the ht://Dig package <http://www.htdig.org/> 17 // Copyright (c) 1995-2004 The ht://Dig Group 18 // For copyright details, see the file COPYING in your distribution 19 // or the GNU Library General Public License (LGPL) version 2 or later 20 // <http://www.gnu.org/copyleft/lgpl.html> 21 // 22 // $Id: Fuzzy.h,v 1.12 2004/05/28 13:15:20 lha Exp $ 23 // 24 25 #ifndef _Fuzzy_h_ 26 #define _Fuzzy_h_ 27 28 #include "Object.h" 29 #include "htString.h" 30 #include "Database.h" 31 #include "HtWordType.h" 32 #include "HtWordList.h" 33 34 class HtConfiguration; 35 class Dictionary; 36 class List; 37 38 39 class Fuzzy : public Object 40 { 41 public: 42 // 43 // Construction/Destruction 44 // 45 Fuzzy(const HtConfiguration& config); 46 virtual ~Fuzzy(); 47 48 // 49 // Given a single work, generate a list of replacement words using 50 // the current algorithm. 51 // 52 virtual void getWords(char *word, List &words); 53 54 // 55 // For the current algorithm, open the key database 56 // 57 virtual int openIndex(); 58 59 // 60 // For searching, we will need to keep track of the weight associated 61 // with a particular fuzzy algorithm. 62 // setWeight(double w)63 void setWeight(double w) {weight = w;} getWeight()64 double getWeight() {return weight;} 65 66 //******************************************************************* 67 // The following are used in the creation of the fuzzy databases. 68 // 69 // For the current algorithm, write the database to disk. 70 // 71 virtual int writeDB(); 72 73 // 74 // For the current algorithm, create the database. 75 // This is for those algoritms that don't need a list of words 76 // to work. 77 // 78 virtual int createDB(const HtConfiguration &config); 79 80 // 81 // Given a word from the htdig word database, create the appropriate 82 // entries into memory which will later be written out with writeDB(). 83 // 84 virtual void addWord(char *word); 85 86 // 87 // Each algorithm has a name... 88 // getName()89 char *getName() {return name;} 90 91 // 92 // Fuzzy algorithm factory. This returns a new Fuzzy algorithm 93 // object that belongs to the given name. 94 // 95 static Fuzzy *getFuzzyByName(char *name, const HtConfiguration& config); 96 97 protected: 98 // 99 // Given a single word, generate a database key 100 // 101 virtual void generateKey(char *word, String &key); 102 103 char *name; 104 Database *index; 105 Dictionary *dict; 106 double weight; 107 const HtConfiguration& config; 108 }; 109 110 #endif 111 112 113