MCPcopy Create free account
hub / github.com/comaps/comaps / Go

Method Go

libs/search/streets_matcher.cpp:140–184  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

138
139// static
140void StreetsMatcher::Go(BaseContext const & ctx, CBV const & candidates, FeaturesFilter const & filter,
141 QueryParams const & params, vector<Prediction> & predictions)
142{
143 predictions.clear();
144 FindStreets(ctx, candidates, filter, params, predictions);
145
146 if (predictions.empty())
147 return;
148
149 // Remove predictions with the same m_hash (features) and token range.
150 base::SortUnique(predictions, &LessByHashAndRange, &EqualsByHashAndRange);
151
152 // We should distinguish predictions with the same m_hash (features) but different range and
153 // m_withMisprints. For example, for "Paramount dive" we will have two parses:
154 //
155 // STREET UNUSED (can be matched to poi later)
156 // Paramount dive
157 //
158 // STREET STREET ("drive" with misprints)
159 // Paramount dive
160 //
161 // The parses will have the same features and hash but we need both of them.
162 //
163 // We also need to distinguish predictions with the same m_hash (features) and m_withMisprints but
164 // different range. For example:
165 //
166 // STREET STREET STREET STREET
167 // 8 March street, 8
168 //
169 // STREET STREET STREET UNUSED (can be matched to house number later)
170 // 8 March street, 8
171 //
172 // Predictions have the same m_hash (features) and m_withMisprints but lead to different parses.
173 //
174 // That's why we need all predictions here.
175
176 sort(predictions.begin(), predictions.end(),
177 [](Prediction const & l, Prediction const & r) { return l.IsBetter(r); });
178
179 // I suppose, it was made to avoid matching by *very* common tokens (like 'street' only).
180 size_t constexpr kMaxNumOfImprobablePredictions = 3;
181 double constexpr kTailProbability = 0.05;
182 while (predictions.size() > kMaxNumOfImprobablePredictions && predictions.back().m_prob < kTailProbability)
183 predictions.pop_back();
184}
185
186// static
187void StreetsMatcher::FindStreets(BaseContext const & ctx, CBV const & candidates, FeaturesFilter const & filter,

Callers

nothing calls this directly

Calls 10

FindStreetsFunction · 0.85
SortUniqueFunction · 0.85
backMethod · 0.80
clearMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
IsBetterMethod · 0.45
sizeMethod · 0.45
pop_backMethod · 0.45

Tested by

no test coverage detected