File: OrFuzzyExpander.cc

package info (click to toggle)
htdig 1%3A3.2.0b6-21
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 21,292 kB
  • sloc: ansic: 49,632; cpp: 46,468; sh: 17,400; xml: 4,180; perl: 2,543; makefile: 888; php: 79; asm: 14
file content (94 lines) | stat: -rw-r--r-- 2,178 bytes parent folder | download
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
//
// OrFuzzyExpander.cc
//
// OrFuzzyExpander: a concrete Fuzzy expander that makes a OR with
//                  all the results returned by the applicable Fuzzies.
//
// Part of the ht://Dig package   <https://htdig.sourceforge.net/>
// 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: OrFuzzyExpander.cc,v 1.4 2004/05/28 13:15:24 lha Exp $
//

#include "OrFuzzyExpander.h"
#include "Dictionary.h"
#include "ExactWordQuery.h"
#include "OrQuery.h"

extern int debug;

//
// creates a query with a OrQuery with all the
// distinct fuzzy results
//
// additionally, sets fuzzy scores for used words
//
Query *
OrFuzzyExpander::MakeQuery(const String &word)
{
	Query *result = 0;
	Dictionary exacts;

	// for each configured fuzzy
	filters.Start_Get();
	Fuzzy *fuzzy = (Fuzzy *)filters.Get_Next();
	while(fuzzy)
	{
		// for each word expanded by fuzzy
		List words;
		String nonconst = word;
		fuzzy->getWords(nonconst, words);
		words.Start_Get();
		String *w = (String *)words.Get_Next();
		while(w)
		{
			// if not yet expanded by another fuzzy
			// add it to the big Or
			if(debug) cerr << "fuzzy " << word << "=" << *w << endl;
			ExactWordQuery *exact = (ExactWordQuery *)exacts[*w];
			if(!exact)
			{
				exact = new ExactWordQuery(*w);
				exact->SetWeight(fuzzy->getWeight());
				exacts.Add(*w, exact);
			}
			// otherwise, just adjust the weight
			else
			{
				exact->SetWeight(
						exact->GetWeight() +
						fuzzy->getWeight());
			}
			w = (String *)words.Get_Next();
		}
		fuzzy = (Fuzzy *)filters.Get_Next();
	}

	// return the expanded query
	// a single word or
	// a Or with all the expanded words
	exacts.Start_Get();
	Query *exact = (Query *)exacts.Get_NextElement();
	if(exact)
	{
		result = exact;
		exact = (Query *)exacts.Get_NextElement();
	}
	if(exact)
	{
		Query *tmp = result;
		result = new OrQuery;
		result->Add(tmp);
		while(exact)
		{
			result->Add(exact);
			exact = (Query *)exacts.Get_NextElement();
		}
	}
	exacts.Release();

	return result;
}