0.08.01
C++ Open Travel Request Parsing Library
Toggle main menu visibility
Loading...
Searching...
No Matches
ScoreBoard.cpp
Go to the documentation of this file.
1
// //////////////////////////////////////////////////////////////////////
2
// Import section
3
// //////////////////////////////////////////////////////////////////////
4
// STL
5
#include <cassert>
6
#include <sstream>
7
// OpenTrep
8
#include <
opentrep/basic/BasConst_General.hpp
>
9
#include <
opentrep/basic/float_utils.hpp
>
10
#include <
opentrep/bom/WordHolder.hpp
>
11
#include <
opentrep/bom/ScoreBoard.hpp
>
12
#include <
opentrep/service/Logger.hpp
>
13
14
namespace
OPENTREP
{
15
16
// //////////////////////////////////////////////////////////////////////
17
ScoreBoard::ScoreBoard
(
const
TravelQuery_T
& iQueryString)
18
: _queryString (iQueryString) {
19
}
20
21
// //////////////////////////////////////////////////////////////////////
22
ScoreBoard::ScoreBoard
(
const
ScoreBoard
& iScoreBoard)
23
: _queryString (iScoreBoard._queryString),
24
_scoreMap (iScoreBoard._scoreMap) {
25
}
26
27
// //////////////////////////////////////////////////////////////////////
28
ScoreBoard::ScoreBoard
(
const
TravelQuery_T
& iQueryString,
29
const
ScoreType
& iType,
const
Score_T
& iScore)
30
: _queryString (iQueryString) {
31
setScore
(iType, iScore);
32
}
33
34
// //////////////////////////////////////////////////////////////////////
35
ScoreBoard::~ScoreBoard
() {
36
_scoreMap.clear();
37
}
38
39
// //////////////////////////////////////////////////////////////////////
40
Score_T
ScoreBoard::getScore
(
const
ScoreType
& iScoreType)
const
{
41
Score_T
oScore = 0.0;
42
43
// Check whether a score value already exists for that type
44
const
ScoreType::EN_ScoreType
& lScoreTypeEnum = iScoreType.
getType
();
45
ScoreMap_T::const_iterator itScore = _scoreMap.find (lScoreTypeEnum);
46
if
(itScore != _scoreMap.end()) {
47
oScore = itScore->second;
48
}
49
50
return
oScore;
51
}
52
53
// //////////////////////////////////////////////////////////////////////
54
void
ScoreBoard::setScore
(
const
ScoreType
& iScoreType,
55
const
Score_T
& iScore) {
56
Score_T
oScore = iScore;
57
73
if
(iScoreType ==
ScoreType::CODE_FULL_MATCH
) {
74
const
FloatingPoint<Percentage_T>
lComparablePct (oScore);
75
const
FloatingPoint<Percentage_T>
lCodeFullMatchingPct (1.0);
76
if
(lComparablePct.
AlmostEquals
(lCodeFullMatchingPct) ==
true
) {
77
oScore =
K_DEFAULT_FULL_CODE_MATCH_PCT
;
78
79
}
else
{
80
// Normally, K_DEFAULT_MODIFIED_MATCHING_PCT == 99.999.
81
// See basic/BasConst.cpp
82
oScore =
K_DEFAULT_MODIFIED_MATCHING_PCT
;
83
}
84
}
85
91
/*
92
if (iScoreType == ScoreType::XAPIAN_PCT) {
93
const FloatingPoint<Percentage_T> lComparablePct (oScore);
94
const FloatingPoint<Percentage_T> lFullMatchingPct (100.0);
95
if (lComparablePct.AlmostEquals (lFullMatchingPct) == true) {
96
// Normally, K_DEFAULT_MODIFIED_MATCHING_PCT == 99.999.
97
// See basic/BasConst.cpp
98
oScore = K_DEFAULT_MODIFIED_MATCHING_PCT;
99
}
100
}
101
*/
102
113
if
(iScoreType ==
ScoreType::ENV_ID
) {
114
const
FloatingPoint<Percentage_T>
lComparableValue (oScore);
115
const
FloatingPoint<Percentage_T>
lNoEnvelopeIDValue (0.0);
116
if
(lComparableValue.
AlmostEquals
(lNoEnvelopeIDValue) ==
true
) {
117
oScore = 100.00;
118
}
else
{
119
// Normally, K_DEFAULT_ENVELOPE_PCT == 0.001. See basic/BasConst.cpp
120
oScore =
K_DEFAULT_ENVELOPE_PCT
;
121
}
122
}
123
124
// Check whether a score value already exists for that type
125
const
ScoreType::EN_ScoreType
& lScoreTypeEnum = iScoreType.
getType
();
126
ScoreMap_T::iterator itScore = _scoreMap.find (lScoreTypeEnum);
127
128
if
(itScore != _scoreMap.end()) {
129
// Just replace the score value
130
Score_T
& lScore = itScore->second;
131
lScore = oScore;
132
133
}
else
{
134
// Insert the score value for that new type
135
const
bool
insertSucceeded =
136
_scoreMap.insert (ScoreMap_T::value_type (lScoreTypeEnum,
137
oScore)).second;
138
139
// Sanity check
140
if
(insertSucceeded ==
false
) {
141
OPENTREP_LOG_ERROR
(
"The "
<< iScore <<
" score value can not be "
142
<<
"inserted in the dedicated list for the "
143
<< iScoreType.
describe
() <<
" score type"
);
144
}
145
assert (insertSucceeded ==
true
);
146
}
147
}
148
149
// //////////////////////////////////////////////////////////////////////
150
std::string
ScoreBoard::describeKey
()
const
{
151
std::ostringstream oStr;
152
oStr << _queryString;
153
return
oStr.str();
154
}
155
156
// //////////////////////////////////////////////////////////////////////
157
std::string
ScoreBoard::describe
()
const
{
158
std::ostringstream oStr;
159
oStr <<
describeKey
() <<
" - "
;
160
161
unsigned
short
idx = 0;
162
for
(ScoreMap_T::const_iterator itScore = _scoreMap.begin();
163
itScore != _scoreMap.end(); ++itScore, ++idx) {
164
if
(idx != 0) {
165
oStr <<
", "
;
166
}
167
const
ScoreType::EN_ScoreType
& lScoreType = itScore->first;
168
const
Score_T
& lScore = itScore->second;
169
oStr <<
ScoreType::getTypeLabelAsString
(lScoreType) <<
": "
170
<< lScore <<
"%"
;
171
}
172
173
return
oStr.str();
174
}
175
176
// //////////////////////////////////////////////////////////////////////
177
void
ScoreBoard::toStream
(std::ostream& ioOut)
const
{
178
ioOut <<
describe
();
179
}
180
181
// //////////////////////////////////////////////////////////////////////
182
void
ScoreBoard::fromStream
(std::istream& ioIn) {
183
}
184
185
// //////////////////////////////////////////////////////////////////////
186
Percentage_T
ScoreBoard::calculateCombinedWeight
() {
187
Percentage_T
oPercentage = 100.0;
188
189
// Browse the registered scores
190
for
(ScoreMap_T::iterator itScore = _scoreMap.begin();
191
itScore != _scoreMap.end(); ++itScore) {
192
const
ScoreType::EN_ScoreType
& lScoreType = itScore->first;
193
Score_T
& lScore = itScore->second;
194
200
const
bool
isIndividual =
ScoreType::isIndividualScore
(lScoreType);
201
if
(isIndividual ==
true
) {
202
oPercentage *= lScore / 100.0;
203
}
204
212
}
213
214
// Register the combined score
215
setCombinedWeight
(oPercentage);
216
217
//
218
return
oPercentage;
219
}
220
221
}
BasConst_General.hpp
Logger.hpp
OPENTREP_LOG_ERROR
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition
Logger.hpp:24
ScoreBoard.hpp
WordHolder.hpp
FloatingPoint
Definition
float_utils_google.hpp:124
FloatingPoint::AlmostEquals
bool AlmostEquals(const FloatingPoint &rhs) const
Definition
float_utils_google.hpp:217
float_utils.hpp
OPENTREP
Definition
BasChronometer.cpp:10
OPENTREP::K_DEFAULT_ENVELOPE_PCT
const Percentage_T K_DEFAULT_ENVELOPE_PCT
OPENTREP::K_DEFAULT_MODIFIED_MATCHING_PCT
const Percentage_T K_DEFAULT_MODIFIED_MATCHING_PCT
OPENTREP::TravelQuery_T
std::string TravelQuery_T
Definition
OPENTREP_Types.hpp:660
OPENTREP::Percentage_T
double Percentage_T
Definition
OPENTREP_Types.hpp:670
OPENTREP::Score_T
double Score_T
Definition
OPENTREP_Types.hpp:675
OPENTREP::K_DEFAULT_FULL_CODE_MATCH_PCT
const Percentage_T K_DEFAULT_FULL_CODE_MATCH_PCT
OPENTREP::ScoreBoard::calculateCombinedWeight
Percentage_T calculateCombinedWeight()
Definition
ScoreBoard.cpp:186
OPENTREP::ScoreBoard::toStream
void toStream(std::ostream &) const
Definition
ScoreBoard.cpp:177
OPENTREP::ScoreBoard::ScoreBoard
ScoreBoard(const TravelQuery_T &, const ScoreType &, const Score_T &)
Definition
ScoreBoard.cpp:28
OPENTREP::ScoreBoard::describe
std::string describe() const
Definition
ScoreBoard.cpp:157
OPENTREP::ScoreBoard::fromStream
void fromStream(std::istream &)
Definition
ScoreBoard.cpp:182
OPENTREP::ScoreBoard::setScore
void setScore(const ScoreType &, const Score_T &)
Definition
ScoreBoard.cpp:54
OPENTREP::ScoreBoard::describeKey
std::string describeKey() const
Definition
ScoreBoard.cpp:150
OPENTREP::ScoreBoard::getScore
Score_T getScore(const ScoreType &) const
Definition
ScoreBoard.cpp:40
OPENTREP::ScoreBoard::~ScoreBoard
~ScoreBoard()
Definition
ScoreBoard.cpp:35
OPENTREP::ScoreBoard::setCombinedWeight
void setCombinedWeight(const Score_T &iScore)
Definition
ScoreBoard.hpp:103
OPENTREP::ScoreType
Enumeration of score types.
Definition
ScoreType.hpp:25
OPENTREP::ScoreType::getTypeLabelAsString
static std::string getTypeLabelAsString(const EN_ScoreType &)
Definition
ScoreType.cpp:66
OPENTREP::ScoreType::isIndividualScore
bool isIndividualScore() const
Definition
ScoreType.cpp:104
OPENTREP::ScoreType::describe
std::string describe() const
Definition
ScoreType.cpp:97
OPENTREP::ScoreType::getType
EN_ScoreType getType() const
Definition
ScoreType.cpp:85
OPENTREP::ScoreType::EN_ScoreType
EN_ScoreType
Definition
ScoreType.hpp:27
OPENTREP::ScoreType::ENV_ID
@ ENV_ID
Definition
ScoreType.hpp:33
OPENTREP::ScoreType::CODE_FULL_MATCH
@ CODE_FULL_MATCH
Definition
ScoreType.hpp:34
Generated on
for OpenTREP by
1.17.0