summaryrefslogtreecommitdiffstats
path: root/debian/htdig/htdig-3.2.0b6/htfuzzy/Fuzzy.h
blob: 825e357fbd5233cfc7abaf7e8a2890120c2a4738 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// Fuzzy.h
//
// Fuzzy: This is the base class for all the different types of fuzzy searches.
//        We only define the interface.
//
// There are two main uses of classes derived from this class:
//    1) Creation of a fuzzy index
//    2) Searching for a word using the fuzzy index
//
// The Fuzzy classes take the raw words from the user's query and generate
// a list of words to be looked up in the database. These words are created
// using the getWords call and can either be picked off from a separate fuzzy
// database specific to the method, or by generating words on the fly.
//
// Part of the ht://Dig package   <http://www.htdig.org/>
// Copyright (c) 1995-2004 The ht://Dig Group
// For copyright details, see the file COPYING in your distribution
// or the GNU Library General Public License (LGPL) version 2 or later
// <http://www.gnu.org/copyleft/lgpl.html>
//
// $Id: Fuzzy.h,v 1.12 2004/05/28 13:15:20 lha Exp $
//

#ifndef _Fuzzy_h_
#define _Fuzzy_h_

#include "Object.h"
#include "htString.h"
#include "Database.h"
#include "HtWordType.h"
#include "HtWordList.h"

class HtConfiguration;
class Dictionary;
class List;


class Fuzzy : public Object
{
public:
    //
    // Construction/Destruction
    //
    Fuzzy(const HtConfiguration& config);
    virtual		~Fuzzy();

    //
    // Given a single work, generate a list of replacement words using
    // the current algorithm.
    //
    virtual void	getWords(char *word, List &words);

    //
    // For the current algorithm, open the key database
    //
    virtual int		openIndex();

    //
    // For searching, we will need to keep track of the weight associated
    // with a particular fuzzy algorithm.
    //
    void		setWeight(double w)		{weight = w;}
    double		getWeight()			{return weight;}

    //*******************************************************************
    // The following are used in the creation of the fuzzy databases.
    //
    // For the current algorithm, write the database to disk.
    //
    virtual int		writeDB();

    //
    // For the current algorithm, create the database.
    // This is for those algoritms that don't need a list of words
    // to work.
    //
    virtual int		createDB(const HtConfiguration &config);
	
    //
    // Given a word from the htdig word database, create the appropriate
    // entries into memory which will later be written out with writeDB().
    //
    virtual void	addWord(char *word);

    //
    // Each algorithm has a name...
    //
    char		*getName()			{return name;}

    //
    // Fuzzy algorithm factory.  This returns a new Fuzzy algorithm
    // object that belongs to the given name.
    //
    static Fuzzy	*getFuzzyByName(char *name, const HtConfiguration& config);
	
protected:
    //
    // Given a single word, generate a database key
    //
    virtual void	generateKey(char *word, String &key);

    char			*name;
    Database			*index;
    Dictionary			*dict;
    double			weight;
    const HtConfiguration&	config;
};

#endif