OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Result.hpp
Go to the documentation of this file.
1 #ifndef __OPENTREP_BOM_RESULT_HPP
2 #define __OPENTREP_BOM_RESULT_HPP
3 
4 // //////////////////////////////////////////////////////////////////////
5 // Import section
6 // //////////////////////////////////////////////////////////////////////
7 // STL
8 #include <list>
9 #include <map>
10 // Xapian
11 #include <xapian.h>
12 // OpenTREP
16 
17 namespace OPENTREP {
18 
19  // Forward declarations
20  class ResultHolder;
21  struct LocationKey;
22  struct Location;
23  class Place;
24 
25 
26  // //////////////////// Type definitions /////////////////////
30  typedef std::pair<Xapian::Document, ScoreBoard> XapianDocumentPair_T;
31 
35  typedef std::list<XapianDocumentPair_T> DocumentList_T;
36 
40  typedef std::map<Xapian::docid, XapianDocumentPair_T> DocumentMap_T;
41 
42 
43  // //////////////////////// Main Class /////////////////////////
48  class Result : public BomAbstract {
49  friend class FacResultHolder;
50  friend class FacResult;
51  public:
52  // ////////////////////// Getters /////////////////////
56  const TravelQuery_T& getQueryString() const {
57  return _queryString;
58  }
59 
65  return _correctedQueryString;
66  }
67 
71  bool hasFullTextMatched() const {
72  return _hasFullTextMatched;
73  }
74 
78  const NbOfErrors_T& getEditDistance() const {
79  return _editDistance;
80  }
81 
87  return _allowableEditDistance;
88  }
89 
94  return _documentList;
95  }
96 
100  const DocumentMap_T& getDocumentMap() const {
101  return _documentMap;
102  }
103 
108  const XapianDocumentPair_T& getDocumentPair (const Xapian::docid&) const;
109 
113  const Xapian::Document& getDocument (const Xapian::docid&) const;
114 
118  const Xapian::docid& getBestDocID() const {
119  return _bestDocID;
120  }
121 
126  return _bestCombinedWeight;
127  }
128 
133  return _bestDocData;
134  }
135 
139  const Xapian::Document& getBestXapianDocument() const {
140  return getDocument (_bestDocID);
141  }
142 
143 
144  public:
145  // ////////////////////// Setters /////////////////////
149  void setQueryString (const TravelQuery_T& iQueryString) {
150  _queryString = iQueryString;
151  }
152 
156  void setCorrectedQueryString (const TravelQuery_T& iCorrectedQueryString) {
157  _correctedQueryString = iCorrectedQueryString;
158  }
159 
163  void setHasFullTextMatched (const bool iHasFullTextMatched) {
164  _hasFullTextMatched = iHasFullTextMatched;
165  }
166 
170  void setEditDistance (const NbOfErrors_T& iEditDistance) {
171  _editDistance = iEditDistance;
172  }
173 
178  void setAllowableEditDistance (const NbOfErrors_T& iAllowableEditDistance) {
179  _allowableEditDistance = iAllowableEditDistance;
180  }
181 
202  void addDocument (const Xapian::Document&, const Score_T&);
203 
207  void setBestDocID (const Xapian::docid& iDocID) {
208  _bestDocID = iDocID;
209  }
210 
215  void setBestCombinedWeight (const Percentage_T& iPercentage) {
216  _bestCombinedWeight = iPercentage;
217  }
218 
222  void setBestDocData (const std::string& iDocData) {
223  _bestDocData = RawDataString_T (iDocData);
224  }
225 
233  void fillResult (const Xapian::MSet& iMatchingSet);
234 
241  void fillPlace (Place&) const;
242 
243 
244  public:
245  // /////////////////// Business support methods /////////////////
256  std::string fullTextMatch (const Xapian::Database&, const TravelQuery_T&);
257 
266  static Location retrieveLocation (const Xapian::Document&);
267 
276  static Location retrieveLocation (const RawDataString_T&);
277 
289  static LocationKey getPrimaryKey (const Xapian::Document&);
290 
300  static Score_T getEnvelopeID (const Xapian::Document&);
301 
310  static PageRank_T getPageRank (const Xapian::Document&);
311 
318  void displayXapianPercentages() const;
319 
328  void setScoreOnDocMap (const Xapian::docid&,
329  const ScoreType&, const Score_T&);
330 
340 
345  void calculateCodeMatches();
346 
350  void calculatePageRanks();
351 
356 
362 
363  private:
375  std::string fullTextMatch (const Xapian::Database&, const TravelQuery_T&,
376  Xapian::MSet&);
377 
378 
379  public:
380  // /////////////////// Display support methods /////////////////
386  void toStream (std::ostream& ioOut) const;
387 
393  void fromStream (std::istream& ioIn);
394 
398  std::string toString() const;
399 
404  std::string describeKey() const;
405 
410  std::string describeShortKey() const;
411 
412 
413  private:
414  // ////////////// Constructors and Destructors /////////////
418  Result (const TravelQuery_T&, const Xapian::Database&);
419 
423  Result();
424 
428  Result (const Result&);
429 
433  ~Result();
434 
438  void init();
439 
440 
441  private:
442  // /////////////// Attributes ////////////////
446  ResultHolder* _resultHolder;
447 
451  const Xapian::Database& _database;
452 
456  TravelQuery_T _queryString;
457 
462  TravelQuery_T _correctedQueryString;
463 
470  bool _hasFullTextMatched;
471 
475  NbOfErrors_T _editDistance;
476 
481  NbOfErrors_T _allowableEditDistance;
482 
486  Xapian::docid _bestDocID;
487 
493  Percentage_T _bestCombinedWeight;
494 
498  RawDataString_T _bestDocData;
499 
503  DocumentList_T _documentList;
504 
508  DocumentMap_T _documentMap;
509  };
510 
511 }
512 #endif // __OPENTREP_BOM_RESULT_HPP
void fromStream(std::istream &ioIn)
Definition: Result.cpp:102
void setCorrectedQueryString(const TravelQuery_T &iCorrectedQueryString)
Definition: Result.hpp:156
Class modelling the primary key of a location/POR (point of reference).
Definition: LocationKey.hpp:21
std::pair< Xapian::Document, ScoreBoard > XapianDocumentPair_T
Definition: Result.hpp:23
const XapianDocumentPair_T & getDocumentPair(const Xapian::docid &) const
Definition: Result.cpp:107
double Percentage_T
double Score_T
const TravelQuery_T & getQueryString() const
Definition: Result.hpp:56
void calculateCombinedWeights()
Definition: Result.cpp:783
const TravelQuery_T & getCorrectedTravelQuery() const
Definition: Result.hpp:64
static LocationKey getPrimaryKey(const Xapian::Document &)
Definition: Result.cpp:278
const NbOfErrors_T & getEditDistance() const
Definition: Result.hpp:78
Structure modelling a (geographical) location.
Definition: Location.hpp:24
static Score_T getEnvelopeID(const Xapian::Document &)
Definition: Result.cpp:289
double PageRank_T
static PageRank_T getPageRank(const Xapian::Document &)
Definition: Result.cpp:303
const Xapian::Document & getDocument(const Xapian::docid &) const
Definition: Result.cpp:128
static Location retrieveLocation(const Xapian::Document &)
Definition: Result.cpp:266
void addDocument(const Xapian::Document &, const Score_T &)
Definition: Result.cpp:141
std::string fullTextMatch(const Xapian::Database &, const TravelQuery_T &)
Definition: Result.cpp:515
void displayXapianPercentages() const
Definition: Result.cpp:556
const Percentage_T & getBestCombinedWeight() const
Definition: Result.hpp:125
void setQueryString(const TravelQuery_T &iQueryString)
Definition: Result.hpp:149
bool hasFullTextMatched() const
Definition: Result.hpp:71
void setScoreOnDocMap(const Xapian::docid &, const ScoreType &, const Score_T &)
Definition: Result.cpp:586
void fillResult(const Xapian::MSet &iMatchingSet)
Definition: Result.cpp:191
void toStream(std::ostream &ioOut) const
Definition: Result.cpp:97
std::map< Xapian::docid, XapianDocumentPair_T > DocumentMap_T
Definition: Result.hpp:40
void setEditDistance(const NbOfErrors_T &iEditDistance)
Definition: Result.hpp:170
Class wrapping functions on a list of Result objects.
unsigned short NbOfErrors_T
void setBestCombinedWeight(const Percentage_T &iPercentage)
Definition: Result.hpp:215
Class modelling a place/POR (point of reference).
Definition: Place.hpp:28
std::string toString() const
Definition: Result.cpp:65
void setBestDocData(const std::string &iDocData)
Definition: Result.hpp:222
const Xapian::docid & getBestDocID() const
Definition: Result.hpp:118
std::list< MatchingDocuments > DocumentList_T
Enumeration of score types.
Definition: ScoreType.hpp:25
void calculateHeuristicWeights()
Definition: Result.cpp:774
void fillPlace(Place &) const
Definition: Result.cpp:205
Base class for the Business Object Model (BOM) layer.
Definition: BomAbstract.hpp:17
std::string describeKey() const
Definition: Result.cpp:49
void calculatePageRanks()
Definition: Result.cpp:740
const DocumentList_T & getDocumentList() const
Definition: Result.hpp:93
void setBestDocID(const Xapian::docid &iDocID)
Definition: Result.hpp:207
std::string TravelQuery_T
const NbOfErrors_T & getAllowableEditDistance() const
Definition: Result.hpp:86
void setHasFullTextMatched(const bool iHasFullTextMatched)
Definition: Result.hpp:163
const DocumentMap_T & getDocumentMap() const
Definition: Result.hpp:100
std::string describeShortKey() const
Definition: Result.cpp:42
void setAllowableEditDistance(const NbOfErrors_T &iAllowableEditDistance)
Definition: Result.hpp:178
void calculateEnvelopeWeights()
Definition: Result.cpp:608
void calculateCodeMatches()
Definition: Result.cpp:647
Class wrapping a set of Xapian documents having matched a given query string.
Definition: Result.hpp:48
const RawDataString_T & getBestDocData() const
Definition: Result.hpp:132
const Xapian::Document & getBestXapianDocument() const
Definition: Result.hpp:139