static
| 138 | |
| 139 | // static |
| 140 | void 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 |
| 187 | void StreetsMatcher::FindStreets(BaseContext const & ctx, CBV const & candidates, FeaturesFilter const & filter, |
nothing calls this directly
no test coverage detected