0.08.02
C++ Open Travel Request Parsing Library
Toggle main menu visibility
Loading...
Searching...
No Matches
ResultHolder.cpp
Go to the documentation of this file.
1
// //////////////////////////////////////////////////////////////////////
2
// Import section
3
// //////////////////////////////////////////////////////////////////////
4
// STL
5
#include <cassert>
6
#include <sstream>
7
// Xapian
8
#include <xapian.h>
9
// OpenTrep
10
#include <
opentrep/basic/BasConst_General.hpp
>
11
#include <
opentrep/bom/StringSet.hpp
>
12
#include <
opentrep/bom/Result.hpp
>
13
#include <
opentrep/bom/ResultHolder.hpp
>
14
#include <
opentrep/service/Logger.hpp
>
15
16
namespace
OPENTREP
{
17
18
// //////////////////////////////////////////////////////////////////////
19
ResultHolder::ResultHolder (
const
TravelQuery_T
& iQueryString,
20
const
Xapian::Database& iDatabase)
21
: _resultCombination (NULL),
22
_queryString (iQueryString), _database (iDatabase) {
23
init();
24
}
25
26
// //////////////////////////////////////////////////////////////////////
27
ResultHolder::~ResultHolder () {
28
}
29
30
// //////////////////////////////////////////////////////////////////////
31
void
ResultHolder::init () {
32
_resultCombination = NULL;
33
_resultList.clear();
34
}
35
36
// //////////////////////////////////////////////////////////////////////
37
std::string
ResultHolder::describeShortKey
()
const
{
38
std::ostringstream oStr;
39
oStr << _queryString;
40
return
oStr.str();
41
}
42
43
// //////////////////////////////////////////////////////////////////////
44
std::string
ResultHolder::describeKey
()
const
{
45
return
describeShortKey
();
46
}
47
48
// //////////////////////////////////////////////////////////////////////
49
std::string
ResultHolder::toString
()
const
{
50
std::ostringstream oStr;
51
oStr <<
describeShortKey
() << std::endl;
52
53
unsigned
short
idx = 0;
54
for
(ResultList_T::const_iterator itResult = _resultList.begin();
55
itResult != _resultList.end(); ++itResult, ++idx) {
56
const
Result
* lResult_ptr = *itResult;
57
assert (lResult_ptr != NULL);
58
59
if
(idx != 0) {
60
oStr << std::endl;
61
}
62
oStr <<
" ==> "
<< std::endl << lResult_ptr->
toString
();
63
}
64
65
return
oStr.str();
66
}
67
68
// //////////////////////////////////////////////////////////////////////
69
void
ResultHolder::toStream
(std::ostream& ioOut)
const
{
70
ioOut <<
toString
();
71
}
72
73
// //////////////////////////////////////////////////////////////////////
74
void
ResultHolder::fromStream
(std::istream& ioIn) {
75
}
76
77
// //////////////////////////////////////////////////////////////////////
78
StringSet
ResultHolder::getCorrectedStringSet
()
const
{
79
StringSet
oStringSet;
80
for
(ResultList_T::const_iterator itResult = _resultList.begin();
81
itResult != _resultList.end(); ++itResult) {
82
const
Result
* lResult_ptr = *itResult;
83
assert (lResult_ptr != NULL);
84
85
// Retrieve the corrected string
86
const
TravelQuery_T
& lCorrectedQueryString =
87
lResult_ptr->
getCorrectedTravelQuery
();
88
oStringSet.
push_back
(lCorrectedQueryString);
89
}
90
91
//
92
return
oStringSet;
93
}
94
95
// //////////////////////////////////////////////////////////////////////
96
void
ResultHolder::displayXapianPercentages
()
const
{
97
// Browse the Result objects
98
for
(ResultList_T::const_iterator itResult = _resultList.begin();
99
itResult != _resultList.end(); ++itResult) {
100
Result
* lResult_ptr = *itResult;
101
assert (lResult_ptr != NULL);
102
103
//
104
lResult_ptr->
displayXapianPercentages
();
105
}
106
}
107
108
// //////////////////////////////////////////////////////////////////////
109
void
ResultHolder::calculateEnvelopeWeights
()
const
{
110
// Browse the Result objects
111
for
(ResultList_T::const_iterator itResult = _resultList.begin();
112
itResult != _resultList.end(); ++itResult) {
113
Result
* lResult_ptr = *itResult;
114
assert (lResult_ptr != NULL);
115
116
//
117
lResult_ptr->
calculateEnvelopeWeights
();
118
}
119
}
120
121
// //////////////////////////////////////////////////////////////////////
122
void
ResultHolder::calculateCodeMatches
()
const
{
123
// Browse the Result objects
124
for
(ResultList_T::const_iterator itResult = _resultList.begin();
125
itResult != _resultList.end(); ++itResult) {
126
Result
* lResult_ptr = *itResult;
127
assert (lResult_ptr != NULL);
128
129
//
130
lResult_ptr->
calculateCodeMatches
();
131
}
132
}
133
134
// //////////////////////////////////////////////////////////////////////
135
void
ResultHolder::calculatePageRanks
()
const
{
136
// Browse the Result objects
137
for
(ResultList_T::const_iterator itResult = _resultList.begin();
138
itResult != _resultList.end(); ++itResult) {
139
Result
* lResult_ptr = *itResult;
140
assert (lResult_ptr != NULL);
141
142
//
143
lResult_ptr->
calculatePageRanks
();
144
}
145
}
146
147
// //////////////////////////////////////////////////////////////////////
148
void
ResultHolder::calculateHeuristicWeights
()
const
{
149
// Browse the Result objects
150
for
(ResultList_T::const_iterator itResult = _resultList.begin();
151
itResult != _resultList.end(); ++itResult) {
152
Result
* lResult_ptr = *itResult;
153
assert (lResult_ptr != NULL);
154
155
//
156
lResult_ptr->
calculateHeuristicWeights
();
157
}
158
}
159
160
// //////////////////////////////////////////////////////////////////////
161
void
ResultHolder::calculateCombinedWeights
() {
162
Percentage_T
oCombinedPercentage = 100.0;
163
164
// When there is no result, the weight is obviously 0%
165
if
(_resultList.empty() ==
true
) {
166
oCombinedPercentage = 0.0;
167
}
168
169
// Browse the Result objects
170
for
(ResultList_T::const_iterator itResult = _resultList.begin();
171
itResult != _resultList.end(); ++itResult) {
172
Result
* lResult_ptr = *itResult;
173
assert (lResult_ptr != NULL);
174
175
// Calculate the combined weights, for all the matching documents,
176
// and set the best combined weight to the greatest one
177
lResult_ptr->
calculateCombinedWeights
();
178
179
// Retrieve the just calculated combined weight
180
const
Percentage_T
& lPercentage = lResult_ptr->
getBestCombinedWeight
();
181
182
// Take into account the current weight into the total
183
oCombinedPercentage *= lPercentage / 100.0;
184
}
185
193
unsigned
short
nbOfResults = _resultList.size();
194
if
(nbOfResults > 1) {
195
oCombinedPercentage /= std::pow (
K_DEFAULT_ATTENUATION_FCTR
, nbOfResults);
196
}
197
198
// DEBUG
199
OPENTREP_LOG_DEBUG
(
" [pct] The "
<<
describeKey
()
200
<<
" string partition overall matches at "
201
<< oCombinedPercentage <<
"%"
);
202
203
// Store the combined weight
204
setCombinedWeight
(oCombinedPercentage);
205
}
206
207
}
BasConst_General.hpp
Logger.hpp
OPENTREP_LOG_DEBUG
#define OPENTREP_LOG_DEBUG(iToBeLogged)
Definition
Logger.hpp:33
ResultHolder.hpp
Result.hpp
StringSet.hpp
OPENTREP::ResultHolder::fromStream
void fromStream(std::istream &)
Definition
ResultHolder.cpp:74
OPENTREP::ResultHolder::describeShortKey
std::string describeShortKey() const
Definition
ResultHolder.cpp:37
OPENTREP::ResultHolder::getCorrectedStringSet
StringSet getCorrectedStringSet() const
Definition
ResultHolder.cpp:78
OPENTREP::ResultHolder::calculateEnvelopeWeights
void calculateEnvelopeWeights() const
Definition
ResultHolder.cpp:109
OPENTREP::ResultHolder::describeKey
std::string describeKey() const
Definition
ResultHolder.cpp:44
OPENTREP::ResultHolder::calculateCombinedWeights
void calculateCombinedWeights()
Definition
ResultHolder.cpp:161
OPENTREP::ResultHolder::toStream
void toStream(std::ostream &) const
Definition
ResultHolder.cpp:69
OPENTREP::ResultHolder::calculateCodeMatches
void calculateCodeMatches() const
Definition
ResultHolder.cpp:122
OPENTREP::ResultHolder::calculatePageRanks
void calculatePageRanks() const
Definition
ResultHolder.cpp:135
OPENTREP::ResultHolder::calculateHeuristicWeights
void calculateHeuristicWeights() const
Definition
ResultHolder.cpp:148
OPENTREP::ResultHolder::setCombinedWeight
void setCombinedWeight(const Percentage_T &iPercentage)
Definition
ResultHolder.hpp:63
OPENTREP::ResultHolder::toString
std::string toString() const
Definition
ResultHolder.cpp:49
OPENTREP::ResultHolder::displayXapianPercentages
void displayXapianPercentages() const
Definition
ResultHolder.cpp:96
OPENTREP::Result
Class wrapping a set of Xapian documents having matched a given query string.
Definition
Result.hpp:48
OPENTREP::Result::displayXapianPercentages
void displayXapianPercentages() const
Definition
Result.cpp:562
OPENTREP::Result::getCorrectedTravelQuery
const TravelQuery_T & getCorrectedTravelQuery() const
Definition
Result.hpp:64
OPENTREP::Result::calculatePageRanks
void calculatePageRanks()
Definition
Result.cpp:746
OPENTREP::Result::getBestCombinedWeight
const Percentage_T & getBestCombinedWeight() const
Definition
Result.hpp:125
OPENTREP::Result::toString
std::string toString() const
Definition
Result.cpp:65
OPENTREP::Result::calculateHeuristicWeights
void calculateHeuristicWeights()
Definition
Result.cpp:780
OPENTREP::Result::calculateEnvelopeWeights
void calculateEnvelopeWeights()
Definition
Result.cpp:614
OPENTREP::Result::calculateCodeMatches
void calculateCodeMatches()
Definition
Result.cpp:653
OPENTREP::Result::calculateCombinedWeights
void calculateCombinedWeights()
Definition
Result.cpp:789
OPENTREP
Definition
BasChronometer.cpp:10
OPENTREP::TravelQuery_T
std::string TravelQuery_T
Definition
OPENTREP_Types.hpp:660
OPENTREP::Percentage_T
double Percentage_T
Definition
OPENTREP_Types.hpp:670
OPENTREP::K_DEFAULT_ATTENUATION_FCTR
const Percentage_T K_DEFAULT_ATTENUATION_FCTR
OPENTREP::StringSet
Class holding a set of strings, e.g., {"rio", "de", "janeiro"}.
Definition
StringSet.hpp:19
OPENTREP::StringSet::push_back
void push_back(const std::string &)
Definition
StringSet.cpp:49
Generated on
for OpenTREP by
1.18.0