File: CQMultiple.h

package info (click to toggle)
gnuift 0.1.14%2Bds-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,632 kB
  • ctags: 2,973
  • sloc: cpp: 15,867; sh: 8,281; ansic: 1,812; perl: 1,007; php: 651; makefile: 483; lisp: 344
file content (188 lines) | stat: -rw-r--r-- 5,324 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* -*- mode: c++ -*- 
*/
/* 

    GIFT, a flexible content based image retrieval system.
    Copyright (C) 1998, 1999, 2000, 2001, 2002, CUI University of Geneva

     Copyright (C) 2003, 2004 Bayreuth University
      2005 Bamberg University
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/
// -*- mode: c++ -*-
#ifndef _CQMULTIPLE
#define _CQMULTIPLE
#include "libMRML/include/uses-declarations.h"

/* -*- mode: c++ -*- 
*/
/**
 *
 * CQMultiple.h
 * A CQuery structure which has several children
 * queries them one after another,
 * weights them, and obtains a common result
 *
 *
 *
 * modification history:
 *
 * WM 20000205 creation
 *
 *
 *
 * compiler defines used:
 * _CQMULTIPLE avoids double inclusion
 *
 */
#include <memory>
#include <map>
#include <list>
#include "libMRML/include/CQuery.h"
#include "libMRML/include/CSelfDestroyPointer.h"
#include "libMRML/include/CIDRelevanceLevelPairList.h"
#include "libMRML/include/CRelevanceLevelList.h"

//#include "CWeightingFunctionPointerList.h"
//#include "CWeightingFunctionPointerHash.h"

#include "libMRML/include/CAlgorithm.h"
#include "libMRML/include/CAccessor.h"
#include "libMRML/include/CAccessorAdminCollection.h"
#include "libMRML/include/CAccessorAdmin.h"

#ifdef HAS_HASH_MAP
#include <hash_map>
#else
#define hash_map map
#endif

class CScoreBoard;
class CAccessor;


/** 

    This is going to be one of our main building blocks.
    It is a structure which contains a couple of 
    CQuery structures, hands a query through to them,
    and then unifies the result. In fact this is the center of 
    all this query tree business.

    Probably we will put another layer into the class tree:
    The CQTreeNode, but let's first start.

    Important: The basic assumption here is, that all children 
    operate on the same collections. If this is not the case we 
    have to be more careful, and most of all: we have to operate using
    URLs.

    [in the following I am talking about things I WANT to do,
    so the two modes stuff is not yet implemented]

    CQMultiple has two minor modes:

    Merge-by-ID or Merge-by-URL

    In the first case, we need information on how to translate image 
    IDs to image URLs. We dispatche a <code>fastQuery()</code> to each
    child node, and then we merge the results (by imageID). The resulting
    list of ID-relevancelevel pairs is translated back to URLs using 
    an URL2FTS accessor.

    <em>Please note that I am aware that this needs refactoring:</em> we should
    have an ULRToID accessor superclass, which provides the necessary translation
    services, without being fixed on a given data representation.
    
    In the second case, we do not need any additional information: 
    we dispatch a <code>query()</code> (as opposed to <code>fastQuery()</code>)  
    to the child nodes, and then we merge the results. This means we have to 
    merge plenty of XML.
    *
    @Author: Wolfgang Mller

 */
class CQMultiple:public CQuery{
protected:

  /** 
      Do we merge the results by their URL or by their 
      image ID? 
  */

  /** */
  void init();
  /** do we merge result URLs or result IDs? */
  bool mUsesResultURLs;
 public:
  /**
   *
   * default constructor
   * 
   */
  CQMultiple();
  /**
   *
   * we need to unregister the accessors used
   * 
   */
  ~CQMultiple();
  /**
   * In fact, what we are doing here is to get ourselves
   * an accessor ACURL2FTS to do a proper fastQuery
   */
  CQMultiple(CAccessorAdminCollection& inAccessorAdminCollection,
	     CAlgorithm&          inAlgorithm);
  
  /** This function processes is in the inner loop of
      fastQuery. If multithreading is possible on the system
      on which GIFT was compiled, then this function will
      run in a thread, and fastQuery will wait for it
  */
  static void* doFastQueryThread(void *);
  /**
   *
   * calls fastQuery for every child, merges the results
   *
   */
  virtual CIDRelevanceLevelPairList* fastQuery(const CXMLElement& inQuery,
					       int inNumberOfInterestingImages,
					       double inDifferenceToBest);

  /** This function processes is in the inner loop of
      query. If multithreading is possible on the system
      on which GIFT was compiled, then this function will
      run in a thread, and fastQuery will wait for it
  */
  static void* doQueryThread(void *);
  /**
   *
   * calls query for every child, merges the results by URLs
   *
   */
  virtual CXMLElement* query(const CXMLElement& inQuery);

  /**
   *
   * set the Algorithm.
   * same scheme as in setCollection
   *
   */
  virtual bool setAlgorithm(CAlgorithm& inAlgorithm);
}; /* end of class */

#endif